Skip to content
This repository has been archived by the owner on Mar 11, 2019. It is now read-only.

Commit

Permalink
Added link between suite matrix and test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanLorenzo committed Jun 3, 2015
1 parent ea28c3b commit fb93c27
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 3 deletions.
29 changes: 26 additions & 3 deletions index.js
Expand Up @@ -9,14 +9,16 @@ var _ = require('lodash');
module.exports = function(inputFilePaths) {
var promises = inputFilePaths.map(_handleSingleFilePath);

return Promise.all(promises).then(function(results) {
return Promise.all(promises).then(function(suitesPerFile) {

var allSuites = _.flatten(suitesPerFile);
var mergedSuites = _mergeSuites(allSuites);
_linkSuiteVariables(mergedSuites);

// Sometimes some promises have failed
if (errorHandler.hasAnyError()) {
return Promise.reject(errorHandler.errors);
} else {
var validSuites = _.flatten(results);
var mergedSuites = _mergeSuites(validSuites);
return Promise.resolve(mergedSuites);
}

Expand All @@ -25,6 +27,27 @@ module.exports = function(inputFilePaths) {
});
};

function _linkSuiteVariables(mergedSuites) {
mergedSuites.forEach(function(suite) {
if(typeof suite.variables !== 'undefined') {
_linkSuiteVariablesToTestcases(suite.variables, suite.testcases);
delete suite.variables;
}
});
}

function _linkSuiteVariablesToTestcases(suiteVariables, testcases) {
testcases.forEach(function(testcase) {
var testcaseVariables = suiteVariables[testcase.id];

if (typeof testcaseVariables === 'undefined') {
errorHandler.add(new Error('The id "' + testcase.id + '" mentioned in the table is not defined in the suite'));
} else {
testcase.variablesFromSuite = testcaseVariables;
}
});
}

function _handleSingleFilePath(inputFilePath) {
return readFile(inputFilePath, 'utf8').then(function(text) {
var json = parseMarkdown(text);
Expand Down
31 changes: 31 additions & 0 deletions test/integration/suite-variables.js
@@ -0,0 +1,31 @@
'use strict';

var assert = require('chai').assert;
var mainPackage = require('../../index');

describe('The main package', function() {

it('should handle the suite variables', function() {
return mainPackage(['test/integration/suite-variables.md']).then(function(actualResult) {
assert.deepEqual(actualResult, [{
"name": "SMS suite",
"testcases": [{
"id": "idone",
"instructions": "Instructions",
"state": "active",
"bug": 1,
"userStory": 1,
"variablesFromSuite": ["var1", "var3"]
}, {
"id": "idtwo",
"instructions": "Instructions 2",
"state": "disabled",
"bug": 2,
"userStory": 2,
"variablesFromSuite": ["var1"]
}]
}]);
});
});

});
20 changes: 20 additions & 0 deletions test/integration/suite-variables.md
@@ -0,0 +1,20 @@
# SMS suite

| var1 | var2 | var3 |
:-- |:-:|:-:|:-:
idone | x | | x
idtwo | x | |


## idone
`bug 1 `
`story 1`

Instructions

## idtwo
`bug 2`
`story 2`
`disabled`

Instructions 2

0 comments on commit fb93c27

Please sign in to comment.