diff --git a/code/core/src/csf-tools/vitest-plugin/transformer.test.ts b/code/core/src/csf-tools/vitest-plugin/transformer.test.ts index a92af8c4cc2f..a96833accaf4 100644 --- a/code/core/src/csf-tools/vitest-plugin/transformer.test.ts +++ b/code/core/src/csf-tools/vitest-plugin/transformer.test.ts @@ -80,7 +80,7 @@ describe('transformer', () => { }; export default _meta; export const Story = {}; - const _isRunningFromThisFile = import.meta.url.includes(_expect.getState().testPath ?? globalThis.__vitest_worker__.filepath); + const _isRunningFromThisFile = import.meta.url.includes(globalThis.__vitest_worker__.filepath ?? _expect.getState().testPath); if (_isRunningFromThisFile) { _test("Story", _testStory("Story", Story, _meta, [])); } @@ -109,7 +109,7 @@ describe('transformer', () => { }; export default _meta; export const Story = {}; - const _isRunningFromThisFile = import.meta.url.includes(_expect.getState().testPath ?? globalThis.__vitest_worker__.filepath); + const _isRunningFromThisFile = import.meta.url.includes(globalThis.__vitest_worker__.filepath ?? _expect.getState().testPath); if (_isRunningFromThisFile) { _test("Story", _testStory("Story", Story, _meta, [])); } @@ -139,7 +139,7 @@ describe('transformer', () => { }; export default meta; export const Story = {}; - const _isRunningFromThisFile = import.meta.url.includes(_expect.getState().testPath ?? globalThis.__vitest_worker__.filepath); + const _isRunningFromThisFile = import.meta.url.includes(globalThis.__vitest_worker__.filepath ?? _expect.getState().testPath); if (_isRunningFromThisFile) { _test("Story", _testStory("Story", Story, meta, [])); } @@ -170,7 +170,7 @@ describe('transformer', () => { }; export default meta; export const Story = {}; - const _isRunningFromThisFile = import.meta.url.includes(_expect.getState().testPath ?? globalThis.__vitest_worker__.filepath); + const _isRunningFromThisFile = import.meta.url.includes(globalThis.__vitest_worker__.filepath ?? _expect.getState().testPath); if (_isRunningFromThisFile) { _test("Story", _testStory("Story", Story, meta, [])); } @@ -206,7 +206,7 @@ describe('transformer', () => { label: 'Primary Button' } }; - const _isRunningFromThisFile = import.meta.url.includes(_expect.getState().testPath ?? globalThis.__vitest_worker__.filepath); + const _isRunningFromThisFile = import.meta.url.includes(globalThis.__vitest_worker__.filepath ?? _expect.getState().testPath); if (_isRunningFromThisFile) { _test("Primary", _testStory("Primary", Primary, _meta, [])); } @@ -240,7 +240,7 @@ describe('transformer', () => { } }; export { Primary }; - const _isRunningFromThisFile = import.meta.url.includes(_expect.getState().testPath ?? globalThis.__vitest_worker__.filepath); + const _isRunningFromThisFile = import.meta.url.includes(globalThis.__vitest_worker__.filepath ?? _expect.getState().testPath); if (_isRunningFromThisFile) { _test("Primary", _testStory("Primary", Primary, _meta, [])); } @@ -276,7 +276,7 @@ describe('transformer', () => { }; export const Secondary = {}; export { Primary }; - const _isRunningFromThisFile = import.meta.url.includes(_expect.getState().testPath ?? globalThis.__vitest_worker__.filepath); + const _isRunningFromThisFile = import.meta.url.includes(globalThis.__vitest_worker__.filepath ?? _expect.getState().testPath); if (_isRunningFromThisFile) { _test("Secondary", _testStory("Secondary", Secondary, _meta, [])); _test("Primary", _testStory("Primary", Primary, _meta, [])); @@ -308,7 +308,7 @@ describe('transformer', () => { export default _meta; export const Story = {}; export const nonStory = 123; - const _isRunningFromThisFile = import.meta.url.includes(_expect.getState().testPath ?? globalThis.__vitest_worker__.filepath); + const _isRunningFromThisFile = import.meta.url.includes(globalThis.__vitest_worker__.filepath ?? _expect.getState().testPath); if (_isRunningFromThisFile) { _test("Story", _testStory("Story", Story, _meta, [])); } @@ -365,7 +365,7 @@ describe('transformer', () => { tags: ['include-me'] }; export const NotIncluded = {}; - const _isRunningFromThisFile = import.meta.url.includes(_expect.getState().testPath ?? globalThis.__vitest_worker__.filepath); + const _isRunningFromThisFile = import.meta.url.includes(globalThis.__vitest_worker__.filepath ?? _expect.getState().testPath); if (_isRunningFromThisFile) { _test("Included", _testStory("Included", Included, _meta, [])); } @@ -396,7 +396,7 @@ describe('transformer', () => { export const NotIncluded = { tags: ['exclude-me'] }; - const _isRunningFromThisFile = import.meta.url.includes(_expect.getState().testPath ?? globalThis.__vitest_worker__.filepath); + const _isRunningFromThisFile = import.meta.url.includes(globalThis.__vitest_worker__.filepath ?? _expect.getState().testPath); if (_isRunningFromThisFile) { _test("Included", _testStory("Included", Included, _meta, [])); } @@ -424,7 +424,7 @@ describe('transformer', () => { export const Skipped = { tags: ['skip-me'] }; - const _isRunningFromThisFile = import.meta.url.includes(_expect.getState().testPath ?? globalThis.__vitest_worker__.filepath); + const _isRunningFromThisFile = import.meta.url.includes(globalThis.__vitest_worker__.filepath ?? _expect.getState().testPath); if (_isRunningFromThisFile) { _test("Skipped", _testStory("Skipped", Skipped, _meta, ["skip-me"])); } @@ -456,7 +456,7 @@ describe('transformer', () => { }; export default meta; export const Primary = {}; - const _isRunningFromThisFile = import.meta.url.includes(_expect.getState().testPath ?? globalThis.__vitest_worker__.filepath); + const _isRunningFromThisFile = import.meta.url.includes(globalThis.__vitest_worker__.filepath ?? _expect.getState().testPath); if (_isRunningFromThisFile) { _test("Primary", _testStory("Primary", Primary, meta, [])); } diff --git a/code/core/src/csf-tools/vitest-plugin/transformer.ts b/code/core/src/csf-tools/vitest-plugin/transformer.ts index b4020ee4efcb..b2c66693b228 100644 --- a/code/core/src/csf-tools/vitest-plugin/transformer.ts +++ b/code/core/src/csf-tools/vitest-plugin/transformer.ts @@ -172,8 +172,10 @@ export async function vitestTransform({ // Combine testPath and filepath using the ?? operator const nullishCoalescingExpression = t.logicalExpression( '??', - testPathProperty, - filePathProperty + // TODO: switch order of testPathProperty and filePathProperty when the bug is fixed + // https://github.com/vitest-dev/vitest/issues/6367 (or probably just use testPathProperty) + filePathProperty, + testPathProperty ); // Create the final expression: import.meta.url.includes(...)