diff --git a/.circleci/config.yml b/.circleci/config.yml index b4bfcfb..dadc6e7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -27,7 +27,7 @@ jobs: node scripts/prepare-test.js export PATH=$PATH:$(pwd)/node_modules/.bin cd ./test - npm test + cucumber-js features workflows: version: 2 diff --git a/features/support/steps.js b/features/support/steps.js new file mode 100644 index 0000000..6955142 --- /dev/null +++ b/features/support/steps.js @@ -0,0 +1,48 @@ +const { expect } = require('chai'); +const fs = require('fs-extra'); +const os = require('os'); +const path = require('path'); +const which = require('which'); +const childProcess = require('child_process'); +const { Given, When, Then, Before, After } = require('cucumber'); + + +Before(function () { + this.dir = fs.mkdtempSync(path.join(os.tmpdir(), 'dredd-hooks-template-')); + this.env = { ...process.env }; +}); + +After(function () { + fs.remove(this.dir); +}); + + +Given(/^I have "([^"]+)" command installed$/, function (command) { + which.sync(command); // throws if the command is not found +}); + +Given(/^a file named "([^"]+)" with:$/, function (filename, content) { + fs.writeFileSync(path.join(this.dir, filename), content); +}); + +Given(/^I set the environment variables to:$/, function (env) { + this.env = { ...this.env, ...env.rowsHash() }; +}); + + +When(/^I run `([^`]+)`$/, function (command) { + this.proc = childProcess.spawnSync(command, [], { + shell: true, + cwd: this.dir, + env: this.env, + }); +}); + + +Then('the exit status should be {int}', function (number) { + expect(this.proc.status).to.equal(parseInt(number, 10)); +}); + +Then('the output should contain:', function (output) { + expect(this.proc.stdout.toString() + this.proc.stderr.toString()).to.contain(output); +}); diff --git a/package.json b/package.json index c8e6d1d..8516bb9 100644 --- a/package.json +++ b/package.json @@ -2,16 +2,19 @@ "name": "dredd-hooks-template", "version": "1.0.0", "description": "A meta-package to install the testing dependencies of the Dredd Hooks template test suite", + "engines": { + "node": ">=10" + }, "devDependencies": { "chai": "4.2.0", "cucumber": "5.1.0", "dredd": "9.0.5", "fs-extra": "7.0.1", "gherkin-lint": "3.0.3", - "glob": "7.1.3" + "glob": "7.1.3", + "which": "1.3.1" }, "scripts": { - "test": "cucumber-js", "lint:features": "gherkin-lint features/" }, "repository": {