Skip to content

Commit

Permalink
format output paths: allow absolute paths (#906)
Browse files Browse the repository at this point in the history
resolves #900
  • Loading branch information
darrinholst authored and charlierudolph committed Aug 23, 2017
1 parent 4238dec commit e306c83
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 10 deletions.
44 changes: 44 additions & 0 deletions features/formatter_paths.feature
Original file line number Diff line number Diff line change
@@ -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)
<duration-stat>
"""

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)
<duration-stat>
"""

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
"""
8 changes: 0 additions & 8 deletions features/multiple_formatters.feature
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,3 @@ Feature: Multiple Formatters
1 step (1 passed)
<duration-stat>
"""

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
"""
2 changes: 2 additions & 0 deletions features/step_definitions/cli_steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
9 changes: 8 additions & 1 deletion features/step_definitions/file_steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2767,6 +2767,10 @@ [email protected]:
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"

[email protected]:
version "0.0.7"
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab"
Expand Down

0 comments on commit e306c83

Please sign in to comment.