diff --git a/features/formatter_paths.feature b/features/formatter_paths.feature new file mode 100644 index 000000000..db11d508c --- /dev/null +++ b/features/formatter_paths.feature @@ -0,0 +1,44 @@ +Feature: Formatter Paths + + Background: + Given a file named "features/a.feature" with: + """ + Feature: some feature + Scenario: some scenario + Given a passing step + """ + And a file named "features/step_definitions/cucumber_steps.js" with: + """ + import {defineSupportCode} from 'cucumber' + + defineSupportCode(({Given}) => { + Given(/^a passing step$/, function() {}) + }) + """ + + Scenario: Relative path + When I run cucumber.js with `-f summary:summary.txt` + Then the file "summary.txt" has the text: + """ + 1 scenario (1 passed) + 1 step (1 passed) + + """ + + Scenario: Absolute path + Given "{{{tmpDir}}}" is an absolute path + When I run cucumber.js with `-f summary:{{{tmpDir}}}/summary.txt` + Then the file "{{{tmpDir}}}/summary.txt" has the text: + """ + 1 scenario (1 passed) + 1 step (1 passed) + + """ + + Scenario: Invalid path + When I run cucumber.js with `-f summary:invalid/summary.txt` + Then it fails + And the error output contains the text: + """ + ENOENT + """ diff --git a/features/multiple_formatters.feature b/features/multiple_formatters.feature index 5b882a16a..87ea5c5dc 100644 --- a/features/multiple_formatters.feature +++ b/features/multiple_formatters.feature @@ -32,11 +32,3 @@ Feature: Multiple Formatters 1 step (1 passed) """ - - Scenario: Invalid path - When I run cucumber.js with `-f progress -f pretty:invalid/pretty.txt` - Then it fails - And the error output contains the text: - """ - ENOENT - """ diff --git a/features/step_definitions/cli_steps.js b/features/step_definitions/cli_steps.js index f641cc284..e6679d33e 100644 --- a/features/step_definitions/cli_steps.js +++ b/features/step_definitions/cli_steps.js @@ -4,11 +4,13 @@ import { defineSupportCode } from '../../' import { expect } from 'chai' import { normalizeText } from '../support/helpers' import stringArgv from 'string-argv' +import Mustache from 'mustache' defineSupportCode(function({ When, Then }) { When(/^I run cucumber.js(?: with `(|.+)`)?$/, { timeout: 10000 }, function( args ) { + args = Mustache.render(args || '', this) args = stringArgv(args || '') return this.run(this.localExecutablePath, args) }) diff --git a/features/step_definitions/file_steps.js b/features/step_definitions/file_steps.js index 09e818d1f..9e0a1f525 100644 --- a/features/step_definitions/file_steps.js +++ b/features/step_definitions/file_steps.js @@ -7,6 +7,7 @@ import { promisify } from 'bluebird' import fs from 'mz/fs' import fsExtra from 'fs-extra' import path from 'path' +import Mustache from 'mustache' defineSupportCode(function({ Given, Then }) { Given(/^a file named "(.*)" with:$/, function(filePath, fileContent) { @@ -27,8 +28,14 @@ defineSupportCode(function({ Given, Then }) { return promisify(fsExtra.mkdirp)(absoluteFilePath) }) + Given(/^"([^"]*)" is an absolute path$/, function(filePath) { + filePath = Mustache.render(filePath, this) + expect(path.isAbsolute(filePath)).to.be.true + }) + Then(/^the file "([^"]*)" has the text:$/, async function(filePath, text) { - const absoluteFilePath = path.join(this.tmpDir, filePath) + filePath = Mustache.render(filePath, this) + const absoluteFilePath = path.resolve(this.tmpDir, filePath) const content = await fs.readFile(absoluteFilePath, 'utf8') const actualContent = normalizeText(content) const expectedContent = normalizeText(text) diff --git a/package.json b/package.json index c7f2cb436..384b52dfb 100644 --- a/package.json +++ b/package.json @@ -175,6 +175,7 @@ "eslint-plugin-prettier": "^2.1.2", "fs-extra": "^3.0.1", "mocha": "^3.1.2", + "mustache": "^2.3.0", "nyc": "^11.0.2", "prettier": "^1.5.2", "regenerator-runtime": "^0.10.0", diff --git a/src/cli/index.js b/src/cli/index.js index ee019ebc8..eeb464b22 100644 --- a/src/cli/index.js +++ b/src/cli/index.js @@ -35,7 +35,7 @@ export default class Cli { await Promise.map(formats, async ({ type, outputTo }) => { let stream = this.stdout if (outputTo) { - let fd = await fs.open(path.join(this.cwd, outputTo), 'w') + let fd = await fs.open(path.resolve(this.cwd, outputTo), 'w') stream = fs.createWriteStream(null, { fd }) streamsToClose.push(stream) } diff --git a/yarn.lock b/yarn.lock index a2652dc4d..598f16817 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2767,6 +2767,10 @@ ms@2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" +mustache@^2.3.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/mustache/-/mustache-2.3.0.tgz#4028f7778b17708a489930a6e52ac3bca0da41d0" + mute-stream@0.0.7: version "0.0.7" resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab"