From bfe6c69a70dbc6f2c331f9a177fcee13739327c1 Mon Sep 17 00:00:00 2001 From: daniel bannert Date: Fri, 9 Oct 2015 00:48:46 +0200 Subject: [PATCH] fixes #7 | start working --- dist/parser.js | 18 ++++++++++++++++++ src/parser.js | 20 ++++++++++++++++++++ tests/fixture/describe.styl | 4 ++++ tests/specs/parser.js | 18 ++++++++++++++++++ tests/specs/parser.js.map | 2 +- tests/src/parser.test.js | 11 +++++++++++ 6 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 tests/fixture/describe.styl diff --git a/dist/parser.js b/dist/parser.js index 0157e8c..48b7c36 100644 --- a/dist/parser.js +++ b/dist/parser.js @@ -44,6 +44,24 @@ function extractTestsFromString(string) { return _lodash2['default'].map(_lodash2['default'].reject(string.split(/.*@it\s?/), _utils.isEmpty), extractTestFromString); } +function getDescribe(string, nummber) { + var describe = string.match(/@describe.*/g).map(_utils.trimNewlines); + + if (describe[nummber] !== '') { + return describe[nummber].replace('@describe ', ''); + } + + return ''; +} + +function extractMainDescribeFromTest(testString) { + var describe = getDescribe(testString, 0); +} + +function extractDescribeFromTest(string) { + var describe = getDescribe(testString, 1); +} + exports['default'] = function (file) { return extractTestsFromString(getFile(file)); }; diff --git a/src/parser.js b/src/parser.js index 0306926..9e48eef 100644 --- a/src/parser.js +++ b/src/parser.js @@ -35,6 +35,26 @@ function extractTestsFromString(string) { ); } +function getDescribe(string, nummber) { + const describe = string.match(/@describe.*/g).map(trimNewlines); + + if (describe[nummber] !== '') { + return describe[nummber].replace('@describe ', ''); + } + + return ''; +} + +function extractMainDescribeFromTest(testString) { + const describe = getDescribe(testString, 0); + +} + +function extractDescribeFromTest(string) { + const describe = getDescribe(testString, 1); + +} + export default function(file) { return extractTestsFromString(getFile(file)); } diff --git a/tests/fixture/describe.styl b/tests/fixture/describe.styl new file mode 100644 index 0000000..102181f --- /dev/null +++ b/tests/fixture/describe.styl @@ -0,0 +1,4 @@ +/** + * @describe test + * @describe test2 + */ diff --git a/tests/specs/parser.js b/tests/specs/parser.js index 204fd26..df090d0 100644 --- a/tests/specs/parser.js +++ b/tests/specs/parser.js @@ -44,6 +44,24 @@ function extractTestsFromString(string) { return _lodash2['default'].map(_lodash2['default'].reject(string.split(/.*@it\s?/), _utils.isEmpty), extractTestFromString); } +function getDescribe(string, nummber) { + var describe = string.match(/@describe.*/g).map(_utils.trimNewlines); + + if (describe[nummber] !== '') { + return describe[nummber].replace('@describe ', ''); + } + + return ''; +} + +function extractMainDescribeFromTest(testString) { + var describe = getDescribe(testString, 0); +} + +function extractDescribeFromTest(string) { + var describe = getDescribe(testString, 1); +} + exports['default'] = function (file) { return extractTestsFromString(getFile(file)); }; diff --git a/tests/specs/parser.js.map b/tests/specs/parser.js.map index 0c1055c..35edbbf 100644 --- a/tests/specs/parser.js.map +++ b/tests/specs/parser.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../src/parser.js"],"names":[],"mappings":";;;;;;kBAAe,IAAI;;;;wBACE,WAAW;;;;sBACb,QAAQ;;;;qBACW,SAAS;;AAE/C,SAAS,OAAO,CAAC,QAAQ,EAAE;AACzB,MAAM,YAAY,GAAG,oBAAa,gBAAG,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;;AAErE,SAAO,YAAY,CAAC;CACrB;;AAED,SAAS,qBAAqB,CAAC,UAAU,EAAE;AACzC,MAAI,IAAI,GAAG,UAAU,CAAC;;AAEtB,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACxC,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,GAAG,qBAAc,CAAC;AACjE,MAAI,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;;AAE9B,SAAO;AACL,eAAW,EAAE,WAAW;AACxB,eAAW,EAAE,YAAY,CAAC,CAAC,CAAC;AAC5B,eAAW,EAAE,sBAAS,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;GAC/C,CAAC;CACH;;AAED,SAAS,sBAAsB,CAAC,MAAM,EAAE;;;AAGtC,SAAO,oBAAO,GAAG,CACf,oBAAO,MAAM,CACX,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,iBAEzB,EACD,qBAAqB,CACtB,CAAC;CACH;;qBAEc,UAAS,IAAI,EAAE;AAC5B,SAAO,sBAAsB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;CAC9C","file":"parser.js","sourcesContent":["import fs from 'fs';\nimport cleanCSS from 'clean-css';\nimport lodash from 'lodash';\nimport { trimNewlines, isEmpty } from './utils';\n\nfunction getFile(filePath) {\n const fileContents = trimNewlines(fs.readFileSync(filePath, 'utf8'));\n\n return fileContents;\n}\n\nfunction extractTestFromString(testString) {\n let test = testString;\n\n const description = test.match(/.*/)[0];\n const stylusAndCss = test.split(/.*@expect.*/).map(trimNewlines);\n test = test.replace(/.*/, '');\n\n return {\n description: description,\n givenStylus: stylusAndCss[0],\n expectedCss: cleanCSS.process(stylusAndCss[1]),\n };\n}\n\nfunction extractTestsFromString(string) {\n // Filter empty strings out, it seems that the\n // @it line leaves an empty string entry behind in the array\n return lodash.map(\n lodash.reject(\n string.split(/.*@it\\s?/),\n isEmpty\n ),\n extractTestFromString\n );\n}\n\nexport default function(file) {\n return extractTestsFromString(getFile(file));\n}\n"]} \ No newline at end of file +{"version":3,"sources":["../../src/parser.js"],"names":[],"mappings":";;;;;;kBAAe,IAAI;;;;wBACE,WAAW;;;;sBACb,QAAQ;;;;qBACW,SAAS;;AAE/C,SAAS,OAAO,CAAC,QAAQ,EAAE;AACzB,MAAM,YAAY,GAAG,oBAAa,gBAAG,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;;AAErE,SAAO,YAAY,CAAC;CACrB;;AAED,SAAS,qBAAqB,CAAC,UAAU,EAAE;AACzC,MAAI,IAAI,GAAG,UAAU,CAAC;;AAEtB,MAAM,WAAW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anCSS from 'clean-css';\nimport lodash from 'lodash';\nimport { trimNewlines, isEmpty } from './utils';\n\nfunction getFile(filePath) {\n const fileContents = trimNewlines(fs.readFileSync(filePath, 'utf8'));\n\n return fileContents;\n}\n\nfunction extractTestFromString(testString) {\n let test = testString;\n\n const description = test.match(/.*/)[0];\n const stylusAndCss = test.split(/.*@expect.*/).map(trimNewlines);\n test = test.replace(/.*/, '');\n\n return {\n description: description,\n givenStylus: stylusAndCss[0],\n expectedCss: cleanCSS.process(stylusAndCss[1]),\n };\n}\n\nfunction extractTestsFromString(string) {\n // Filter empty strings out, it seems that the\n // @it line leaves an empty string entry behind in the array\n return lodash.map(\n lodash.reject(\n string.split(/.*@it\\s?/),\n isEmpty\n ),\n extractTestFromString\n );\n}\n\nfunction getDescribe(string, nummber) {\n const describe = string.match(/@describe.*/g).map(trimNewlines);\n\n if (describe[nummber] !== '') {\n return describe[nummber].replace('@describe ', '');\n }\n\n return '';\n}\n\nfunction extractMainDescribeFromTest(testString) {\n const describe = getDescribe(testString, 0);\n\n}\n\nfunction extractDescribeFromTest(string) {\n const describe = getDescribe(testString, 1);\n\n}\n\nexport default function(file) {\n return extractTestsFromString(getFile(file));\n}\n"]} \ No newline at end of file diff --git a/tests/src/parser.test.js b/tests/src/parser.test.js index ecac419..088f638 100644 --- a/tests/src/parser.test.js +++ b/tests/src/parser.test.js @@ -16,3 +16,14 @@ describe('#parser:extractTestFromString', function() { // assert.equal(extractTestFromString('./tests/fixture/textFile.txt'), 'dasdada'); }); }); + +describe('#parser:getDescribe', function() { + it('get describe', function() { + var getDescribe = utils.__get__('getDescribe'); + var getFile = utils.__get__('getFile'); + var string = getFile('./tests/fixture/describe.styl'); + + assert.equal(getDescribe(string, 0), 'test'); + assert.equal(getDescribe(string, 1), 'test2'); + }); +});