Skip to content

Commit ea4d860

Browse files
jshiffletaslakhellesoyaurelien-reevesdavidjgoss
authored
Empty rerun file exits running no scenarios (#1302) (#1568)
Co-authored-by: Aslak Hellesøy <[email protected]> Co-authored-by: Aurélien Reeves <[email protected]> Co-authored-by: David Goss <[email protected]>
1 parent b04d6fe commit ea4d860

File tree

5 files changed

+90
-21
lines changed

5 files changed

+90
-21
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CO
2828

2929
* Progress bar formatter now reports total step count correctly ([#1579](https://github.com/cucumber/cucumber-js/issues/1579)
3030
[#1669](https://github.com/cucumber/cucumber-js/pull/1669))
31+
* Rerun functionality will now run nothing if the rerun file is empty from the previous run ([#1302](https://github.com/cucumber/cucumber-js/issues/1302) [#1568](https://github.com/cucumber/cucumber-js/pull/1568))
3132
* All messages now emitted with project-relative `uri`s
3233
([#1534](https://github.com/cucumber/cucumber-js/issues/1534)
3334
[#1672](https://github.com/cucumber/cucumber-js/pull/1672))

features/rerun_formatter.feature

+3-11
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,11 @@ Feature: Rerun Formatter
9595
When I run cucumber-js with `@rerun.txt`
9696
Then it runs the scenario "C - passing"
9797

98-
Scenario: empty rerun file
98+
Scenario: empty rerun file exits without running any scenarios
9999
Given an empty file named "@rerun.txt"
100100
When I run cucumber-js with `@rerun.txt`
101-
Then it fails
102-
And it runs the scenarios:
103-
| NAME |
104-
| A - passing |
105-
| A - failing |
106-
| A - ambiguous |
107-
| B - passing |
108-
| B - pending |
109-
| C - passing |
110-
| C - undefined |
101+
Then it passes
102+
And it runs 0 scenarios
111103

112104
Scenario: rerun with fail fast outputs all skipped scenarios
113105
When I run cucumber-js with `--fail-fast --format rerun:@rerun.txt`

src/cli/configuration_builder.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,13 @@ export default class ConfigurationBuilder {
210210
if (filename[0] === '@') {
211211
const filePath = path.join(this.cwd, arg)
212212
const content = await fs.readFile(filePath, 'utf8')
213-
return _.chain(content).split('\n').map(_.trim).compact().value()
213+
return _.chain(content).split('\n').map(_.trim).value()
214214
}
215215
return [arg]
216216
})
217217
const featurePaths = _.flatten(nestedFeaturePaths)
218218
if (featurePaths.length > 0) {
219-
return featurePaths
219+
return _.compact(featurePaths)
220220
}
221221
}
222222
return ['features/**/*.{feature,feature.md}']

src/cli/configuration_builder_spec.ts

+72
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,78 @@ describe('Configuration', () => {
164164
})
165165
})
166166

167+
describe('path to an empty rerun file', () => {
168+
it('returns empty featurePaths and support code paths', async function () {
169+
// Arrange
170+
const cwd = await buildTestWorkingDirectory()
171+
172+
const relativeRerunPath = '@empty_rerun.txt'
173+
const rerunPath = path.join(cwd, '@empty_rerun.txt')
174+
await fsExtra.outputFile(rerunPath, '')
175+
const argv = baseArgv.concat([relativeRerunPath])
176+
177+
// Act
178+
const {
179+
featurePaths,
180+
pickleFilterOptions,
181+
supportCodePaths,
182+
} = await ConfigurationBuilder.build({ argv, cwd })
183+
184+
// Assert
185+
expect(featurePaths).to.eql([])
186+
expect(pickleFilterOptions.featurePaths).to.eql([])
187+
expect(supportCodePaths).to.eql([])
188+
})
189+
})
190+
191+
describe('path to an rerun file with new line', () => {
192+
it('returns empty featurePaths and support code paths', async function () {
193+
// Arrange
194+
const cwd = await buildTestWorkingDirectory()
195+
196+
const relativeRerunPath = '@empty_rerun.txt'
197+
const rerunPath = path.join(cwd, '@empty_rerun.txt')
198+
await fsExtra.outputFile(rerunPath, '\n')
199+
const argv = baseArgv.concat([relativeRerunPath])
200+
201+
// Act
202+
const {
203+
featurePaths,
204+
pickleFilterOptions,
205+
supportCodePaths,
206+
} = await ConfigurationBuilder.build({ argv, cwd })
207+
208+
// Assert
209+
expect(featurePaths).to.eql([])
210+
expect(pickleFilterOptions.featurePaths).to.eql([])
211+
expect(supportCodePaths).to.eql([])
212+
})
213+
})
214+
215+
describe('path to a rerun file with one new line character', () => {
216+
it('returns empty featurePaths and support code paths', async function () {
217+
// Arrange
218+
const cwd = await buildTestWorkingDirectory()
219+
220+
const relativeRerunPath = '@empty_rerun.txt'
221+
const rerunPath = path.join(cwd, '@empty_rerun.txt')
222+
await fsExtra.outputFile(rerunPath, '\n\n')
223+
const argv = baseArgv.concat([relativeRerunPath])
224+
225+
// Act
226+
const {
227+
featurePaths,
228+
pickleFilterOptions,
229+
supportCodePaths,
230+
} = await ConfigurationBuilder.build({ argv, cwd })
231+
232+
// Assert
233+
expect(featurePaths).to.eql([])
234+
expect(pickleFilterOptions.featurePaths).to.eql([])
235+
expect(supportCodePaths).to.eql([])
236+
})
237+
})
238+
167239
describe('formatters', () => {
168240
it('adds a default', async function () {
169241
// Arrange

src/cli/index.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,18 @@ export default class Cli {
208208
relativeTo: this.cwd,
209209
}
210210
)
211-
const pickleIds = await parseGherkinMessageStream({
212-
cwd: this.cwd,
213-
eventBroadcaster,
214-
eventDataCollector,
215-
gherkinMessageStream,
216-
order: configuration.order,
217-
pickleFilter: new PickleFilter(configuration.pickleFilterOptions),
218-
})
211+
let pickleIds: string[] = []
212+
213+
if (configuration.featurePaths.length > 0) {
214+
pickleIds = await parseGherkinMessageStream({
215+
cwd: this.cwd,
216+
eventBroadcaster,
217+
eventDataCollector,
218+
gherkinMessageStream,
219+
order: configuration.order,
220+
pickleFilter: new PickleFilter(configuration.pickleFilterOptions),
221+
})
222+
}
219223
emitSupportCodeMessages({
220224
eventBroadcaster,
221225
supportCodeLibrary,

0 commit comments

Comments
 (0)