Skip to content

Commit ffaa423

Browse files
Testing running unit test with swc
1 parent 562464b commit ffaa423

File tree

6 files changed

+1569
-858
lines changed

6 files changed

+1569
-858
lines changed

.swcrc

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
// .swcrc should be treated as JSONC
3+
4+
"sourceMaps": true,
5+
6+
"jsc": {
7+
"parser": {
8+
"syntax": "ecmascript",
9+
"jsx": true
10+
},
11+
12+
"transform": {
13+
"react": {
14+
"runtime": "automatic"
15+
}
16+
},
17+
18+
"baseUrl": "./app/javascript",
19+
"paths": {
20+
"test-utils":[ "./test-utils/index.js"]
21+
}
22+
}
23+
}

app/javascript/test-utils/globals.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import "mutationobserver-shim";
2-
import { MessageChannel } from "worker_threads";
32

43
import get from "lodash/get";
54
import { parseISO, format as formatDate } from "date-fns";
@@ -90,4 +89,3 @@ class Worker {
9089
addEventListener() {}
9190
}
9291
global.Worker = Worker;
93-
global.MessageChannel = MessageChannel;

app/javascript/test-utils/setup.js

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
import "react-16-node-hanging-test-fix"; // TODO: Remove when update to React 18
22
import "./globals";
33
import "@testing-library/jest-dom/extend-expect";
4+
import { MessageChannel } from "worker_threads";
5+
6+
import { createMocks } from "react-idle-timer";
7+
import { cleanup } from "@testing-library/react";
48

59
global.IS_REACT_ACT_ENVIRONMENT = true;
10+
11+
beforeAll(() => {
12+
createMocks();
13+
global.MessageChannel = MessageChannel;
14+
});
15+
16+
afterEach(cleanup);

jest.config.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ module.exports = {
121121
// restoreMocks: false,
122122

123123
// The root directory that Jest should scan for tests and modules within
124-
// rootDir: undefined,
124+
rootDir: "./app/javascript",
125125

126126
// A list of paths to directories that Jest should use to search for files in
127127
// roots: [
@@ -135,7 +135,7 @@ module.exports = {
135135
setupFiles: ["fake-indexeddb/auto"],
136136

137137
// A list of paths to modules that run some code to configure or set up the testing framework before each test
138-
setupFilesAfterEnv: ["./app/javascript/test-utils/setup.js"],
138+
setupFilesAfterEnv: ["./test-utils/setup.js"],
139139

140140
// The number of seconds after which a test is considered as slow and reported as such in the results.
141141
// slowTestThreshold: 5,
@@ -153,7 +153,7 @@ module.exports = {
153153
// testLocationInResults: false,
154154

155155
// The glob patterns Jest uses to detect test files
156-
testMatch: ["<rootDir>/app/javascript/components/**/*.spec.js"],
156+
testMatch: ["<rootDir>/components/**/*.spec.js"],
157157

158158
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
159159
// testPathIgnorePatterns: ["/node_modules/"],
@@ -168,10 +168,13 @@ module.exports = {
168168
// testRunner: "jest-circus/runner",
169169

170170
// A map from regular expressions to paths to transformers
171-
// transform: {}
171+
transform: {
172+
"^.+\\.(t|j)sx?$": "@swc/jest",
173+
"^.+\\.(t|j)s?$": "@swc/jest"
174+
},
172175

173176
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
174-
transformIgnorePatterns: ["node_modules/(?!uuid|(?!proxy-memoize)|proxy-memoize)"]
177+
transformIgnorePatterns: []
175178

176179
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
177180
// unmockedModulePathPatterns: undefined,

0 commit comments

Comments
 (0)