Skip to content

Commit

Permalink
Labels param + fixs
Browse files Browse the repository at this point in the history
  • Loading branch information
mantovanig committed Feb 9, 2017
1 parent 5343c34 commit f064274
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 22 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ Reference task of backstopJS.
`options[Object]`
```javascript
{
scenario: NameOfSubfolder[string],
tags: [array]
scenario: NameOfSubfolder[string/array],
tags: [string/array],
labels: [string/array]
}
```

Expand All @@ -54,8 +55,9 @@ Test task of backstopJS.
`options[Object]`
```javascript
{
scenario: NameOfSubfolder[string],
tags: [array]
scenario: NameOfSubfolder[string/array],
tags: [string/array],
labels: [string/array]
}
```

Expand Down Expand Up @@ -148,4 +150,7 @@ module.exports = function (casper, scenario, vp) {
```

## TODO
- CLI command for first setup
- [x] add label to task cofig
- [x] add the support for multiple scenarios
- [ ] add country to init config
- [ ] yeoman generator
44 changes: 28 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,48 +22,60 @@ const bracco = {

buildConfig(options) {
let scenarios = [];
let tags = [];
let conf = this.conf;

// read tags option
if(Array.isArray(options.tags)) {
let tags = (options.tags) ? options.tags : false;
tags = (tags && !Array.isArray(tags)) ? [tags] : tags;

if(options.tags.length > 0) {
tags = tags.concat(options.tags);
}

} else if(options.tags !== '' && options.tags) {
tags.push(options.tags);
}
let labels = (options.labels) ? options.labels : false;
labels = (labels && !Array.isArray(labels)) ? [labels] : labels;

let scenarioNames = (options.scenario) ? options.scenario : false;
scenarioNames = (scenarioNames && !Array.isArray(scenarioNames)) ? [scenarioNames] : scenarioNames;

// build path for globby
let root = path.normalize(process.cwd());
let pathScenario = (options.hasOwnProperty('scenario')) ? root + '/scenarios/' + options.scenario + '/*.js' : root + '/scenarios/**/*.js';
let scenariosPaths = [];

if (scenarioNames.length > 0) {
scenariosPaths = scenarioNames.map(e => {
return root + '/scenarios/' + e + '/*.js'
})
} else {
scenariosPaths.push(root + '/scenarios/**/*.js');
}

// get scenarios from js files
globby.sync([pathScenario]).map(e => {
globby.sync(scenariosPaths).map(e => {
let getScenario = require(e);
let newScenarios = [];

if(tags.length > 0) {

if (tags && tags.length > 0) {

getScenario(conf)
.filter(scenario => scenario.hasOwnProperty('tags'))
.map(scenario => {

scenario.tags.map(cTag => {
let match = _.findIndex(tags, o => o === cTag );
if(match !== -1) {
if (match !== -1) {
newScenarios.push(Object.assign({}, defaultScenario, scenario));
}
});

});
});

} else {

newScenarios = getScenario(conf).map(scenario => Object.assign({}, defaultScenario, scenario));
}

if(labels && labels.length > 0) {
newScenarios = newScenarios
.filter(scenario => scenario.hasOwnProperty('label'))
.filter(scenario => {
return labels.indexOf(scenario.label) === 0
});
}

scenarios = scenarios.concat(newScenarios);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "brakko",
"version": "1.0.2",
"version": "1.1.0",
"description": "Simple runner based on backstopJs for Visual Regression Test",
"keywords": [
"backstopjs",
Expand Down

0 comments on commit f064274

Please sign in to comment.