From 117964d0e21e210622b3890df8c5d3fffb6302bd Mon Sep 17 00:00:00 2001 From: Vorobey Aleksandr Vladimirovich Date: Mon, 14 Jan 2019 18:44:07 +0300 Subject: [PATCH 1/7] Fix running tests with different data and with only --- lib/data/context.js | 2 +- test/data/sandbox/codecept.sddt.json | 11 +++++++++++ test/data/sandbox/ddt_test.sddt.js | 5 +++++ test/runner/interface_test.js | 16 ++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 test/data/sandbox/codecept.sddt.json create mode 100644 test/data/sandbox/ddt_test.sddt.js diff --git a/lib/data/context.js b/lib/data/context.js index d1f9d5fa3..733ed3bf7 100644 --- a/lib/data/context.js +++ b/lib/data/context.js @@ -31,7 +31,7 @@ module.exports = function (context) { context.xScenario(`${title} | ${dataRow.data}`); } else { opts.data = dataRow; - context.Scenario.only(`${title} | ${dataRow.data}`, opts, fn) + context.Scenario(`${title} | ${dataRow.data}`, opts, fn) .inject({ current: dataRow.data }); } }); diff --git a/test/data/sandbox/codecept.sddt.json b/test/data/sandbox/codecept.sddt.json new file mode 100644 index 000000000..46b907d3c --- /dev/null +++ b/test/data/sandbox/codecept.sddt.json @@ -0,0 +1,11 @@ +{ + "tests": "./*_test.sddt.js", + "timeout": 10000, + "output": "./output", + "helpers": { + }, + "include": {}, + "bootstrap": false, + "mocha": {}, + "name": "sandbox" +} diff --git a/test/data/sandbox/ddt_test.sddt.js b/test/data/sandbox/ddt_test.sddt.js new file mode 100644 index 000000000..6925ae432 --- /dev/null +++ b/test/data/sandbox/ddt_test.sddt.js @@ -0,0 +1,5 @@ +Feature('SDDT'); + +Data(['1', '2', '3']).only.Scenario('Should log array of strings', (I, current) => { + console.log(`Got array item ${current}`); +}); diff --git a/test/runner/interface_test.js b/test/runner/interface_test.js index a311933e5..f00c95558 100644 --- a/test/runner/interface_test.js +++ b/test/runner/interface_test.js @@ -71,6 +71,22 @@ describe('CodeceptJS Interface', () => { }); }); + it('should run all different data for tests with only', (done) => { + exec(config_run_config('codecept.sddt.json'), (err, stdout, stderr) => { + const output = stdout.replace(/in [0-9]ms/g, '').replace(/\r/g, ''); + output.should.include(`Got array item 1 + ✔ Should log array of strings | 1`); + + output.should.include(`Got array item 2 + ✔ Should log array of strings | 2`); + + output.should.include(`Got array item 3 + ✔ Should log array of strings | 3`); + assert(!err); + done(); + }); + }); + it('should execute expected promise chain', (done) => { exec(`${codecept_run} --verbose`, (err, stdout, stderr) => { const lines = stdout.match(/\S.+/g); From c809ad3534b623777a7303f9d6d34f4af4ad9cf6 Mon Sep 17 00:00:00 2001 From: Vorobey Aleksandr Vladimirovich Date: Mon, 14 Jan 2019 19:51:35 +0300 Subject: [PATCH 2/7] fix --- lib/data/context.js | 10 ++++++---- test/runner/interface_test.js | 8 ++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/data/context.js b/lib/data/context.js index 733ed3bf7..9572b6a88 100644 --- a/lib/data/context.js +++ b/lib/data/context.js @@ -11,11 +11,12 @@ module.exports = function (context) { opts = {}; } data.forEach((dataRow) => { + let dataTitle = `${title} | ${typeof dataRow.data === 'object' ? `${dataRow.data}` : `{${dataRow.data}}`}` if (dataRow.skip) { - context.xScenario(`${title} | ${dataRow.data}`); + context.xScenario(dataTitle); } else { opts.data = dataRow; - context.Scenario(`${title} | ${dataRow.data}`, opts, fn) + context.Scenario(dataTitle, opts, fn) .inject({ current: dataRow.data }); } }); @@ -27,11 +28,12 @@ module.exports = function (context) { opts = {}; } data.forEach((dataRow) => { + let dataTitle = `${title} | ${typeof dataRow.data === 'object' ? `${dataRow.data}` : `{${dataRow.data}}`}` if (dataRow.skip) { - context.xScenario(`${title} | ${dataRow.data}`); + context.xScenario(dataTitle); } else { opts.data = dataRow; - context.Scenario(`${title} | ${dataRow.data}`, opts, fn) + context.Scenario.only(dataTitle, opts, fn) .inject({ current: dataRow.data }); } }); diff --git a/test/runner/interface_test.js b/test/runner/interface_test.js index f00c95558..ae7ed637d 100644 --- a/test/runner/interface_test.js +++ b/test/runner/interface_test.js @@ -71,17 +71,17 @@ describe('CodeceptJS Interface', () => { }); }); - it('should run all different data for tests with only', (done) => { + it.only('should run all different data for tests with only', (done) => { exec(config_run_config('codecept.sddt.json'), (err, stdout, stderr) => { const output = stdout.replace(/in [0-9]ms/g, '').replace(/\r/g, ''); output.should.include(`Got array item 1 - ✔ Should log array of strings | 1`); + ✔ Should log array of strings | {1}`); output.should.include(`Got array item 2 - ✔ Should log array of strings | 2`); + ✔ Should log array of strings | {2}`); output.should.include(`Got array item 3 - ✔ Should log array of strings | 3`); + ✔ Should log array of strings | {3}`); assert(!err); done(); }); From d7e196499f440d98a9e2faec9ffe6742f1c02824 Mon Sep 17 00:00:00 2001 From: Vorobey Aleksandr Vladimirovich Date: Mon, 14 Jan 2019 19:54:23 +0300 Subject: [PATCH 3/7] remove only --- test/runner/interface_test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runner/interface_test.js b/test/runner/interface_test.js index ae7ed637d..0096c3340 100644 --- a/test/runner/interface_test.js +++ b/test/runner/interface_test.js @@ -71,7 +71,7 @@ describe('CodeceptJS Interface', () => { }); }); - it.only('should run all different data for tests with only', (done) => { + it('should run all different data for tests with only', (done) => { exec(config_run_config('codecept.sddt.json'), (err, stdout, stderr) => { const output = stdout.replace(/in [0-9]ms/g, '').replace(/\r/g, ''); output.should.include(`Got array item 1 From 3dd15aca1254b37ce6d8cb3fbfce11fa423c4865 Mon Sep 17 00:00:00 2001 From: Vorobey Aleksandr Vladimirovich Date: Mon, 14 Jan 2019 19:55:19 +0300 Subject: [PATCH 4/7] fix comment --- lib/data/context.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/data/context.js b/lib/data/context.js index 9572b6a88..cb9fe9eb9 100644 --- a/lib/data/context.js +++ b/lib/data/context.js @@ -11,7 +11,7 @@ module.exports = function (context) { opts = {}; } data.forEach((dataRow) => { - let dataTitle = `${title} | ${typeof dataRow.data === 'object' ? `${dataRow.data}` : `{${dataRow.data}}`}` + const dataTitle = `${title} | ${typeof dataRow.data === 'object' ? `${dataRow.data}` : `{${dataRow.data}}`}` if (dataRow.skip) { context.xScenario(dataTitle); } else { @@ -28,7 +28,7 @@ module.exports = function (context) { opts = {}; } data.forEach((dataRow) => { - let dataTitle = `${title} | ${typeof dataRow.data === 'object' ? `${dataRow.data}` : `{${dataRow.data}}`}` + const dataTitle = `${title} | ${typeof dataRow.data === 'object' ? `${dataRow.data}` : `{${dataRow.data}}`}` if (dataRow.skip) { context.xScenario(dataTitle); } else { From 4106d66cba1d2b2143435fbf6fd10ccd5a8a2843 Mon Sep 17 00:00:00 2001 From: Vorobey Aleksandr Vladimirovich Date: Mon, 14 Jan 2019 20:01:37 +0300 Subject: [PATCH 5/7] fix comments --- lib/data/context.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/data/context.js b/lib/data/context.js index cb9fe9eb9..2a2e3b2e7 100644 --- a/lib/data/context.js +++ b/lib/data/context.js @@ -11,7 +11,7 @@ module.exports = function (context) { opts = {}; } data.forEach((dataRow) => { - const dataTitle = `${title} | ${typeof dataRow.data === 'object' ? `${dataRow.data}` : `{${dataRow.data}}`}` + const dataTitle = `${title} | ${typeof dataRow.data === 'object' ? `${dataRow.data}` : `{${dataRow.data}}`}`; if (dataRow.skip) { context.xScenario(dataTitle); } else { @@ -28,7 +28,7 @@ module.exports = function (context) { opts = {}; } data.forEach((dataRow) => { - const dataTitle = `${title} | ${typeof dataRow.data === 'object' ? `${dataRow.data}` : `{${dataRow.data}}`}` + const dataTitle = `${title} | ${typeof dataRow.data === 'object' ? `${dataRow.data}` : `{${dataRow.data}}`}`; if (dataRow.skip) { context.xScenario(dataTitle); } else { From 1143be93b8a5da248ee1dc446c68bf27d2089654 Mon Sep 17 00:00:00 2001 From: Vorobey Aleksandr Vladimirovich Date: Mon, 14 Jan 2019 23:38:24 +0300 Subject: [PATCH 6/7] fix issue 1443 --- lib/data/context.js | 16 +++++++-- ...{codecept.sddt.json => codecept.addt.json} | 2 +- test/data/sandbox/codecept.gddt.json | 11 ++++++ .../{ddt_test.sddt.js => ddt_test.addt.js} | 2 +- test/data/sandbox/ddt_test.ddt.js | 7 ++++ test/data/sandbox/ddt_test.gddt.js | 8 +++++ test/runner/interface_test.js | 36 ++++++++++++++++--- 7 files changed, 74 insertions(+), 8 deletions(-) rename test/data/sandbox/{codecept.sddt.json => codecept.addt.json} (82%) create mode 100644 test/data/sandbox/codecept.gddt.json rename test/data/sandbox/{ddt_test.sddt.js => ddt_test.addt.js} (88%) create mode 100644 test/data/sandbox/ddt_test.gddt.js diff --git a/lib/data/context.js b/lib/data/context.js index 2a2e3b2e7..3be2563bf 100644 --- a/lib/data/context.js +++ b/lib/data/context.js @@ -11,7 +11,7 @@ module.exports = function (context) { opts = {}; } data.forEach((dataRow) => { - const dataTitle = `${title} | ${typeof dataRow.data === 'object' ? `${dataRow.data}` : `{${dataRow.data}}`}`; + const dataTitle = replaceTitle(title, dataRow); if (dataRow.skip) { context.xScenario(dataTitle); } else { @@ -28,7 +28,7 @@ module.exports = function (context) { opts = {}; } data.forEach((dataRow) => { - const dataTitle = `${title} | ${typeof dataRow.data === 'object' ? `${dataRow.data}` : `{${dataRow.data}}`}`; + const dataTitle = replaceTitle(title, dataRow); if (dataRow.skip) { context.xScenario(dataTitle); } else { @@ -48,6 +48,18 @@ module.exports = function (context) { }; }; +function replaceTitle(title, dataRow) { + if (typeof dataRow.data === 'object') { + return `${title} | ${JSON.stringify(dataRow.data)}`; + } + + if (Array.isArray(dataRow.data)) { + return `${title} | {${JSON.stringify(dataRow.data)}}`; + } + + return `${title} | {${dataRow.data}}`; +} + function isTableDataRow(row) { const has = Object.prototype.hasOwnProperty; return has.call(row, 'data') && has.call(row, 'skip'); diff --git a/test/data/sandbox/codecept.sddt.json b/test/data/sandbox/codecept.addt.json similarity index 82% rename from test/data/sandbox/codecept.sddt.json rename to test/data/sandbox/codecept.addt.json index 46b907d3c..e38a62cac 100644 --- a/test/data/sandbox/codecept.sddt.json +++ b/test/data/sandbox/codecept.addt.json @@ -1,5 +1,5 @@ { - "tests": "./*_test.sddt.js", + "tests": "./*_test.addt.js", "timeout": 10000, "output": "./output", "helpers": { diff --git a/test/data/sandbox/codecept.gddt.json b/test/data/sandbox/codecept.gddt.json new file mode 100644 index 000000000..013c61769 --- /dev/null +++ b/test/data/sandbox/codecept.gddt.json @@ -0,0 +1,11 @@ +{ + "tests": "./*_test.gddt.js", + "timeout": 10000, + "output": "./output", + "helpers": { + }, + "include": {}, + "bootstrap": false, + "mocha": {}, + "name": "sandbox" +} diff --git a/test/data/sandbox/ddt_test.sddt.js b/test/data/sandbox/ddt_test.addt.js similarity index 88% rename from test/data/sandbox/ddt_test.sddt.js rename to test/data/sandbox/ddt_test.addt.js index 6925ae432..b98aa95f7 100644 --- a/test/data/sandbox/ddt_test.sddt.js +++ b/test/data/sandbox/ddt_test.addt.js @@ -1,4 +1,4 @@ -Feature('SDDT'); +Feature('ADDT'); Data(['1', '2', '3']).only.Scenario('Should log array of strings', (I, current) => { console.log(`Got array item ${current}`); diff --git a/test/data/sandbox/ddt_test.ddt.js b/test/data/sandbox/ddt_test.ddt.js index 1c8320464..5c4086f56 100644 --- a/test/data/sandbox/ddt_test.ddt.js +++ b/test/data/sandbox/ddt_test.ddt.js @@ -23,6 +23,13 @@ Data(function* () { console.log(`Got changed login ${current[0]}`); }); +Data(function* () { + yield { user: 'nick' }; + yield { user: 'pick' }; +}).Scenario('Should log accounts4', (I, current) => { + console.log(`Got generator login ${current.user}`); +}); + Data(['1', '2', '3']).Scenario('Should log array of strings', (I, current) => { console.log(`Got array item ${current}`); }); diff --git a/test/data/sandbox/ddt_test.gddt.js b/test/data/sandbox/ddt_test.gddt.js new file mode 100644 index 000000000..9322aacdf --- /dev/null +++ b/test/data/sandbox/ddt_test.gddt.js @@ -0,0 +1,8 @@ +Feature('ADDT'); + +Data(function* () { + yield { user: 'nick' }; + yield { user: 'pick' }; +}).only.Scenario('Should log generator of strings', (I, current) => { + console.log(`Got generator login ${current.user}`); +}); diff --git a/test/runner/interface_test.js b/test/runner/interface_test.js index 0096c3340..84743a656 100644 --- a/test/runner/interface_test.js +++ b/test/runner/interface_test.js @@ -61,18 +61,33 @@ describe('CodeceptJS Interface', () => { ✔ Should log accounts2 | {"login":"collaborator","password":"222222"}`); output.should.include(`Got changed login nick - ✔ Should log accounts3 | nick`); + ✔ Should log accounts3 | ["nick","pick"]`); output.should.include(`Got changed login jack - ✔ Should log accounts3 | jack`); + ✔ Should log accounts3 | ["jack","sacj"]`); + + output.should.include(`Got generator login nick + ✔ Should log accounts4 | {"user":"nick"}`); + + output.should.include(`Got generator login pick + ✔ Should log accounts4 | {"user":"pick"}`); + + output.should.include(`Got array item 1 + ✔ Should log array of strings | {1}`); + + output.should.include(`Got array item 2 + ✔ Should log array of strings | {2}`); + + output.should.include(`Got array item 3 + ✔ Should log array of strings | {3}`); assert(!err); done(); }); }); - it('should run all different data for tests with only', (done) => { - exec(config_run_config('codecept.sddt.json'), (err, stdout, stderr) => { + it('should run all tests with data of array by only', (done) => { + exec(config_run_config('codecept.addt.json'), (err, stdout, stderr) => { const output = stdout.replace(/in [0-9]ms/g, '').replace(/\r/g, ''); output.should.include(`Got array item 1 ✔ Should log array of strings | {1}`); @@ -87,6 +102,19 @@ describe('CodeceptJS Interface', () => { }); }); + it('should run all tests with data of generator by only', (done) => { + exec(config_run_config('codecept.gddt.json'), (err, stdout, stderr) => { + const output = stdout.replace(/in [0-9]ms/g, '').replace(/\r/g, ''); + output.should.include(`Got generator login nick + ✔ Should log generator of strings | {"user":"nick"}`); + + output.should.include(`Got generator login pick + ✔ Should log generator of strings | {"user":"pick"}`); + assert(!err); + done(); + }); + }); + it('should execute expected promise chain', (done) => { exec(`${codecept_run} --verbose`, (err, stdout, stderr) => { const lines = stdout.match(/\S.+/g); From 5a3927f3e491849343ef2f488126bab2224bc2b8 Mon Sep 17 00:00:00 2001 From: Vorobey Aleksandr Vladimirovich Date: Tue, 15 Jan 2019 10:06:36 +0300 Subject: [PATCH 7/7] use JSON.stringify for all obj --- lib/data/context.js | 8 ++------ test/runner/interface_test.js | 12 ++++++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/data/context.js b/lib/data/context.js index 3be2563bf..0f5f1aa97 100644 --- a/lib/data/context.js +++ b/lib/data/context.js @@ -49,15 +49,11 @@ module.exports = function (context) { }; function replaceTitle(title, dataRow) { - if (typeof dataRow.data === 'object') { - return `${title} | ${JSON.stringify(dataRow.data)}`; - } - - if (Array.isArray(dataRow.data)) { + if (typeof dataRow.data !== 'object') { return `${title} | {${JSON.stringify(dataRow.data)}}`; } - return `${title} | {${dataRow.data}}`; + return `${title} | ${JSON.stringify(dataRow.data)}`; } function isTableDataRow(row) { diff --git a/test/runner/interface_test.js b/test/runner/interface_test.js index 84743a656..34fe59c67 100644 --- a/test/runner/interface_test.js +++ b/test/runner/interface_test.js @@ -73,13 +73,13 @@ describe('CodeceptJS Interface', () => { ✔ Should log accounts4 | {"user":"pick"}`); output.should.include(`Got array item 1 - ✔ Should log array of strings | {1}`); + ✔ Should log array of strings | {"1"}`); output.should.include(`Got array item 2 - ✔ Should log array of strings | {2}`); + ✔ Should log array of strings | {"2"}`); output.should.include(`Got array item 3 - ✔ Should log array of strings | {3}`); + ✔ Should log array of strings | {"3"}`); assert(!err); done(); @@ -90,13 +90,13 @@ describe('CodeceptJS Interface', () => { exec(config_run_config('codecept.addt.json'), (err, stdout, stderr) => { const output = stdout.replace(/in [0-9]ms/g, '').replace(/\r/g, ''); output.should.include(`Got array item 1 - ✔ Should log array of strings | {1}`); + ✔ Should log array of strings | {"1"}`); output.should.include(`Got array item 2 - ✔ Should log array of strings | {2}`); + ✔ Should log array of strings | {"2"}`); output.should.include(`Got array item 3 - ✔ Should log array of strings | {3}`); + ✔ Should log array of strings | {"3"}`); assert(!err); done(); });