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: Upgrade Jest to version 28 #19613

Merged
merged 47 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
9255a00
Start upgrading to Jest 28
Marklb Oct 25, 2022
22bcdd0
Fix some of the Angular tests
Marklb Oct 25, 2022
2c509cb
More Angular test fixes and others
Marklb Nov 1, 2022
217d461
Merge remote-tracking branch 'origin/next' into marklb/upgrade-to-jest28
IanVS Nov 10, 2022
0d29947
Create separate jest configs for browser and node
IanVS Nov 10, 2022
dfb9384
Create separate jest projects in /lib
IanVS Nov 10, 2022
8e05115
Update a few jest package stragglers
IanVS Nov 10, 2022
3035827
Get /lib tests passing
IanVS Nov 10, 2022
13f50c3
Fix some typescript errors
IanVS Nov 10, 2022
28bac34
Add frameworks
IanVS Nov 10, 2022
3594219
Ignore angular project for now
IanVS Nov 10, 2022
b5f1860
Add projects to avoid warnings
IanVS Nov 10, 2022
d296ad8
Add tests for renderers
IanVS Nov 10, 2022
d5f5648
Add tests for addons
IanVS Nov 10, 2022
96c7dce
Move enzyme serializer to storyshots config
IanVS Nov 10, 2022
89b0891
Ignore angular in config, not cli
IanVS Nov 10, 2022
80c699f
[fixme] check in new snapshot
IanVS Nov 10, 2022
91e920c
Merge remote-tracking branch 'origin/next' into marklb/upgrade-to-jest28
IanVS Nov 13, 2022
e6eac86
Fix export map for jest-transform-mdx
IanVS Nov 13, 2022
7fc44d0
Ensure that storyshot files are absolute
IanVS Nov 13, 2022
4820cf9
Remove unnecessary/unused ts-jest
IanVS Nov 13, 2022
7292434
Replace @types/jest with @jest/globals
IanVS Nov 13, 2022
2746c37
Remove unused jest-jasmine2
IanVS Nov 13, 2022
bb49da3
Remove unused jest-enzyme
IanVS Nov 13, 2022
6e2d4b6
Remove unused jest-raw-loader
IanVS Nov 13, 2022
3d3c23e
Merge remote-tracking branch 'origin/next' into marklb/upgrade-to-jest28
IanVS Nov 13, 2022
e1d0790
Merge remote-tracking branch 'origin/next' into marklb/upgrade-to-jest28
IanVS Nov 14, 2022
067c7b8
Incorporate feedback from Norbert
IanVS Nov 14, 2022
3bf7d8b
Fix corrupt yarn.lock
IanVS Nov 14, 2022
25f7141
name jest projects using file path
IanVS Nov 14, 2022
a30f4d4
Add UI unit tests
IanVS Nov 14, 2022
299eabe
Remove unneeded ts-expect-error
IanVS Nov 14, 2022
2370e56
Clean up typescript some more
IanVS Nov 14, 2022
c9dc70b
re-ignore failing windows tests
IanVS Nov 15, 2022
8a97d67
Merge remote-tracking branch 'origin/next' into marklb/upgrade-to-jest28
IanVS Nov 15, 2022
8efda95
Merge remote-tracking branch 'origin/next' into marklb/upgrade-to-jest28
IanVS Nov 15, 2022
894b2ca
Merge remote-tracking branch 'origin/next' into marklb/upgrade-to-jest28
IanVS Nov 15, 2022
6d7eee0
Enable vue3 test
IanVS Nov 15, 2022
f9e47d8
Disable vue3 tests
IanVS Nov 16, 2022
48c8cc0
Disable vue2 tests
IanVS Nov 16, 2022
80141d9
Upgrade jest-specific-snapshot
IanVS Nov 16, 2022
7d4801a
Disable vue (both 2 and 3) tests for now
IanVS Nov 16, 2022
c77276b
Upgrade jest-specific-snapshot
IanVS Nov 16, 2022
2e46846
Run unit tests in single thread
IanVS Nov 16, 2022
08ba919
Re-enable vue tests
IanVS Nov 16, 2022
ff582a6
Re-disable vue3 test
IanVS Nov 16, 2022
c1a49c4
Merge remote-tracking branch 'origin/next' into marklb/upgrade-to-jest28
IanVS Nov 16, 2022
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ jobs:
name: Test
command: |
cd code
yarn test --coverage --ci
yarn test --coverage --ci --runInBand
- store_test_results:
path: code/junit.xml
- persist_to_workspace:
Expand Down
7 changes: 7 additions & 0 deletions code/addons/a11y/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const path = require('path');
const baseConfig = require('../../jest.config.browser');

module.exports = {
...baseConfig,
displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep),
};
7 changes: 7 additions & 0 deletions code/addons/actions/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const path = require('path');
const baseConfig = require('../../jest.config.browser');

module.exports = {
...baseConfig,
displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep),
};
7 changes: 7 additions & 0 deletions code/addons/backgrounds/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const path = require('path');
const baseConfig = require('../../jest.config.browser');

module.exports = {
...baseConfig,
displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep),
};
7 changes: 7 additions & 0 deletions code/addons/controls/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const path = require('path');
const baseConfig = require('../../jest.config.browser');

module.exports = {
...baseConfig,
displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep),
};
7 changes: 7 additions & 0 deletions code/addons/docs/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const path = require('path');
const baseConfig = require('../../jest.config.browser');

module.exports = {
...baseConfig,
displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep),
};
4 changes: 2 additions & 2 deletions code/addons/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"./angular": "./angular/index.js",
"./angular/index.js": "./angular/index.js",
"./web-components/index.js": "./web-components/index.js",
"./jest-transform-mdx.js": "./jest-transform-mdx.js",
"./jest-transform-mdx": "./jest-transform-mdx.js",
"./package.json": "./package.json"
},
"main": "dist/index.js",
Expand Down Expand Up @@ -85,7 +85,7 @@
},
"dependencies": {
"@babel/plugin-transform-react-jsx": "^7.12.12",
"@jest/transform": "^26.6.2",
"@jest/transform": "^28.0.0",
"@mdx-js/react": "^2.1.5",
"@storybook/blocks": "7.0.0-alpha.49",
"@storybook/components": "7.0.0-alpha.49",
Expand Down
7 changes: 7 additions & 0 deletions code/addons/essentials/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const path = require('path');
const baseConfig = require('../../jest.config.browser');

module.exports = {
...baseConfig,
displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep),
};
1 change: 0 additions & 1 deletion code/addons/essentials/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@
"devDependencies": {
"@babel/core": "^7.12.10",
"@storybook/vue": "7.0.0-alpha.49",
"@types/jest": "^26.0.16",
"typescript": "~4.6.3"
},
"peerDependencies": {
Expand Down
7 changes: 7 additions & 0 deletions code/addons/highlight/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const path = require('path');
const baseConfig = require('../../jest.config.browser');

module.exports = {
...baseConfig,
displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep),
};
7 changes: 7 additions & 0 deletions code/addons/interactions/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const path = require('path');
const baseConfig = require('../../jest.config.browser');

module.exports = {
...baseConfig,
displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep),
};
7 changes: 7 additions & 0 deletions code/addons/jest/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const path = require('path');
const baseConfig = require('../../jest.config.browser');

module.exports = {
...baseConfig,
displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep),
};
7 changes: 7 additions & 0 deletions code/addons/links/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const path = require('path');
const baseConfig = require('../../jest.config.browser');

module.exports = {
...baseConfig,
displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep),
};
7 changes: 7 additions & 0 deletions code/addons/measure/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const path = require('path');
const baseConfig = require('../../jest.config.browser');

module.exports = {
...baseConfig,
displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep),
};
7 changes: 7 additions & 0 deletions code/addons/outline/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const path = require('path');
const baseConfig = require('../../jest.config.browser');

module.exports = {
...baseConfig,
displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep),
};
12 changes: 12 additions & 0 deletions code/addons/storyshots/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const path = require('path');
const baseConfig = require('../../jest.config.browser');

module.exports = {
...baseConfig,
snapshotSerializers: [...baseConfig.snapshotSerializers, 'enzyme-to-json/serializer'],
transform: {
...baseConfig.transform,
'^.+\\.stories\\.[jt]sx?$': '@storybook/addon-storyshots/injectFileName',
},
displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep),
};
7 changes: 3 additions & 4 deletions code/addons/storyshots/storyshots-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"storybook": "yarn sb dev -p 6006"
},
"dependencies": {
"@jest/transform": "^26.6.2",
"@jest/transform": "^28.0.0",
"@storybook/addons": "7.0.0-alpha.49",
"@storybook/babel-plugin-require-context-hook": "1.0.1",
"@storybook/client-api": "7.0.0-alpha.49",
Expand All @@ -46,14 +46,13 @@
"@storybook/core-webpack": "7.0.0-alpha.49",
"@storybook/types": "7.0.0-alpha.49",
"@types/glob": "^7.1.3",
"@types/jest": "^26.0.16",
"@types/jest-specific-snapshot": "^0.5.3",
"core-js": "^3.8.2",
"glob": "^7.1.6",
"global": "^4.4.0",
"jest-specific-snapshot": "^4.0.0",
"jest-specific-snapshot": "^6.0.0",
"preact-render-to-string": "^5.1.19",
"pretty-format": "^26.6.2",
"pretty-format": "^28.0.0",
"react-test-renderer": "^16.8.0 || ^17.0.0 || ^18.0.0",
"read-pkg-up": "^7.0.1",
"ts-dedent": "^2.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,33 @@ const target = new Stories2SnapsConverter();

describe('getSnapshotFileName', () => {
it('fileName is provided - snapshot is stored in __snapshots__ dir', () => {
const context = { fileName: 'foo.js' };
const context = { fileName: 'foo.js', kind: 'kind' };

// @ts-expect-error (TODO)
const result = target.getSnapshotFileName(context);
const platformAgnosticResult = result.replace(/\\|\//g, '/');

expect(platformAgnosticResult).toBe('__snapshots__/foo.storyshot');
// This is an absolute path, so we need to use `toContain()`
expect(platformAgnosticResult).toContain('__snapshots__/foo.storyshot');
});

it('fileName with multiple extensions is provided - only the last extension is replaced', () => {
const context = { fileName: 'foo.web.stories.js' };
const context = { fileName: 'foo.web.stories.js', kind: 'kind' };

// @ts-expect-error (TODO)
const result = target.getSnapshotFileName(context);
const platformAgnosticResult = result.replace(/\\|\//g, '/');

expect(platformAgnosticResult).toBe('__snapshots__/foo.web.stories.storyshot');
// This is an absolute path, so we need to use `toContain()`
expect(platformAgnosticResult).toContain('__snapshots__/foo.web.stories.storyshot');
});

it('fileName with dir is provided - __snapshots__ dir is created inside another dir', () => {
const context = { fileName: 'test/foo.js' };
const context = { fileName: 'test/foo.js', kind: 'kind' };

// @ts-expect-error (TODO)
const result = target.getSnapshotFileName(context);
const platformAgnosticResult = result.replace(/\\|\//g, '/');

expect(platformAgnosticResult).toBe('test/__snapshots__/foo.storyshot');
// This is an absolute path, so we need to use `toContain()`
expect(platformAgnosticResult).toContain('test/__snapshots__/foo.storyshot');
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ export class Stories2SnapsConverter {
const { dir, name } = path.parse(fileName);
const { snapshotsDirName, snapshotExtension } = this.options;

return path.format({ dir: path.join(dir, snapshotsDirName), name, ext: snapshotExtension });
// Convert to absolute path, in case jest is not running in CWD,
// else it will create snapshots with the wrong path
const absDir = path.isAbsolute(dir) ? dir : path.resolve(dir);

return path.format({
dir: path.join(absDir, snapshotsDirName),
name,
ext: snapshotExtension,
});
}

getSnapshotFileName(context: { fileName?: string; kind: any }) {
Expand Down
7 changes: 7 additions & 0 deletions code/addons/storysource/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const path = require('path');
const baseConfig = require('../../jest.config.browser');

module.exports = {
...baseConfig,
displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep),
};
7 changes: 7 additions & 0 deletions code/addons/toolbars/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const path = require('path');
const baseConfig = require('../../jest.config.browser');

module.exports = {
...baseConfig,
displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep),
};
7 changes: 7 additions & 0 deletions code/addons/viewport/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const path = require('path');
const baseConfig = require('../../jest.config.browser');

module.exports = {
...baseConfig,
displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep),
};
9 changes: 8 additions & 1 deletion code/frameworks/angular/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
const path = require('path');

module.exports = {
displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep),
preset: 'jest-preset-angular',
setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'],
transformIgnorePatterns: ['^.+\\.js$'],
transformIgnorePatterns: ['/node_modules/(?!@angular|rxjs|nanoid|uuid)'],
snapshotFormat: {
escapeString: true,
printBasicPrototype: true,
},
};
4 changes: 2 additions & 2 deletions code/frameworks/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@
"@types/rimraf": "^3.0.2",
"@types/tmp": "^0.2.3",
"cross-spawn": "^7.0.3",
"jest": "^27.5.1",
"jest": "^28.0.0",
"jest-preset-angular": "^12.0.0",
"jest-specific-snapshot": "^5.0.0",
"jest-specific-snapshot": "^6.0.0",
"rimraf": "^3.0.2",
"tmp": "^0.2.1",
"typescript": "~4.6.3",
Expand Down
8 changes: 8 additions & 0 deletions code/frameworks/angular/setup-jest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import 'jest-preset-angular/setup-jest';

import { webcrypto } from 'node:crypto';

Object.defineProperty(window, 'crypto', {
get() {
return webcrypto;
},
});

global.EventSource = class {} as any;
Loading