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

Commit

Permalink
refactor: rewrite some basic steps to Node.js
Browse files Browse the repository at this point in the history
  • Loading branch information
honzajavorek committed Apr 23, 2019
1 parent f5f77a4 commit 863eb96
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 48 additions & 0 deletions features/support/steps.js
Original file line number Diff line number Diff line change
@@ -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);
});
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 863eb96

Please sign in to comment.