Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addon Vitest: Fix tests potentially not existing in non-isolate mode #28993

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions code/core/src/csf-tools/vitest-plugin/transformer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, []));
}
Expand Down Expand Up @@ -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, []));
}
Expand Down Expand Up @@ -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, []));
}
Expand Down Expand Up @@ -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, []));
}
Expand Down Expand Up @@ -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, []));
}
Expand Down Expand Up @@ -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, []));
}
Expand Down Expand Up @@ -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, []));
Expand Down Expand Up @@ -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, []));
}
Expand Down Expand Up @@ -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, []));
}
Expand Down Expand Up @@ -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, []));
}
Expand Down Expand Up @@ -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"]));
}
Expand Down Expand Up @@ -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, []));
}
Expand Down
4 changes: 3 additions & 1 deletion code/core/src/csf-tools/vitest-plugin/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,10 @@ export async function vitestTransform({
// Combine testPath and filepath using the ?? operator
const nullishCoalescingExpression = t.logicalExpression(
'??',
// 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,
filePathProperty
);

// Create the final expression: import.meta.url.includes(...)
Expand Down
Loading