This repository has been archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: rewrite some basic steps to Node.js
- Loading branch information
1 parent
f5f77a4
commit 863eb96
Showing
3 changed files
with
54 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters