Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 0 additions & 12 deletions code/addons/vitest/src/vitest-plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,18 +403,6 @@ export const storybookTest = async (options?: UserOptions): Promise<Plugin[]> =>
join(relative(finalOptions.vitestRoot, process.cwd()), '**/*.mdx').replaceAll(sep, '/'),
],

// if the existing deps.inline is true, we keep it as-is, because it will inline everything
// TODO: Remove the check once we don't support Vitest 3 anymore
...(nonMutableInputConfig.test?.server?.deps?.inline !== true
? {
server: {
deps: {
inline: ['@storybook/addon-vitest'],
},
},
}
: {}),

browser: {
// if there is a test.browser config AND test.browser.screenshotFailures is not explicitly set, we set it to false
...(nonMutableInputConfig.test?.browser &&
Expand Down
5 changes: 2 additions & 3 deletions code/core/src/actions/loaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ const logActionsWhenMockCalled: LoaderFunction = (context) => {
onMockCall((mock, args) => {
const name = mock.getMockName();

// Default name provided by vi.fn(), which we don't want to log.
// TODO: Can be removed as soon as we drop Vitest 3 support
// https://main.vitest.dev/guide/migration.html#changes-to-mocking
// Default name provided by vi.fn() under storybook/test's pinned @vitest/spy@3.2.4,
// which we don't want to log. Vitest 4's own spy defaults to 'vi.fn()' instead.
if (name === 'spy') {
return;
}
Expand Down
1 change: 0 additions & 1 deletion code/core/src/babel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export {
getEffectiveMergeConfigCall,
getTargetConfigObject,
canUpdateVitestConfigFile,
canUpdateVitestWorkspaceFile,
} from './vitest-config-helpers.ts';

// @ts-expect-error (needed due to it's use of `exports.default`)
Expand Down
66 changes: 1 addition & 65 deletions code/core/src/babel/vitest-config-helpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { describe, expect, it } from 'vitest';

import {
canUpdateVitestConfigFile,
canUpdateVitestWorkspaceFile,
} from './vitest-config-helpers.ts';
import { canUpdateVitestConfigFile } from './vitest-config-helpers.ts';

describe('canUpdateVitestConfigFile', () => {
it('returns true for plain export default object literal', () => {
Expand Down Expand Up @@ -293,64 +290,3 @@ describe('canUpdateVitestConfigFile', () => {
);
});
});

// ─── canUpdateVitestWorkspaceFile ────────────────────────────────────────────

describe('canUpdateVitestWorkspaceFile', () => {
// ----- Supported patterns (should return true) -----

it('returns true for plain array workspace', () => {
expect(canUpdateVitestWorkspaceFile('export default ["project1", "project2"]')).toBe(true);
});

it('returns true for array with object entries', () => {
expect(canUpdateVitestWorkspaceFile('export default [{ test: {} }, "project"]')).toBe(true);
});

it('returns true for empty array', () => {
expect(canUpdateVitestWorkspaceFile('export default []')).toBe(true);
});

it('returns true for defineWorkspace([...]) pattern', () => {
expect(
canUpdateVitestWorkspaceFile(
`
import { defineWorkspace } from 'vitest/config';
export default defineWorkspace(['project1', 'project2'])
`
)
).toBe(true);
});

it('returns true for defineWorkspace with object entries', () => {
expect(
canUpdateVitestWorkspaceFile(
`
import { defineWorkspace } from 'vitest/config';
export default defineWorkspace([{ test: { name: 'unit' } }])
`
)
).toBe(true);
});

// ----- Unsupported patterns (should return false) -----

it('returns false when there is no export default', () => {
expect(canUpdateVitestWorkspaceFile('const projects = ["a"];')).toBe(false);
});

it('returns false for defineWorkspace with a non-array argument', () => {
expect(
canUpdateVitestWorkspaceFile(
`
import { defineWorkspace } from 'vitest/config';
export default defineWorkspace('glob/**')
`
)
).toBe(false);
});

it('returns false for syntax errors', () => {
expect(canUpdateVitestWorkspaceFile('this is not valid syntax !!!')).toBe(false);
});
});
48 changes: 0 additions & 48 deletions code/core/src/babel/vitest-config-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,51 +206,3 @@ export const canUpdateVitestConfigFile = (fileContent: string): boolean => {
getEffectiveMergeConfigCall(exportDefault.declaration, parsedAst) !== null
);
};

/**
* Returns `true` when a Vitest workspace file's default export uses a pattern that
* `updateWorkspaceFile` (from addon-vitest) can auto-update.
*
* Supported patterns:
*
* - `export default ["project1", "project2"]`
* - `export default [{...}, "project"]`
* - `export default defineWorkspace(["project1", "project2"])`
*
* Returns `false` for any other shape (e.g. JSON files should be rejected before parsing, CommonJS
* files, unrecognizable exports).
*/
export const canUpdateVitestWorkspaceFile = (fileContent: string): boolean => {
let parsedAst: AST;
try {
parsedAst = babelParse(fileContent);
} catch {
return false;
}

const exportDefault = parsedAst.program.body.find(
(n): n is t.ExportDefaultDeclaration => n.type === 'ExportDefaultDeclaration'
);
if (!exportDefault) {
return false;
}

const decl = exportDefault.declaration;

// export default [...]
if (decl.type === 'ArrayExpression') {
return true;
}

// export default defineWorkspace([...])
if (
decl.type === 'CallExpression' &&
decl.callee.type === 'Identifier' &&
decl.callee.name === 'defineWorkspace' &&
decl.arguments[0]?.type === 'ArrayExpression'
) {
return true;
}

return false;
};
Loading
Loading