Skip to content

Commit 457db29

Browse files
hi-ogawacodex
andauthored
fix: test tags options should overwrite inherited suite options + inherit suite options in task API (#10216)
Co-authored-by: Codex <noreply@openai.com>
1 parent 3112abe commit 457db29

3 files changed

Lines changed: 88 additions & 8 deletions

File tree

packages/runner/src/suite.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,9 @@ function createSuiteCollector(
340340
}, {} as TestOptions)
341341

342342
const testOwnMeta = options.meta
343+
const parentOptions = collectorContext.currentSuite?.options
343344
options = {
345+
...parentOptions,
344346
...tagsOptions,
345347
...options,
346348
}
@@ -440,12 +442,7 @@ function createSuiteCollector(
440442
optionsOrFn?: TestOptions | TestFunction,
441443
timeoutOrTest?: number | TestFunction,
442444
) {
443-
let { options, handler } = parseArguments(optionsOrFn, timeoutOrTest)
444-
445-
// inherit repeats, retry, timeout from suite
446-
if (typeof suiteOptions === 'object') {
447-
options = Object.assign({}, suiteOptions, options)
448-
}
445+
const { options, handler } = parseArguments(optionsOrFn, timeoutOrTest)
449446

450447
const concurrent = this.concurrent ?? options?.concurrent
451448
if (concurrent != null) {

test/e2e/test/test-tags.test.ts

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,15 +654,13 @@ test('concurrent false tag option opts out of sequence.concurrent', async () =>
654654
{
655655
"basic.test.js": {
656656
"test 1": {
657-
"concurrent": true,
658657
"mode": "run",
659658
"tags": [
660659
"non-concurrent-tag",
661660
],
662661
"timeout": 5000,
663662
},
664663
"test 2": {
665-
"concurrent": true,
666664
"mode": "run",
667665
"tags": [
668666
"non-concurrent-tag",
@@ -1757,6 +1755,61 @@ test('multiple tags with meta are merged with priority order', async () => {
17571755
`)
17581756
})
17591757

1758+
test('tag options override inherited suite options', async () => {
1759+
const { stderr, buildTree } = await runInlineTests({
1760+
'basic.test.js': `
1761+
describe('with suite options', { timeout: 1000, repeats: 1, concurrent: true }, () => {
1762+
test('tag wins', { tags: ['my-tag'] }, () => {})
1763+
test('explicit test wins', { tags: ['my-tag'], timeout: 9999 }, () => {})
1764+
})
1765+
describe('without suite options', () => {
1766+
test('tag applies', { tags: ['my-tag'] }, () => {})
1767+
})
1768+
`,
1769+
'vitest.config.js': {
1770+
test: {
1771+
globals: true,
1772+
tags: [{ name: 'my-tag', timeout: 5000, repeats: 2, concurrent: false }],
1773+
},
1774+
},
1775+
})
1776+
expect(stderr).toBe('')
1777+
expect(buildOptionsTree(buildTree)).toMatchInlineSnapshot(`
1778+
{
1779+
"basic.test.js": {
1780+
"with suite options": {
1781+
"explicit test wins": {
1782+
"mode": "run",
1783+
"repeats": 2,
1784+
"tags": [
1785+
"my-tag",
1786+
],
1787+
"timeout": 9999,
1788+
},
1789+
"tag wins": {
1790+
"mode": "run",
1791+
"repeats": 2,
1792+
"tags": [
1793+
"my-tag",
1794+
],
1795+
"timeout": 5000,
1796+
},
1797+
},
1798+
"without suite options": {
1799+
"tag applies": {
1800+
"mode": "run",
1801+
"repeats": 2,
1802+
"tags": [
1803+
"my-tag",
1804+
],
1805+
"timeout": 5000,
1806+
},
1807+
},
1808+
},
1809+
}
1810+
`)
1811+
})
1812+
17601813
function getTestTree(builder: (fn: (test: TestCase) => any) => any) {
17611814
return builder(test => test.options.tags)
17621815
}

test/unit/test/task-collector.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,36 @@ describe('collector.extend should preserve handler wrapping', () => {
5050
})
5151
})
5252

53+
describe('suite.task inherits suite options', { meta: { yay: true } as any, concurrent: true, repeats: 1, retry: 2, timeout: 1234 }, () => {
54+
const customTest = TestRunner.createTaskCollector(function (
55+
this: object,
56+
name: string,
57+
fn: () => void,
58+
) {
59+
TestRunner.getCurrentSuite().task(name, { ...this, handler: fn })
60+
})
61+
62+
customTest('inherits options from current suite', ({ task }) => {
63+
expect({
64+
concurrent: task.concurrent,
65+
meta: task.meta,
66+
repeats: task.repeats,
67+
retry: task.retry,
68+
timeout: task.timeout,
69+
}).toMatchInlineSnapshot(`
70+
{
71+
"concurrent": true,
72+
"meta": {
73+
"yay": true,
74+
},
75+
"repeats": 1,
76+
"retry": 2,
77+
"timeout": 1234,
78+
}
79+
`)
80+
})
81+
})
82+
5383
describe('empty tests and suites are todos', () => {
5484
describe('suite should be todo')
5585
test('test should be todo')

0 commit comments

Comments
 (0)