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

Try: @swc/jest for transformation #84225

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Draft
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
9 changes: 9 additions & 0 deletions client/__mocks__/file-transformer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const path = require( 'path' );

module.exports = {
process( sourceText, sourcePath ) {
return {
code: `module.exports = ${ JSON.stringify( path.basename( sourcePath ) ) };`,
};
},
};
6 changes: 5 additions & 1 deletion client/state/test/initial-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

import { withStorageKey } from '@automattic/state-utils';
import * as browserStorage from 'calypso/lib/browser-storage';
import * as browserStorageMethods from 'calypso/lib/browser-storage';
import { isSupportSession } from 'calypso/lib/user/support-user-interop';
import { createReduxStore } from 'calypso/state';
import { addReducerToStore } from 'calypso/state/add-reducer';
Expand All @@ -27,6 +27,9 @@ const initialReducer = combineReducers( {
postTypes,
} );

// Needed to be able to mock browserStorage later
const browserStorage = { ...browserStorageMethods };

jest.mock( 'calypso/lib/user/support-user-interop', () => ( {
isSupportSession: jest.fn().mockReturnValue( false ),
} ) );
Expand Down Expand Up @@ -1000,6 +1003,7 @@ describe( 'loading stored state with dynamic reducers', () => {

// load initial state and create Redux store with it
await loadPersistedState();

const userId = 123456789;
const state = getInitialState( reducer, userId );
const store = createReduxStore( state, reducer );
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@
"@signal-noise/stylelint-scales": "^2.0.3",
"@storybook/cli": "^7.5.2",
"@storybook/react": "^7.5.2",
"@swc/core": "^1.3.96",
"@swc/jest": "^0.2.29",
"@tanstack/eslint-plugin-query": "^4.29.8",
"@testing-library/jest-dom": "^6.1.4",
"@types/gradient-parser": "^0.1.4",
Expand Down
25 changes: 24 additions & 1 deletion test/client/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,33 @@ module.exports = {
rootDir: '../../client',
cacheDirectory: path.join( __dirname, '../../.cache/jest' ),
testPathIgnorePatterns: [ '<rootDir>/server/' ],

moduleNameMapper: {
'^@automattic/calypso-config$': '<rootDir>/server/config/index.js',
},
transform: {
'\\.(css|scss|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/__mocks__/file-transformer.js',
'^.+\\.(t|j)sx?$': [
'@swc/jest',
{
jsc: {
parser: {
syntax: 'typescript',
tsx: true,
},
transform: {
react: {
runtime: 'automatic',
},
},
},
env: {
mode: 'entry',
coreJs: '3.33.2',
},
},
],
},
transformIgnorePatterns: [
'node_modules[\\/\\\\](?!.*\\.(?:gif|jpg|jpeg|png|svg|scss|sass|css)$)',
],
Expand Down
47 changes: 46 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4349,6 +4349,15 @@ __metadata:
languageName: node
linkType: hard

"@jest/create-cache-key-function@npm:^27.4.2":
version: 27.5.1
resolution: "@jest/create-cache-key-function@npm:27.5.1"
dependencies:
"@jest/types": ^27.5.1
checksum: 1890ac93fad852e0a98c31de1e5f2c548974aefd36e838d27b70834dda1654a153ed6a52258447ebacfd47463e9bdb83750631bee827797c7b9973c083998a96
languageName: node
linkType: hard

"@jest/environment@npm:^29.7.0":
version: 29.7.0
resolution: "@jest/environment@npm:29.7.0"
Expand Down Expand Up @@ -4510,6 +4519,19 @@ __metadata:
languageName: node
linkType: hard

"@jest/types@npm:^27.5.1":
version: 27.5.1
resolution: "@jest/types@npm:27.5.1"
dependencies:
"@types/istanbul-lib-coverage": ^2.0.0
"@types/istanbul-reports": ^3.0.0
"@types/node": "*"
"@types/yargs": ^16.0.0
chalk: ^4.0.0
checksum: 4598b302398db0eb77168b75a6c58148ea02cc9b9f21c5d1bbe985c1c9257110a5653cf7b901c3cab87fba231e3fed83633687f1c0903b4bc6939ab2a8452504
languageName: node
linkType: hard

"@jest/types@npm:^29.5.0, @jest/types@npm:^29.6.3":
version: 29.6.3
resolution: "@jest/types@npm:29.6.3"
Expand Down Expand Up @@ -7061,7 +7083,7 @@ __metadata:
languageName: node
linkType: hard

"@swc/core@npm:^1.3.82":
"@swc/core@npm:^1.3.82, @swc/core@npm:^1.3.96":
version: 1.3.96
resolution: "@swc/core@npm:1.3.96"
dependencies:
Expand Down Expand Up @@ -7114,6 +7136,18 @@ __metadata:
languageName: node
linkType: hard

"@swc/jest@npm:^0.2.29":
version: 0.2.29
resolution: "@swc/jest@npm:0.2.29"
dependencies:
"@jest/create-cache-key-function": ^27.4.2
jsonc-parser: ^3.2.0
peerDependencies:
"@swc/core": "*"
checksum: 10f34341f9bc8003cec44f91a88b531ba44094aad97b2f8410fb2f94db9eb3b8fc7f6d14ba867eb9c1dc6ba29cc46058244b8280d673a7c681062fe0dc73c3f0
languageName: node
linkType: hard

"@swc/types@npm:^0.1.5":
version: 0.1.5
resolution: "@swc/types@npm:0.1.5"
Expand Down Expand Up @@ -8356,6 +8390,15 @@ __metadata:
languageName: node
linkType: hard

"@types/yargs@npm:^16.0.0":
version: 16.0.8
resolution: "@types/yargs@npm:16.0.8"
dependencies:
"@types/yargs-parser": "*"
checksum: ba659eb5a48009ccaa8d6426ad63f2b8de09c153d02f70c911d86b421cfc29ad63e92e17c120d97e81f43cda306760fb3cb5a4137b083d5fafb38c174a6ddf01
languageName: node
linkType: hard

"@types/yargs@npm:^17.0.1, @types/yargs@npm:^17.0.8":
version: 17.0.24
resolution: "@types/yargs@npm:17.0.24"
Expand Down Expand Up @@ -32247,6 +32290,8 @@ __metadata:
"@signal-noise/stylelint-scales": ^2.0.3
"@storybook/cli": ^7.5.2
"@storybook/react": ^7.5.2
"@swc/core": ^1.3.96
"@swc/jest": ^0.2.29
"@tanstack/eslint-plugin-query": ^4.29.8
"@testing-library/jest-dom": ^6.1.4
"@types/cookie": ^0.4.1
Expand Down
Loading