Skip to content

Fix issue 1445 and 1443 #1446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions lib/data/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
});
Expand All @@ -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 });
}
});
Expand All @@ -46,6 +48,14 @@ module.exports = function (context) {
};
};

function replaceTitle(title, dataRow) {
if (typeof dataRow.data !== 'object') {
return `${title} | {${JSON.stringify(dataRow.data)}}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{${JSON.stringify(dataRow.data)}} - additional {} is not needed here

Copy link
Contributor Author

@Vorobeyko Vorobeyko Jan 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

additional {} needed, because in file ui.js on 139 line you used regexp /( \| {.+})?$/g where used {} and when data is array of string then codeceptjs runs test only with last data

}

return `${title} | ${JSON.stringify(dataRow.data)}`;
}

function isTableDataRow(row) {
const has = Object.prototype.hasOwnProperty;
return has.call(row, 'data') && has.call(row, 'skip');
Expand Down
11 changes: 11 additions & 0 deletions test/data/sandbox/codecept.addt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"tests": "./*_test.addt.js",
"timeout": 10000,
"output": "./output",
"helpers": {
},
"include": {},
"bootstrap": false,
"mocha": {},
"name": "sandbox"
}
11 changes: 11 additions & 0 deletions test/data/sandbox/codecept.gddt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"tests": "./*_test.gddt.js",
"timeout": 10000,
"output": "./output",
"helpers": {
},
"include": {},
"bootstrap": false,
"mocha": {},
"name": "sandbox"
}
5 changes: 5 additions & 0 deletions test/data/sandbox/ddt_test.addt.js
Original file line number Diff line number Diff line change
@@ -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}`);
});
7 changes: 7 additions & 0 deletions test/data/sandbox/ddt_test.ddt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
});
8 changes: 8 additions & 0 deletions test/data/sandbox/ddt_test.gddt.js
Original file line number Diff line number Diff line change
@@ -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}`);
});
48 changes: 46 additions & 2 deletions test/runner/interface_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down