Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit 182794a

Browse files
committed
Upgrade cucumber to version 6
1 parent ca75f18 commit 182794a

File tree

8 files changed

+347
-114
lines changed

8 files changed

+347
-114
lines changed

package-lock.json

Lines changed: 306 additions & 76 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"chai": "4.3.4",
5050
"clone": "2.1.2",
5151
"cross-spawn": "7.0.3",
52-
"cucumber": "1.3.2",
52+
"cucumber": "6.0.5",
5353
"eslint": "6.8.0",
5454
"eslint-config-airbnb": "17.1.1",
5555
"eslint-config-airbnb-base": "13.2.0",

scripts/cucumber.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ const args = [
1414
'test/cucumber/support/',
1515
'-r',
1616
'test/cucumber/steps/',
17-
'-f',
18-
'pretty',
1917
'node_modules/gavel-spec/features/'
2018
];
2119

test/cucumber/steps/cli.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1+
const { defineSupportCode } = require('cucumber');
12
const { assert } = require('chai');
23

3-
module.exports = function() {
4-
this.Given(
4+
defineSupportCode(function({ Then, When, Given }) {
5+
Given(
56
/^(I record (expected|actual) raw HTTP message:)|(a header is missing in actual message:)$/,
6-
function(_1, _2, _3, command) {
7+
function(_1, _2, command) {
78
this.commands.push(command);
89
}
910
);
1011

11-
this.When(
12+
When(
1213
'I validate the message using the following Gavel command:',
1314
async function(command) {
1415
this.commands.push(command);
1516
this.exitCode = await this.executeCommands(this.commands);
1617
}
1718
);
1819

19-
this.Then(/^exit status is (\d+)$/, function(expectedExitCode) {
20+
Then(/^exit status is (\d+)$/, function(expectedExitCode) {
2021
assert.equal(
2122
this.exitCode,
2223
expectedExitCode,
2324
`Expected process to exit with code ${expectedExitCode}, but got ${this.exitCode}.`
2425
);
2526
});
26-
};
27+
});

test/cucumber/steps/fields.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
const { defineSupportCode } = require('cucumber');
12
const chai = require('chai');
23
const parseJson = require('../../../lib/utils/parseJson');
34

45
chai.config.truncateThreshold = 0;
56
const { expect } = chai;
67

7-
module.exports = function() {
8-
this.Then(/^the result field "([^"]*)" equals:$/, function(
8+
defineSupportCode(function({ Then }) {
9+
Then(/^the result field "([^"]*)" equals:$/, function(
910
fieldName,
1011
expectedJson
1112
) {
@@ -14,4 +15,4 @@ module.exports = function() {
1415

1516
expect(actual).to.deep.equal(expected);
1617
});
17-
};
18+
});

test/cucumber/steps/general.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
1+
const { defineSupportCode } = require('cucumber');
12
const { expect } = require('chai');
23
const parseJson = require('../../../lib/utils/parseJson');
34

4-
module.exports = function() {
5-
this.Given(
6-
/^I expect the following HTTP (message|request|response):$/i,
7-
function(_, expectedMessage) {
8-
this.expected = parseJson(expectedMessage);
9-
}
10-
);
5+
defineSupportCode(function({ Then, When, Given }) {
6+
Given(/^I expect the following HTTP (message|request|response):$/i, function(
7+
_,
8+
expectedMessage
9+
) {
10+
this.expected = parseJson(expectedMessage);
11+
});
1112

12-
this.Given(/^the actual HTTP (message|request|response) equals:$/i, function(
13+
Given(/^the actual HTTP (message|request|response) equals:$/i, function(
1314
_,
1415
actualMessage
1516
) {
1617
this.actual = parseJson(actualMessage);
1718
});
1819

1920
// Inline value assertion.
20-
this.Given(/^the actual "([^"]*)" is "([^"]*)"/, function(fieldName, value) {
21+
Given(/^the actual "([^"]*)" is "([^"]*)"/, function(fieldName, value) {
2122
this.actual[fieldName] = value;
2223
});
2324

24-
this.Given(/^I expect "([^"]*)" to be "([^"]*)"$/, function(
25+
Given(/^I expect "([^"]*)" to be "([^"]*)"$/, function(
2526
fieldName,
2627
expectedValue
2728
) {
2829
this.expected[fieldName] = expectedValue;
2930
});
3031

31-
this.Given(/^I expect "([^"]*)" to equal:$/, function(fieldName, codeBlock) {
32+
Given(/^I expect "([^"]*)" to equal:$/, function(fieldName, codeBlock) {
3233
// Perform conditional code block parsing (if headers, etc.)
3334
this.expected[fieldName] = this.transformCodeBlock(fieldName, codeBlock);
3435
});
3536

36-
this.Given(/^I expect "body" to match the following "([^"]*)":$/, function(
37+
Given(/^I expect "body" to match the following "([^"]*)":$/, function(
3738
bodyType,
3839
value
3940
) {
@@ -48,27 +49,27 @@ module.exports = function() {
4849
});
4950

5051
// Block value assertion.
51-
this.Given(/^the actual "([^"]*)" equals:$/, function(fieldName, codeBlock) {
52+
Given(/^the actual "([^"]*)" equals:$/, function(fieldName, codeBlock) {
5253
// Also perform conditional code parsing
5354
this.actual[fieldName] = this.transformCodeBlock(fieldName, codeBlock);
5455
});
5556

5657
// Actions
57-
this.When('Gavel validates the HTTP message', function() {
58+
When('Gavel validates the HTTP message', function() {
5859
this.validate();
5960
});
6061

6162
// Vocabulary proxy over the previous action for better scenarios readability.
62-
this.When(/^I call "gavel.validate(([^"]*))"$/, function(_, _command) {
63+
When(/^I call "gavel.validate(([^"]*))"$/, function(_command) {
6364
this.validate();
6465
});
6566

6667
// Assertions
67-
this.Then(/^the actual HTTP message is( NOT)? valid$/i, function(isInvalid) {
68+
Then(/^the actual HTTP message is( NOT)? valid$/i, function(isInvalid) {
6869
expect(this.result).to.have.property('valid', !isInvalid);
6970
});
7071

71-
this.Then('the validation result is:', function(expectedResult) {
72+
Then('the validation result is:', function(expectedResult) {
7273
const stringifiedActual = JSON.stringify(this.result, null, 2);
7374

7475
expect(this.result).to.deep.equal(
@@ -85,10 +86,10 @@ ${expectedResult}
8586
);
8687
});
8788

88-
this.Then(/^the "(\w+)" is( NOT)? valid$/i, function(fieldName, isInvalid) {
89+
Then(/^the "(\w+)" is( NOT)? valid$/i, function(fieldName, isInvalid) {
8990
expect(this.result).to.have.nested.property(
9091
`fields.${fieldName}.valid`,
9192
!isInvalid
9293
);
9394
});
94-
};
95+
});

test/cucumber/support/hooks.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
const { defineSupportCode } = require('cucumber');
12
const { exec } = require('child_process');
23

3-
module.exports = function() {
4-
this.Before({ tags: ['@cli', '@cli'] }, function(scenario, callback) {
4+
defineSupportCode(function({ After, Before }) {
5+
Before({ tags: '@cli and @cli' }, function(scenarioResult, callback) {
56
const proc = exec('mkdir /tmp/gavel-test-`date +%s`', function(
67
err,
78
stdout,
@@ -15,7 +16,7 @@ module.exports = function() {
1516
proc.on('exit', callback);
1617
});
1718

18-
return this.After({ tags: ['@cli', '@cli'] }, function(scenario, callback) {
19+
After({ tags: '@cli and @cli' }, function(scenarioResult, callback) {
1920
const proc = exec('rm -rf /tmp/gavel-test-*', function(
2021
err,
2122
stdout,
@@ -28,4 +29,4 @@ module.exports = function() {
2829

2930
proc.on('exit', callback);
3031
});
31-
};
32+
});

test/cucumber/support/world.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const { defineSupportCode } = require('cucumber');
12
const { assert } = require('chai');
23
const { exec } = require('child_process');
34
const gavel = require('../../../build');
@@ -167,6 +168,6 @@ Make sure it's in the "Header-Name: value" format.
167168
}
168169
}
169170

170-
module.exports = function() {
171-
this.World = World;
172-
};
171+
defineSupportCode(function({ setWorldConstructor }) {
172+
setWorldConstructor(World);
173+
});

0 commit comments

Comments
 (0)