nemo-fixo
nemo-fixo is a nemo plugin plugin to manage your test fixtures.
Test fixtures can be complex when you need to run your tests for different environments and locales, as there tends to be a lot of data duplication.
nemo-fixo
solves this issue with fixo
, an extension to JSON parser to extend and compose JSON objects. fixo
instance is accessible from nemo.fixo
; nemo-fixo
also provides load
and iterate
functions to use the fixture data to drive your mocha test cases.
Installation
$ npm install nemo-fixo
How to use it
Edit Nemo config.json
file, add nemo-fixo
plugin settings:
Options
- srcDir: Test fixtures directory (required, default:
test/fixture
) - specDir: Test specs directory (optional, default:
undefined
), more info here. - defaultIterateList : Default list loaded by
iterate
helper function (optional, default:all
), more info here.
Fixo instance
// Load fixturenemofixo; // Or with Promisenemofixo; // Load fixture property for a profilenemofixo; // Load multiple fixturesnemofixo; // Load fixture in a foldernemofixo;
Fixture file
Inheritance and Override
Fixo supports object inheritance and override, example:
GB
extends frommaster
GB-en
extends frommaster
,GB
,en
GB-en-dev
extends frommaster
,GB
,en
,GB-en
Default values
Shared default values. Visa, Diners, Amex extend the default values:
"master": "default": "expiry_date": "08/18" "cvv": "123" "visa": "account_number": "1111111111111111" "cvv": "123" "diners": "account_number": "22222222222222" "amex": "account_number": "333333333333333"
Resolvers and Macros
Resolvers
allow you to transform an object property value as a whole, while Macros
allow you to replace parts of a string value with dynamic content.
You could easily create custom resolvers and macros, refer to fixo documentation for more information.
"master": "profile": "name": "Walter Mitty" "email": "test-{random}@domain.com" "name": "get:profile.name" "wallet": "bank": "include:bank.citibank" "card_GB": "include.GB:card.visa" "GB": "profile": "name": "William"
Load and iterate functions
Use your test fixture data to drive your test cases. nemo-fixo
provides load
and iterate
functions:
nemo-fixo/load
— to load one or multiple fixturenemo-fixo/iterate
— to load one or multiple fixtures and iterate over different profiles
Load fixture function
var load = ;var fixture = ; if fixtureflagOn
Iterate fixtures function
var iterate = ; ;
Iterate profile list
Iterate profile list is determined from multiple sources in the following precedence:
FIXO_ITERATE_PROFILES
environment variable, a comma-seperated value of profile list. Used in development to force iterate a fixed set of profiles.- Profile list argument passed to
iterate
function - Profile list configured in the fixture file under
iterate
property name
// test/fixture/card.json "master": "visa": {} "amex": {} "US": {} "GB": {} "CA": {} ... "iterate": "all": "US" "GB" "CA"
// test/spec/test-card.js// Profile list is retrieved from the card.json, i.e. ['US', 'GB', 'CA'];
Multiple profile lists
You could configure multiple profile lists in your fixture file. By default, iterate method will look for the all
list:
// test/fixture/card.json "master": {} ... "iterate": "all": ... "small": ... "medium": ... "large": ...
If you need to change the default list name, set defaultIterateList
option when configuring nemo fixo plugin. To load a specific profile list, you could pass the list
option:
;
When configuring your CI environment, you could also set FIXO_ITERATE_LIST
environment variable.
Load fixture matching the spec filename
To load fixture matching the spec name and the directory structure, configure specDir
option in Nemo config.json
and pass __filename
for the fixture name.
// Nemo config.json "plugins": "nemo-fixo": "modules": "nemo-fixo" "arguments": "srcDir": "test/fixture" "specDir": "test/spec" // Comment off to ignore fixture directory structure // test/spec/nested/test-card.js// fixture will load from test/fixture/nested/test-card.json;;
License
Copyright (C) 2016 PayPal
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.