Skip to content

Commit c0f25c1

Browse files
authored
Merge pull request #28993 from storybookjs/yann/fix-isolate-false-issue
Addon Vitest: Fix tests potentially not existing in non-isolate mode
2 parents e870b9d + 7d7acc4 commit c0f25c1

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

code/core/src/csf-tools/vitest-plugin/transformer.test.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe('transformer', () => {
8080
};
8181
export default _meta;
8282
export const Story = {};
83-
const _isRunningFromThisFile = import.meta.url.includes(_expect.getState().testPath ?? globalThis.__vitest_worker__.filepath);
83+
const _isRunningFromThisFile = import.meta.url.includes(globalThis.__vitest_worker__.filepath ?? _expect.getState().testPath);
8484
if (_isRunningFromThisFile) {
8585
_test("Story", _testStory("Story", Story, _meta, []));
8686
}
@@ -109,7 +109,7 @@ describe('transformer', () => {
109109
};
110110
export default _meta;
111111
export const Story = {};
112-
const _isRunningFromThisFile = import.meta.url.includes(_expect.getState().testPath ?? globalThis.__vitest_worker__.filepath);
112+
const _isRunningFromThisFile = import.meta.url.includes(globalThis.__vitest_worker__.filepath ?? _expect.getState().testPath);
113113
if (_isRunningFromThisFile) {
114114
_test("Story", _testStory("Story", Story, _meta, []));
115115
}
@@ -139,7 +139,7 @@ describe('transformer', () => {
139139
};
140140
export default meta;
141141
export const Story = {};
142-
const _isRunningFromThisFile = import.meta.url.includes(_expect.getState().testPath ?? globalThis.__vitest_worker__.filepath);
142+
const _isRunningFromThisFile = import.meta.url.includes(globalThis.__vitest_worker__.filepath ?? _expect.getState().testPath);
143143
if (_isRunningFromThisFile) {
144144
_test("Story", _testStory("Story", Story, meta, []));
145145
}
@@ -170,7 +170,7 @@ describe('transformer', () => {
170170
};
171171
export default meta;
172172
export const Story = {};
173-
const _isRunningFromThisFile = import.meta.url.includes(_expect.getState().testPath ?? globalThis.__vitest_worker__.filepath);
173+
const _isRunningFromThisFile = import.meta.url.includes(globalThis.__vitest_worker__.filepath ?? _expect.getState().testPath);
174174
if (_isRunningFromThisFile) {
175175
_test("Story", _testStory("Story", Story, meta, []));
176176
}
@@ -206,7 +206,7 @@ describe('transformer', () => {
206206
label: 'Primary Button'
207207
}
208208
};
209-
const _isRunningFromThisFile = import.meta.url.includes(_expect.getState().testPath ?? globalThis.__vitest_worker__.filepath);
209+
const _isRunningFromThisFile = import.meta.url.includes(globalThis.__vitest_worker__.filepath ?? _expect.getState().testPath);
210210
if (_isRunningFromThisFile) {
211211
_test("Primary", _testStory("Primary", Primary, _meta, []));
212212
}
@@ -240,7 +240,7 @@ describe('transformer', () => {
240240
}
241241
};
242242
export { Primary };
243-
const _isRunningFromThisFile = import.meta.url.includes(_expect.getState().testPath ?? globalThis.__vitest_worker__.filepath);
243+
const _isRunningFromThisFile = import.meta.url.includes(globalThis.__vitest_worker__.filepath ?? _expect.getState().testPath);
244244
if (_isRunningFromThisFile) {
245245
_test("Primary", _testStory("Primary", Primary, _meta, []));
246246
}
@@ -276,7 +276,7 @@ describe('transformer', () => {
276276
};
277277
export const Secondary = {};
278278
export { Primary };
279-
const _isRunningFromThisFile = import.meta.url.includes(_expect.getState().testPath ?? globalThis.__vitest_worker__.filepath);
279+
const _isRunningFromThisFile = import.meta.url.includes(globalThis.__vitest_worker__.filepath ?? _expect.getState().testPath);
280280
if (_isRunningFromThisFile) {
281281
_test("Secondary", _testStory("Secondary", Secondary, _meta, []));
282282
_test("Primary", _testStory("Primary", Primary, _meta, []));
@@ -308,7 +308,7 @@ describe('transformer', () => {
308308
export default _meta;
309309
export const Story = {};
310310
export const nonStory = 123;
311-
const _isRunningFromThisFile = import.meta.url.includes(_expect.getState().testPath ?? globalThis.__vitest_worker__.filepath);
311+
const _isRunningFromThisFile = import.meta.url.includes(globalThis.__vitest_worker__.filepath ?? _expect.getState().testPath);
312312
if (_isRunningFromThisFile) {
313313
_test("Story", _testStory("Story", Story, _meta, []));
314314
}
@@ -365,7 +365,7 @@ describe('transformer', () => {
365365
tags: ['include-me']
366366
};
367367
export const NotIncluded = {};
368-
const _isRunningFromThisFile = import.meta.url.includes(_expect.getState().testPath ?? globalThis.__vitest_worker__.filepath);
368+
const _isRunningFromThisFile = import.meta.url.includes(globalThis.__vitest_worker__.filepath ?? _expect.getState().testPath);
369369
if (_isRunningFromThisFile) {
370370
_test("Included", _testStory("Included", Included, _meta, []));
371371
}
@@ -396,7 +396,7 @@ describe('transformer', () => {
396396
export const NotIncluded = {
397397
tags: ['exclude-me']
398398
};
399-
const _isRunningFromThisFile = import.meta.url.includes(_expect.getState().testPath ?? globalThis.__vitest_worker__.filepath);
399+
const _isRunningFromThisFile = import.meta.url.includes(globalThis.__vitest_worker__.filepath ?? _expect.getState().testPath);
400400
if (_isRunningFromThisFile) {
401401
_test("Included", _testStory("Included", Included, _meta, []));
402402
}
@@ -424,7 +424,7 @@ describe('transformer', () => {
424424
export const Skipped = {
425425
tags: ['skip-me']
426426
};
427-
const _isRunningFromThisFile = import.meta.url.includes(_expect.getState().testPath ?? globalThis.__vitest_worker__.filepath);
427+
const _isRunningFromThisFile = import.meta.url.includes(globalThis.__vitest_worker__.filepath ?? _expect.getState().testPath);
428428
if (_isRunningFromThisFile) {
429429
_test("Skipped", _testStory("Skipped", Skipped, _meta, ["skip-me"]));
430430
}
@@ -456,7 +456,7 @@ describe('transformer', () => {
456456
};
457457
export default meta;
458458
export const Primary = {};
459-
const _isRunningFromThisFile = import.meta.url.includes(_expect.getState().testPath ?? globalThis.__vitest_worker__.filepath);
459+
const _isRunningFromThisFile = import.meta.url.includes(globalThis.__vitest_worker__.filepath ?? _expect.getState().testPath);
460460
if (_isRunningFromThisFile) {
461461
_test("Primary", _testStory("Primary", Primary, meta, []));
462462
}

code/core/src/csf-tools/vitest-plugin/transformer.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,10 @@ export async function vitestTransform({
172172
// Combine testPath and filepath using the ?? operator
173173
const nullishCoalescingExpression = t.logicalExpression(
174174
'??',
175-
testPathProperty,
176-
filePathProperty
175+
// TODO: switch order of testPathProperty and filePathProperty when the bug is fixed
176+
// https://github.com/vitest-dev/vitest/issues/6367 (or probably just use testPathProperty)
177+
filePathProperty,
178+
testPathProperty
177179
);
178180

179181
// Create the final expression: import.meta.url.includes(...)

0 commit comments

Comments
 (0)