Skip to content

Commit 7648744

Browse files
committed
fix(run-multiple): keep test patterns globbable when --config is passed
With --config, run-multiple resolved config.tests and gherkin.features with path.resolve. On Windows this produced backslash paths, which glob treats as escapes, so no feature files were found. An array of patterns made path.resolve throw a TypeError on every platform. Resolve each pattern separately and use forward slashes. Fixes #5358
1 parent 1c2d9f3 commit 7648744

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

‎lib/command/run-multiple.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ export default async function (selectedRuns, options) {
7575
if (options.config) {
7676
// update paths to config path
7777
if (config.tests) {
78-
config.tests = path.resolve(testRoot, config.tests)
78+
config.tests = resolvePatterns(testRoot, config.tests)
7979
}
8080
if (config.gherkin && config.gherkin.features) {
81-
config.gherkin.features = path.resolve(testRoot, config.gherkin.features)
81+
config.gherkin.features = resolvePatterns(testRoot, config.gherkin.features)
8282
}
8383
}
8484

@@ -117,6 +117,11 @@ export default async function (selectedRuns, options) {
117117
})
118118
}
119119

120+
export function resolvePatterns(testRoot, patterns) {
121+
const resolve = pattern => path.resolve(testRoot, pattern).split(path.sep).join(path.posix.sep)
122+
return Array.isArray(patterns) ? patterns.map(resolve) : resolve(patterns)
123+
}
124+
120125
function executeRun(runName, runConfig) {
121126
// clone config
122127
let overriddenConfig = { ...config }
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { expect } from 'chai'
2+
import path from 'path'
3+
import { fileURLToPath } from 'url'
4+
import { globSync } from 'glob'
5+
import { resolvePatterns } from '../../../lib/command/run-multiple.js'
6+
7+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
8+
const testRoot = path.join(__dirname, '../../data/sandbox')
9+
10+
describe('run-multiple command', () => {
11+
describe('resolvePatterns', () => {
12+
it('should resolve a pattern that glob can match', () => {
13+
const pattern = resolvePatterns(testRoot, './features/*.feature')
14+
expect(path.isAbsolute(pattern)).to.be.true
15+
expect(globSync(pattern)).to.have.lengthOf(globSync('./features/*.feature', { cwd: testRoot }).length).and.not.be.empty
16+
})
17+
18+
it('should resolve each pattern of an array', () => {
19+
const patterns = resolvePatterns(testRoot, ['./features/checkout.feature', './features/async.feature'])
20+
expect(patterns).to.have.lengthOf(2)
21+
patterns.forEach(pattern => expect(globSync(pattern)).to.have.lengthOf(1))
22+
})
23+
})
24+
})

0 commit comments

Comments
 (0)