Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.
Open
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
382 changes: 306 additions & 76 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"chai": "4.3.4",
"clone": "2.1.2",
"cross-spawn": "7.0.3",
"cucumber": "1.3.2",
"cucumber": "6.0.5",
"eslint": "6.8.0",
"eslint-config-airbnb": "17.1.1",
"eslint-config-airbnb-base": "13.2.0",
Expand Down
2 changes: 0 additions & 2 deletions scripts/cucumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ const args = [
'test/cucumber/support/',
'-r',
'test/cucumber/steps/',
'-f',
'pretty',
'node_modules/gavel-spec/features/'
];

Expand Down
13 changes: 7 additions & 6 deletions test/cucumber/steps/cli.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
const { defineSupportCode } = require('cucumber');
const { assert } = require('chai');

module.exports = function() {
this.Given(
defineSupportCode(function({ Then, When, Given }) {
Given(
/^(I record (expected|actual) raw HTTP message:)|(a header is missing in actual message:)$/,
function(_1, _2, _3, command) {
function(_1, _2, command) {
this.commands.push(command);
}
);

this.When(
When(
'I validate the message using the following Gavel command:',
async function(command) {
this.commands.push(command);
this.exitCode = await this.executeCommands(this.commands);
}
);

this.Then(/^exit status is (\d+)$/, function(expectedExitCode) {
Then(/^exit status is (\d+)$/, function(expectedExitCode) {
assert.equal(
this.exitCode,
expectedExitCode,
`Expected process to exit with code ${expectedExitCode}, but got ${this.exitCode}.`
);
});
};
});
7 changes: 4 additions & 3 deletions test/cucumber/steps/fields.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const { defineSupportCode } = require('cucumber');
const chai = require('chai');
const parseJson = require('../../../lib/utils/parseJson');

chai.config.truncateThreshold = 0;
const { expect } = chai;

module.exports = function() {
this.Then(/^the result field "([^"]*)" equals:$/, function(
defineSupportCode(function({ Then }) {
Then(/^the result field "([^"]*)" equals:$/, function(
fieldName,
expectedJson
) {
Expand All @@ -14,4 +15,4 @@ module.exports = function() {

expect(actual).to.deep.equal(expected);
});
};
});
39 changes: 20 additions & 19 deletions test/cucumber/steps/general.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
const { defineSupportCode } = require('cucumber');
const { expect } = require('chai');
const parseJson = require('../../../lib/utils/parseJson');

module.exports = function() {
this.Given(
/^I expect the following HTTP (message|request|response):$/i,
function(_, expectedMessage) {
this.expected = parseJson(expectedMessage);
}
);
defineSupportCode(function({ Then, When, Given }) {
Given(/^I expect the following HTTP (message|request|response):$/i, function(
_,
expectedMessage
) {
this.expected = parseJson(expectedMessage);
});

this.Given(/^the actual HTTP (message|request|response) equals:$/i, function(
Given(/^the actual HTTP (message|request|response) equals:$/i, function(
_,
actualMessage
) {
this.actual = parseJson(actualMessage);
});

// Inline value assertion.
this.Given(/^the actual "([^"]*)" is "([^"]*)"/, function(fieldName, value) {
Given(/^the actual "([^"]*)" is "([^"]*)"/, function(fieldName, value) {
this.actual[fieldName] = value;
});

this.Given(/^I expect "([^"]*)" to be "([^"]*)"$/, function(
Given(/^I expect "([^"]*)" to be "([^"]*)"$/, function(
fieldName,
expectedValue
) {
this.expected[fieldName] = expectedValue;
});

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

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

// Block value assertion.
this.Given(/^the actual "([^"]*)" equals:$/, function(fieldName, codeBlock) {
Given(/^the actual "([^"]*)" equals:$/, function(fieldName, codeBlock) {
// Also perform conditional code parsing
this.actual[fieldName] = this.transformCodeBlock(fieldName, codeBlock);
});

// Actions
this.When('Gavel validates the HTTP message', function() {
When('Gavel validates the HTTP message', function() {
this.validate();
});

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

// Assertions
this.Then(/^the actual HTTP message is( NOT)? valid$/i, function(isInvalid) {
Then(/^the actual HTTP message is( NOT)? valid$/i, function(isInvalid) {
expect(this.result).to.have.property('valid', !isInvalid);
});

this.Then('the validation result is:', function(expectedResult) {
Then('the validation result is:', function(expectedResult) {
const stringifiedActual = JSON.stringify(this.result, null, 2);

expect(this.result).to.deep.equal(
Expand All @@ -85,10 +86,10 @@ ${expectedResult}
);
});

this.Then(/^the "(\w+)" is( NOT)? valid$/i, function(fieldName, isInvalid) {
Then(/^the "(\w+)" is( NOT)? valid$/i, function(fieldName, isInvalid) {
expect(this.result).to.have.nested.property(
`fields.${fieldName}.valid`,
!isInvalid
);
});
};
});
9 changes: 5 additions & 4 deletions test/cucumber/support/hooks.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const { defineSupportCode } = require('cucumber');
const { exec } = require('child_process');

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

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

proc.on('exit', callback);
});
};
});
7 changes: 4 additions & 3 deletions test/cucumber/support/world.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { defineSupportCode } = require('cucumber');
const { assert } = require('chai');
const { exec } = require('child_process');
const gavel = require('../../../build');
Expand Down Expand Up @@ -167,6 +168,6 @@ Make sure it's in the "Header-Name: value" format.
}
}

module.exports = function() {
this.World = World;
};
defineSupportCode(function({ setWorldConstructor }) {
setWorldConstructor(World);
});