[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

fix: fix test.scoped inheritance (#7814)

authored by

Hiroshi Ogawa and committed by
GitHub
(Apr 9, 2025, 10:45 AM +0200) db6c3bcc 773b10e0

+43 -4
+7 -4
packages/runner/src/suite.ts
··· 295 295 mode: RunMode, 296 296 each?: boolean, 297 297 suiteOptions?: TestOptions, 298 + parentCollectorFixtures?: FixtureItem[], 298 299 ) { 299 300 const tasks: (Test | Suite | SuiteCollector)[] = [] 300 301 ··· 395 396 test.type = 'test' 396 397 }) 397 398 398 - let collectorFixtures: FixtureItem[] | undefined 399 + let collectorFixtures = parentCollectorFixtures 399 400 400 401 const collector: SuiteCollector = { 401 402 type: 'collector', ··· 555 556 mode, 556 557 this.each, 557 558 options, 559 + currentSuite?.fixtures(), 558 560 ) 559 561 } 560 562 ··· 768 770 ) { 769 771 const collector = getCurrentSuite() 770 772 const scopedFixtures = collector.fixtures() 773 + const context = { ...this } 771 774 if (scopedFixtures) { 772 - this.fixtures = mergeScopedFixtures( 773 - this.fixtures || [], 775 + context.fixtures = mergeScopedFixtures( 776 + context.fixtures || [], 774 777 scopedFixtures, 775 778 ) 776 779 } 777 780 collector.test.fn.call( 778 - this, 781 + context, 779 782 formatName(name), 780 783 optionsOrFn as TestOptions, 781 784 optionsOrTest as TestFunction,
+36
test/core/test/test-extend.test.ts
··· 451 451 }) 452 452 }) 453 453 }) 454 + 455 + describe('test.scoped repro #7793', () => { 456 + const extendedTest = test.extend<{ foo: boolean }>({ 457 + foo: false, 458 + }) 459 + 460 + describe('top level', () => { 461 + extendedTest.scoped({ foo: true }) 462 + 463 + describe('second level', () => { 464 + extendedTest('foo is true', ({ foo }) => { 465 + expect(foo).toBe(true) 466 + }) 467 + }) 468 + }) 469 + }) 470 + 471 + describe('test.scoped repro #7813', () => { 472 + const extendedTest = test.extend<{ foo?: boolean }>({ 473 + foo: false, 474 + }) 475 + 476 + describe('foo is scoped to true', () => { 477 + extendedTest.scoped({ foo: true }) 478 + 479 + extendedTest('foo is true', ({ foo }) => { 480 + expect(foo).toBe(true) 481 + }) 482 + }) 483 + 484 + describe('foo is left as default of false', () => { 485 + extendedTest('foo is false', ({ foo }) => { 486 + expect(foo).toBe(false) 487 + }) 488 + }) 489 + })