diff --git a/lib/data/context.js b/lib/data/context.js index d1f9d5fa3..0f5f1aa97 100644 --- a/lib/data/context.js +++ b/lib/data/context.js @@ -11,11 +11,12 @@ module.exports = function (context) { opts = {}; } data.forEach((dataRow) => { + const dataTitle = replaceTitle(title, dataRow); 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) => { + const dataTitle = replaceTitle(title, dataRow); if (dataRow.skip) { - context.xScenario(`${title} | ${dataRow.data}`); + context.xScenario(dataTitle); } else { opts.data = dataRow; - context.Scenario.only(`${title} | ${dataRow.data}`, opts, fn) + context.Scenario.only(dataTitle, opts, fn) .inject({ current: dataRow.data }); } }); @@ -46,6 +48,14 @@ module.exports = function (context) { }; }; +function replaceTitle(title, dataRow) { + if (typeof dataRow.data !== 'object') { + return `${title} | {${JSON.stringify(dataRow.data)}}`; + } + + return `${title} | ${JSON.stringify(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.addt.json b/test/data/sandbox/codecept.addt.json new file mode 100644 index 000000000..e38a62cac --- /dev/null +++ b/test/data/sandbox/codecept.addt.json @@ -0,0 +1,11 @@ +{ + "tests": "./*_test.addt.js", + "timeout": 10000, + "output": "./output", + "helpers": { + }, + "include": {}, + "bootstrap": false, + "mocha": {}, + "name": "sandbox" +} 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.addt.js b/test/data/sandbox/ddt_test.addt.js new file mode 100644 index 000000000..b98aa95f7 --- /dev/null +++ b/test/data/sandbox/ddt_test.addt.js @@ -0,0 +1,5 @@ +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 a311933e5..34fe59c67 100644 --- a/test/runner/interface_test.js +++ b/test/runner/interface_test.js @@ -61,11 +61,55 @@ 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 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"}`); + + 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 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(); });