diff --git a/lib/model/meta-suite.js b/lib/model/meta-suite.js deleted file mode 100644 index b7e8fe9..0000000 --- a/lib/model/meta-suite.js +++ /dev/null @@ -1,8 +0,0 @@ -'use strict'; - -function MetaSuite(name, suites) { - this.name = name; - this.suites = suites; -} - -module.exports = MetaSuite; diff --git a/lib/parsers/markdown.js b/lib/parsers/markdown.js index 0ab853c..b36bcef 100644 --- a/lib/parsers/markdown.js +++ b/lib/parsers/markdown.js @@ -2,15 +2,14 @@ var marked = require('marked'); var helper = require('./helper'); -var parseMetaSuite = require('./meta-suite'); +var parseSuite = require('./suite'); module.exports = function(text){ var lexer = new marked.Lexer(); var tokens = lexer.lex(text); - var metaSuiteTokens = helper.sortTokensByHierarchy(tokens, 'heading', 1); - var metaSuites = metaSuiteTokens.map(parseMetaSuite); + var suiteTokens = helper.sortTokensByHierarchy(tokens, 'heading', 1); + var suites = suiteTokens.map(parseSuite); - // FIXME This hack - return metaSuites[0]; + return suites; }; diff --git a/lib/parsers/meta-suite.js b/lib/parsers/meta-suite.js deleted file mode 100644 index ee474b1..0000000 --- a/lib/parsers/meta-suite.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; - -var parseSuite = require('./suite'); -var helper = require('./helper'); -var MetaSuite = require('../model/meta-suite'); - -module.exports = function(metaSuiteToken) { - var suiteTokens = helper.sortTokensByHierarchy(metaSuiteToken.childrenTokens, 'heading', 2); - var suites = suiteTokens.map(parseSuite); - return new MetaSuite(metaSuiteToken.name, suites); -}; diff --git a/lib/parsers/suite.js b/lib/parsers/suite.js index aad66fc..430e1d5 100644 --- a/lib/parsers/suite.js +++ b/lib/parsers/suite.js @@ -5,7 +5,7 @@ var helper = require('./helper'); var Suite = require('../model/suite'); module.exports = function(suiteToken) { - var testcasesTokens = helper.sortTokensByHierarchy(suiteToken.childrenTokens, 'heading', 3); + var testcasesTokens = helper.sortTokensByHierarchy(suiteToken.childrenTokens, 'heading', 2); var testcases = testcasesTokens.map(parseTestcase); return new Suite(suiteToken.name, testcases); }; diff --git a/test/e2e/default.md b/test/e2e/default.md index 87a8173..2a4c4c0 100644 --- a/test/e2e/default.md +++ b/test/e2e/default.md @@ -1,15 +1,13 @@ -# Functional +# Launch suite -## Launch suite - -### fxos.func.sanity.launch_contacts +## fxos.func.sanity.launch_contacts `bug 2 ` `story 1` `draft` Launch contacts! this is an updated version -### fxos.func.sanity.launch_music +## fxos.func.sanity.launch_music `bug 3 ` `story 3` `disabled` @@ -17,7 +15,7 @@ Launch contacts! this is an updated version Launch music -### fxos.func.sanity.launch_sms_repeated +## fxos.func.sanity.launch_sms_repeated `bug 3 ` `story 3` `xfail` @@ -27,7 +25,7 @@ Do it again. And again. -### fxos.func.parameterized.test +## fxos.func.parameterized.test Launch the dialog, insert :val1, :val2, :val3 and hit enter. ID | val1 | val2 | val3 | @@ -36,7 +34,7 @@ id1 | a | 1 | one one id2 | b | 2 | two two -### fxos.func.sanity.launch_rocketbar +## fxos.func.sanity.launch_rocketbar `bug 4` `story 3` `draft` diff --git a/test/e2e/main.js b/test/e2e/main.js index cb2b13b..b8a3430 100644 --- a/test/e2e/main.js +++ b/test/e2e/main.js @@ -7,52 +7,49 @@ describe('cli', function() { var exec = require('child_process').exec; exec("./cli.js test/e2e/default.md", function(error, stdout) { - var expectedResult = JSON.stringify({ - name: 'Functional', - suites: [{ - name: 'Launch suite', - testcases: [{ - id: 'fxos.func.sanity.launch_contacts', - instructions: 'Launch contacts! this is an updated version', - state: 'draft', - bug: 2, - userStory: 1 + var expectedResult = JSON.stringify([{ + name: 'Launch suite', + testcases: [{ + id: 'fxos.func.sanity.launch_contacts', + instructions: 'Launch contacts! this is an updated version', + state: 'draft', + bug: 2, + userStory: 1 + }, { + id: 'fxos.func.sanity.launch_music', + instructions: 'Launch music', + state: 'disabled', + bug: 3, + userStory: 3 + }, { + id: 'fxos.func.sanity.launch_sms_repeated', + instructions: 'Launch SMS and measure elapsed time\nDo it again.\nAnd again.', + state: 'xfail', + bug: 3, + userStory: 3 + }, { + id: 'fxos.func.parameterized.test', + instructions: 'Launch the dialog, insert :val1, :val2, :val3 and hit enter.', + state: 'active', + variables: [{ + ID: 'id1', + val1: 'a', + val2: '1', + val3: 'one one' }, { - id: 'fxos.func.sanity.launch_music', - instructions: 'Launch music', - state: 'disabled', - bug: 3, - userStory: 3 - }, { - id: 'fxos.func.sanity.launch_sms_repeated', - instructions: 'Launch SMS and measure elapsed time\nDo it again.\nAnd again.', - state: 'xfail', - bug: 3, - userStory: 3 - }, { - id: 'fxos.func.parameterized.test', - instructions: 'Launch the dialog, insert :val1, :val2, :val3 and hit enter.', - state: 'active', - variables: [{ - ID: 'id1', - val1: 'a', - val2: '1', - val3: 'one one' - }, { - ID: 'id2', - val1: 'b', - val2: '2', - val3: 'two two' - }] - }, { - id: 'fxos.func.sanity.launch_rocketbar', - instructions: 'Launch rocketbar', - state: 'draft', - bug: 4, - userStory: 3 + ID: 'id2', + val1: 'b', + val2: '2', + val3: 'two two' }] + }, { + id: 'fxos.func.sanity.launch_rocketbar', + instructions: 'Launch rocketbar', + state: 'draft', + bug: 4, + userStory: 3 }] - }); + }]); expectedResult += '\n'; assert.deepEqual(stdout, expectedResult); diff --git a/test/unit/parsers/markdown.js b/test/unit/parsers/markdown.js index 0eb2449..87b7339 100644 --- a/test/unit/parsers/markdown.js +++ b/test/unit/parsers/markdown.js @@ -6,18 +6,16 @@ var parseMarkdown = require('../../../lib/parsers/markdown'); describe('The magical ugly parser', function() { it('should transform the whole markdown file into this whole json file', function() { - var actualResult = parseMarkdown(['# Functional', + var actualResult = parseMarkdown(['# Launch suite', '', - '## Launch suite', - '', - '### fxos.func.sanity.launch_contacts', + '## fxos.func.sanity.launch_contacts', '`bug 2 `', '`story 1`', '`draft`', '', 'Launch contacts! this is an updated version', '', - '### fxos.func.sanity.launch_music', + '## fxos.func.sanity.launch_music', '`bug 3 `', '`story 3`', '`disabled`', @@ -25,7 +23,7 @@ describe('The magical ugly parser', function() { 'Launch music', '', '', - '### fxos.func.sanity.launch_sms_repeated', + '## fxos.func.sanity.launch_sms_repeated', '`bug 3 `', '`story 3`', '`xfail`', @@ -35,7 +33,7 @@ describe('The magical ugly parser', function() { 'And again.', '', '', - '### fxos.func.parameterized.test', + '## fxos.func.parameterized.test', 'Launch the dialog, insert :val1, :val2, :val3 and hit enter.', '', 'ID | val1 | val2 | val3 |', @@ -44,7 +42,7 @@ describe('The magical ugly parser', function() { 'id2 | b | 2 | two two', '', '', - '### fxos.func.sanity.launch_rocketbar', + '## fxos.func.sanity.launch_rocketbar', '`bug 4`', '`story 3`', '`draft`', @@ -52,52 +50,49 @@ describe('The magical ugly parser', function() { 'Launch rocketbar' ].join('\n')); - assert.deepEqual(actualResult, { - name: 'Functional', - suites: [{ - name: 'Launch suite', - testcases: [{ - "id": "fxos.func.sanity.launch_contacts", - "bug": 2, - "userStory": 1, - "state": "draft", - "instructions": "Launch contacts! this is an updated version" - }, { - "id": "fxos.func.sanity.launch_music", - "bug": 3, - "userStory": 3, - "state": "disabled", - "instructions": "Launch music" - }, { - "id": "fxos.func.sanity.launch_sms_repeated", - "bug": 3, - "userStory": 3, - "state": "xfail", - "instructions": "Launch SMS and measure elapsed time\nDo it again.\nAnd again." - }, { - "id": "fxos.func.parameterized.test", - "instructions": "Launch the dialog, insert :val1, :val2, :val3 and hit enter.", - "state": "active", - "variables": [{ - "ID": "id1", - "val1": "a", - "val2": "1", - "val3": "one one" - }, { - "ID": "id2", - "val1": "b", - "val2": "2", - "val3": "two two" - }] + assert.deepEqual(actualResult, [{ + name: 'Launch suite', + testcases: [{ + "id": "fxos.func.sanity.launch_contacts", + "bug": 2, + "userStory": 1, + "state": "draft", + "instructions": "Launch contacts! this is an updated version" + }, { + "id": "fxos.func.sanity.launch_music", + "bug": 3, + "userStory": 3, + "state": "disabled", + "instructions": "Launch music" + }, { + "id": "fxos.func.sanity.launch_sms_repeated", + "bug": 3, + "userStory": 3, + "state": "xfail", + "instructions": "Launch SMS and measure elapsed time\nDo it again.\nAnd again." + }, { + "id": "fxos.func.parameterized.test", + "instructions": "Launch the dialog, insert :val1, :val2, :val3 and hit enter.", + "state": "active", + "variables": [{ + "ID": "id1", + "val1": "a", + "val2": "1", + "val3": "one one" }, { - "id": "fxos.func.sanity.launch_rocketbar", - "bug": 4, - "userStory": 3, - "state": "draft", - "instructions": "Launch rocketbar" + "ID": "id2", + "val1": "b", + "val2": "2", + "val3": "two two" }] + }, { + "id": "fxos.func.sanity.launch_rocketbar", + "bug": 4, + "userStory": 3, + "state": "draft", + "instructions": "Launch rocketbar" }] - }); + }]); }); }); diff --git a/test/unit/parsers/meta-suite.js b/test/unit/parsers/meta-suite.js deleted file mode 100644 index bf2ee7b..0000000 --- a/test/unit/parsers/meta-suite.js +++ /dev/null @@ -1,67 +0,0 @@ -'use strict'; - -var sinon = require('sinon'); -var rewire = require('rewire'); -var metaSuiteParse = rewire('../../../lib/parsers/meta-suite'); - -describe('metaSuiteParse', function () { - - var parseSuiteMock = sinon.stub(); - var MetaSuiteMock = sinon.stub(); - var helperMock = { - sortTokensByHierarchy: sinon.stub() - }; - helperMock.sortTokensByHierarchy.returns([]); - - metaSuiteParse.__set__("parseSuite", parseSuiteMock); - metaSuiteParse.__set__("MetaSuite", MetaSuiteMock); - metaSuiteParse.__set__("helper", helperMock); - - afterEach(function() { - parseSuiteMock.reset(); - helperMock.sortTokensByHierarchy.reset(); - MetaSuiteMock.reset(); - }); - - describe('the main function', function() { - - var token; - - it('should pass the name of the suite', function() { - token = { - name: 'A suite', - }; - metaSuiteParse(token); - sinon.assert.calledWith(MetaSuiteMock, 'A suite'); - }); - - it('should pass the testcases of the suite', function() { - var children = ['child1', 'child2']; - token = { - name: 'A suite', - childrenTokens: children - }; - helperMock.sortTokensByHierarchy.returns(children); - parseSuiteMock.onCall(0).returns(children[0]); - parseSuiteMock.onCall(1).returns(children[1]); - - metaSuiteParse(token); - sinon.assert.calledWith(MetaSuiteMock, 'A suite', children); - }); - - it('should sort the children tokens by heading', function() { - token = { - childrenTokens: ['child'] - }; - metaSuiteParse(token); - sinon.assert.calledWith(helperMock.sortTokensByHierarchy, token.childrenTokens, 'heading', 2); - }); - - it('should delegate the parsing of the children tokens to parseSuite', function() { - helperMock.sortTokensByHierarchy.returns(['child1', 'child2']); - metaSuiteParse(token); - sinon.assert.calledTwice(parseSuiteMock); - }); - - }); -}); diff --git a/test/unit/parsers/suite.js b/test/unit/parsers/suite.js index 04cb75f..ce20bb8 100644 --- a/test/unit/parsers/suite.js +++ b/test/unit/parsers/suite.js @@ -54,7 +54,7 @@ describe('suiteParse', function () { childrenTokens: ['child'] }; suiteParse(token); - sinon.assert.calledWith(helperMock.sortTokensByHierarchy, token.childrenTokens, 'heading', 3); + sinon.assert.calledWith(helperMock.sortTokensByHierarchy, token.childrenTokens, 'heading', 2); }); it('should delegate the parsing of the children tokens to parseTestCase', function() {