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

Build: Migrate unit tests from Jest to Vitest #24415

Merged
merged 116 commits into from Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
8c7f376
add vitest to the monorepo - WIP
ndelangen Sep 14, 2023
be2bf24
remove storyshots some more and delete jest configs
ndelangen Sep 14, 2023
b911c4d
migrate first 2 stories by hand
ndelangen Sep 14, 2023
ed23b2e
run tests only once
ndelangen Sep 14, 2023
aacc4ac
migrate some things by hand
ndelangen Sep 14, 2023
93db551
more manual migrations
ndelangen Sep 14, 2023
fd0386f
making progress on migrating to vitest
ndelangen Sep 14, 2023
1dfe687
migrate all jest references to vitest
yannbf Sep 14, 2023
799b7c7
update snapshots
yannbf Sep 14, 2023
d91a91e
more fixes
yannbf Sep 14, 2023
604a442
progress on fixes
ndelangen Sep 14, 2023
4eace09
Merge branch 'norbert/vitest-for-monorepo' of github.com:storybookjs/…
ndelangen Sep 14, 2023
c9f36de
fixing tests in scripts
ndelangen Sep 14, 2023
90d5409
remove jest-specific-snapshot and update snapshots
yannbf Sep 14, 2023
d1966b1
fix imports
yannbf Sep 14, 2023
cb9ffb1
more test fixes
yannbf Sep 15, 2023
c43385b
fix more tests
yannbf Sep 15, 2023
6c272c9
more fixes
yannbf Sep 15, 2023
6250ef3
fix codemods test
ndelangen Sep 15, 2023
ab77c3e
improve test
ndelangen Sep 15, 2023
2ae51af
fix a test
ndelangen Sep 15, 2023
70beaf7
remove jest-os-detection
yannbf Sep 18, 2023
5d73a0a
Merge branch 'next' into norbert/vitest-for-monorepo
yannbf Oct 9, 2023
9a2f8f6
upgrade to vitest 1.0.0-beta.4 and fix many more tests
yannbf Oct 9, 2023
b76d42c
Merge branch 'next' into norbert/vitest-for-monorepo
yannbf Oct 9, 2023
75e7d00
Add/configure jest-dom
IanVS Oct 10, 2023
db243e1
Cleanup after rendering
IanVS Oct 10, 2023
ccff556
Only use vite 4
IanVS Oct 10, 2023
5fe8e5b
Get renderers/vue tests passing
IanVS Oct 10, 2023
2ca45f5
Get renderers/vue3 tests passing
IanVS Oct 10, 2023
ca0394d
Get renderers/svelte tests passing
IanVS Oct 10, 2023
00b0f0e
Fix cli helpers test
IanVS Oct 10, 2023
238f254
Recreate throwMessage helpers from jest into vitest setup
IanVS Oct 10, 2023
5652c32
Fix type error
IanVS Oct 10, 2023
8abefdb
Avoid empty mockImplementation
IanVS Oct 10, 2023
af7e7e4
A bit cleaner way to deal with fsExtra.__setMockFiles
IanVS Oct 10, 2023
a53cf8d
Avoid console warning error
IanVS Oct 10, 2023
7634e80
Fix lib/codemod test
IanVS Oct 10, 2023
397cafe
Use `import()` for presets instead of `interopRequireDefault`
IanVS Oct 10, 2023
f70813d
Get lib/core-common tests passing
IanVS Oct 10, 2023
fd15923
Get lib/theming tests passing
IanVS Oct 10, 2023
d2f4af1
Update snapshot format
IanVS Oct 11, 2023
6d35099
Avoid infinite loop in find-up
IanVS Oct 11, 2023
375fe3d
Be consistent about named vs default imports
IanVS Oct 11, 2023
2373a09
Use default actual import from debounce
IanVS Oct 11, 2023
29d3e7c
Use vi.waitFor() instead of timing hacks
IanVS Oct 11, 2023
ae00f52
[HACK] add import condition for @storybook/preview/globals
IanVS Oct 11, 2023
3c2479f
Use arg of mock factory to clean up types
IanVS Oct 11, 2023
4ddebe8
Use vi.mocked() instead of casting to Mock
IanVS Oct 11, 2023
1da8527
Remove some unused code
IanVS Oct 11, 2023
3f5e0f3
fix StoryIndexGenerator.test
JReinhold Oct 11, 2023
aab2798
fix StoryIndexGenerator.deprecated.test
JReinhold Oct 11, 2023
1e8adfd
add ignore
ndelangen Nov 4, 2023
99ad313
Merge branch 'release-8-0' into norbert/vitest-for-monorepo
ndelangen Nov 4, 2023
360d02d
ts fixes
ndelangen Nov 4, 2023
bfe4397
upgrade @testing-library/jest-dom
ndelangen Nov 4, 2023
458227a
update snapshots && fixes
ndelangen Nov 4, 2023
4572eeb
fixes
ndelangen Nov 4, 2023
e65f677
upgrade vitest to beta.3 & fixes
ndelangen Nov 7, 2023
1c9050a
fix linting
ndelangen Nov 8, 2023
44944d4
fix check
ndelangen Nov 8, 2023
a5d5e8e
fix check of scripts
ndelangen Nov 8, 2023
e3de0b5
remove invalid flags
ndelangen Nov 8, 2023
3a2986e
remove --ci flags
ndelangen Nov 8, 2023
6f53f7a
add @vitest/coverage-v8 - npm
ndelangen Nov 8, 2023
9adfc24
add package
ndelangen Nov 9, 2023
0452176
remove --runInBand test flag
JReinhold Nov 9, 2023
b64d62b
set vi globals to silent emotion warnings
JReinhold Nov 9, 2023
8e533c2
Merge remote-tracking branch 'origin/next' into norbert/vitest-for-mo…
IanVS Nov 20, 2023
3710197
Update snapshot
IanVS Nov 20, 2023
39f3e42
Update globals
IanVS Nov 20, 2023
ee0953d
fix more tests
yannbf Nov 24, 2023
360ba46
Merge remote-tracking branch 'origin/next' into norbert/vitest-for-mo…
IanVS Dec 5, 2023
3e2f4be
Skip tests that are failing due to emotion theme
IanVS Dec 5, 2023
7ddbde1
Convert new tests from jest to vitest
IanVS Dec 5, 2023
513a02f
Fix eslint test
IanVS Dec 5, 2023
dcabfe6
Update exports
IanVS Dec 5, 2023
5a6b178
Fix lockfile
IanVS Dec 5, 2023
6ce478c
Fix lint errors
IanVS Dec 5, 2023
0845820
Update vitest to 1.0.1
IanVS Dec 5, 2023
56c0710
Fix scripts tests
IanVS Dec 5, 2023
f368ac4
Update snapshots
IanVS Dec 5, 2023
20ccf0b
Unpin vite
IanVS Dec 5, 2023
3fbe517
Fix type errors
IanVS Dec 5, 2023
7df71d3
Merge branch 'next' into norbert/vitest-for-monorepo
IanVS Dec 5, 2023
ee78f8e
Merge branch 'next' of github.com:storybookjs/storybook into norbert/…
JReinhold Dec 6, 2023
6dfcad5
re-add interopRequireDefault, use mock-require in unit tests
JReinhold Dec 6, 2023
7d671ee
revert wrong export statements
JReinhold Dec 6, 2023
239a67d
increase test timeouts, add @types/mock-require
JReinhold Dec 6, 2023
e95b906
increase timeout
JReinhold Dec 6, 2023
019a19f
Fix changelog test
kasperpeulen Dec 7, 2023
5b383c0
Merge branch 'next' into norbert/vitest-for-monorepo
ndelangen Dec 11, 2023
c16c125
Merge branch 'next' into norbert/vitest-for-monorepo
valentinpalkovic Dec 12, 2023
205a339
Fix Angular tests
valentinpalkovic Dec 12, 2023
eed6f38
Fix eslint
valentinpalkovic Dec 12, 2023
2eaeb1f
Fix Svelte tests
valentinpalkovic Dec 12, 2023
ac864a8
Fix test for Windows
valentinpalkovic Dec 14, 2023
4f1931d
fix types in compodoc tests
yannbf Dec 18, 2023
27047ab
remove unnecessary directories
yannbf Dec 18, 2023
8acf97a
remove jest leftovers
yannbf Dec 18, 2023
5a20d19
temporarily debug windows test
yannbf Dec 18, 2023
3d61dc5
undo function calls
yannbf Dec 18, 2023
51ead4f
temporarily skip type checks on public-types.test.ts
yannbf Dec 18, 2023
93339af
Merge branch 'next' into norbert/vitest-for-monorepo
yannbf Dec 19, 2023
795fb55
fix helper tests on windows
yannbf Dec 19, 2023
7844a6e
migrate tests from jest to vitest
yannbf Dec 19, 2023
f62613c
remove unnecessary ts ignore comment
yannbf Dec 19, 2023
10c614e
increase test timeout
yannbf Dec 19, 2023
6b61f37
temporarily skip some ci checks
yannbf Dec 19, 2023
4a32582
undo debugging checks
yannbf Dec 19, 2023
62df129
update misc code
yannbf Dec 19, 2023
62348c0
undo svelte component changes
yannbf Dec 19, 2023
f07f64e
fix types in normalize-stories
yannbf Dec 19, 2023
469f49c
final cleanup
yannbf Dec 19, 2023
9508756
update contribution guide
yannbf Dec 19, 2023
2b1258a
fix typo
yannbf Dec 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 22 additions & 21 deletions code/lib/core-common/src/utils/__tests__/normalize-stories.test.ts
@@ -1,7 +1,5 @@
/// <reference types="@testing-library/jest-dom" />;

import { describe, it, expect, vi } from 'vitest';

import { dedent } from 'ts-dedent';
import { sep } from 'path';

Expand All @@ -18,7 +16,7 @@ expect.addSnapshotSerializer({
});

expect.extend({
toEqual(regex: RegExp, paths: string[]) {
toMatchPaths(regex: RegExp, paths: string[]) {
const matched = paths.map((p) => !!p.match(regex));

const pass = matched.every(Boolean);
Expand Down Expand Up @@ -71,8 +69,8 @@ describe('normalizeStoriesEntry', () => {
}
`);

expect(specifier.importPathMatcher).toEqual(['./path/to/file.stories.mdx']);
expect(specifier.importPathMatcher).not.toEqual([
expect(specifier.importPathMatcher).toMatchPaths(['./path/to/file.stories.mdx']);
expect(specifier.importPathMatcher).not.toMatchPaths([
'./path/to/file.stories.js',
'./file.stories.mdx',
'../file.stories.mdx',
Expand All @@ -90,8 +88,8 @@ describe('normalizeStoriesEntry', () => {
}
`);

expect(specifier.importPathMatcher).toEqual(['./.storybook/file.stories.mdx']);
expect(specifier.importPathMatcher).not.toEqual([
expect(specifier.importPathMatcher).toMatchPaths(['./.storybook/file.stories.mdx']);
expect(specifier.importPathMatcher).not.toMatchPaths([
'.storybook/file.stories.mdx',
'./file.stories.mdx',
'../file.stories.mdx',
Expand All @@ -109,11 +107,11 @@ describe('normalizeStoriesEntry', () => {
}
`);

expect(specifier.importPathMatcher).toEqual([
expect(specifier.importPathMatcher).toMatchPaths([
'./path/file.stories.mdx',
'./second-path/file.stories.mdx',
]);
expect(specifier.importPathMatcher).not.toEqual([
expect(specifier.importPathMatcher).not.toMatchPaths([
'./path/file.stories.js',
'./path/to/file.stories.mdx',
'./file.stories.mdx',
Expand All @@ -132,11 +130,11 @@ describe('normalizeStoriesEntry', () => {
}
`);

expect(specifier.importPathMatcher).toEqual([
expect(specifier.importPathMatcher).toMatchPaths([
'./path/to/file.stories.mdx',
'./second-path/to/file.stories.mdx',
]);
expect(specifier.importPathMatcher).not.toEqual([
expect(specifier.importPathMatcher).not.toMatchPaths([
'./file.stories.mdx',
'./path/file.stories.mdx',
'./path/to/third/file.stories.mdx',
Expand All @@ -155,13 +153,16 @@ describe('normalizeStoriesEntry', () => {
"importPathMatcher": {}
}
`);
expect(specifier.importPathMatcher).toEqual([
expect(specifier.importPathMatcher).toMatchPaths([
'./file.stories.mdx',
'./path/file.stories.mdx',
'./path/to/file.stories.mdx',
'./path/to/third/file.stories.mdx',
]);
expect(specifier.importPathMatcher).not.toEqual(['./file.stories.js', '../file.stories.mdx']);
expect(specifier.importPathMatcher).not.toMatchPaths([
'./file.stories.js',
'../file.stories.mdx',
]);
});

it('double stars glob', () => {
Expand All @@ -175,12 +176,12 @@ describe('normalizeStoriesEntry', () => {
}
`);

expect(specifier.importPathMatcher).toEqual([
expect(specifier.importPathMatcher).toMatchPaths([
'./foo/file.stories.mdx',
'./path/to/foo/file.stories.mdx',
'./path/to/foo/third/fourth/file.stories.mdx',
]);
expect(specifier.importPathMatcher).not.toEqual([
expect(specifier.importPathMatcher).not.toMatchPaths([
'./file.stories.mdx',
'./file.stories.js',
'../file.stories.mdx',
Expand All @@ -198,11 +199,11 @@ describe('normalizeStoriesEntry', () => {
}
`);

expect(specifier.importPathMatcher).toEqual([
expect(specifier.importPathMatcher).toMatchPaths([
'./path/to/foo/file.stories.mdx',
'./foo/file.stories.mdx',
]);
expect(specifier.importPathMatcher).not.toEqual([
expect(specifier.importPathMatcher).not.toMatchPaths([
'./file.stories.mdx',
'./file.stories.js',
'./path/to/foo/third/fourth/file.stories.mdx',
Expand All @@ -221,8 +222,8 @@ describe('normalizeStoriesEntry', () => {
}
`);

expect(specifier.importPathMatcher).toEqual(['../src/file.stories.mdx']);
expect(specifier.importPathMatcher).not.toEqual([
expect(specifier.importPathMatcher).toMatchPaths(['../src/file.stories.mdx']);
expect(specifier.importPathMatcher).not.toMatchPaths([
'./src/file.stories.mdx',
'../src/file.stories.js',
]);
Expand Down Expand Up @@ -302,11 +303,11 @@ describe('normalizeStoriesEntry', () => {
}
`);

expect(specifier.importPathMatcher).toEqual([
expect(specifier.importPathMatcher).toMatchPaths([
'./path/file.stories.mdx',
'./second-path/file.stories.mdx',
]);
expect(specifier.importPathMatcher).not.toEqual([
expect(specifier.importPathMatcher).not.toMatchPaths([
'./path/file.stories.js',
'./path/to/file.stories.mdx',
'./file.stories.mdx',
Expand Down
2 changes: 1 addition & 1 deletion code/lib/core-common/tsconfig.json
Expand Up @@ -3,5 +3,5 @@
"compilerOptions": {
"strict": true
},
"include": ["src/**/*"]
"include": ["src/**/*", "*.d.ts"]
}
11 changes: 11 additions & 0 deletions code/lib/core-common/vitest.d.ts
@@ -0,0 +1,11 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
import 'vitest';

interface CustomMatchers<R = unknown> {
toMatchPaths(paths: string[]): R;
yannbf marked this conversation as resolved.
Show resolved Hide resolved
}

declare module 'vitest' {
interface Assertion<T = unknown> extends CustomMatchers<T> {}
interface AsymmetricMatchersContaining extends CustomMatchers {}
}