Skip to content

Commit a7b65e3

Browse files
authored
Merge pull request #385 from gadget-inc/swc-jest
Upgrade jest, use swc, switch to community package for playwright integration
2 parents 85af14f + e252778 commit a7b65e3

File tree

14 files changed

+1361
-1263
lines changed

14 files changed

+1361
-1263
lines changed

.swcrc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"env": {
3+
"targets": {
4+
"node": 16
5+
}
6+
},
7+
"jsc": {
8+
"parser": {
9+
"syntax": "typescript",
10+
"decorators": true,
11+
"dynamicImport": true
12+
},
13+
"target": "es2020"
14+
},
15+
"module": {
16+
"type": "commonjs"
17+
}
18+
}

jest.config.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
module.exports = {
2-
preset: 'ts-jest',
3-
testTimeout: process.env.CI ? 30000 : 10000,
4-
globalSetup: './scripts/jestGlobalSetup.js',
5-
globalTeardown: './scripts/jestGlobalTeardown.js',
6-
testEnvironment: './scripts/jestEnv.js',
2+
projects: ['<rootDir>/packages/fastify-renderer', '<rootDir>/packages/test-apps/simple-react'],
73
}

packages/fastify-renderer/jest.config.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ module.exports = {
9393
// notifyMode: "failure-change",
9494

9595
// A preset that is used as a base for Jest's configuration
96-
preset: 'ts-jest',
96+
// preset: 'ts-jest',
9797

9898
// Run tests from one or more projects
9999
// projects: undefined,
@@ -172,7 +172,9 @@ module.exports = {
172172
// timers: "real",
173173

174174
// A map from regular expressions to paths to transformers
175-
// transform: undefined,
175+
transform: {
176+
'^.+\\.(t|j)sx?$': '@swc/jest',
177+
},
176178

177179
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
178180
// transformIgnorePatterns: [

packages/fastify-renderer/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@
7777
"react-dom": "experimental"
7878
},
7979
"devDependencies": {
80+
"@swc/core": "^1.2.218",
81+
"@swc/jest": "^0.2.22",
8082
"@types/connect": "^3.4.35",
8183
"@types/jest": "^26.0.24",
8284
"@types/node": "^14.17.20",
@@ -93,15 +95,15 @@
9395
"eslint-plugin-react-hooks": "^4.6.0",
9496
"fastify": "^3.29.0",
9597
"gitpkg": "^1.0.0-beta.2",
96-
"jest": "^27.5.1",
98+
"jest": "^28.1.3",
99+
"jest-playwright-preset": "^2.0.0",
97100
"npm-run-all": "^4.1.5",
98101
"pino-pretty": "^4.8.0",
99102
"prettier": "^2.7.1",
100103
"prettier-plugin-organize-imports": "^2.3.4",
101104
"react": "0.0.0-experimental-4ead6b530",
102105
"react-dom": "0.0.0-experimental-4ead6b530",
103106
"rimraf": "^3.0.2",
104-
"ts-jest": "^27.1.4",
105107
"typescript": "^4.7.4"
106108
},
107109
"files": [

packages/fastify-renderer/test/esm/default-esm-export.mjs

Lines changed: 0 additions & 4 deletions
This file was deleted.

packages/fastify-renderer/test/esm/esm.test.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

packages/fastify-renderer/test/esm/named-esm-export.mjs

Lines changed: 0 additions & 4 deletions
This file was deleted.

packages/test-apps/helpers.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
import { FastifyInstance } from 'fastify'
22
import fs from 'fs-extra'
33
import { resolve } from 'path'
4-
import { Browser, ConsoleMessage, Page } from 'playwright-chromium'
5-
6-
// injected by the test env
7-
declare global {
8-
// eslint-disable-next-line @typescript-eslint/no-namespace
9-
namespace NodeJS {
10-
interface Global {
11-
browser?: Browser
12-
}
13-
}
14-
}
4+
import { ConsoleMessage, Page } from 'playwright-chromium'
155

166
export function slash(p: string): string {
177
return p.replace(/\\/g, '/')
@@ -72,7 +62,7 @@ afterEach(async () => {
7262

7363
/** Create a new playwright page for testing against */
7464
export const newTestPage = async (): Promise<Page> => {
75-
const page: Page = await (global as any).browser.newPage()
65+
const page: Page = await browser.newPage()
7666
page.on('console', onConsole)
7767
pages.push(page)
7868

packages/test-apps/simple-react/jest.config.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ module.exports = {
5454
// forceCoverageMatch: [],
5555

5656
// A path to a module which exports an async function that is triggered once before all test suites
57-
// globalSetup: undefined,
57+
// globalSetup: '../../../scripts/jestGlobalSetup.js',
5858

5959
// A path to a module which exports an async function that is triggered once after all test suites
60-
// globalTeardown: undefined,
60+
// globalTeardown: '../../../scripts/jestGlobalTeardown.js',
6161

6262
// A set of global variables that need to be available in all test environments
6363
// globals: {},
@@ -93,7 +93,7 @@ module.exports = {
9393
// notifyMode: "failure-change",
9494

9595
// A preset that is used as a base for Jest's configuration
96-
preset: 'ts-jest',
96+
preset: 'jest-playwright-preset',
9797

9898
// Run tests from one or more projects
9999
// projects: undefined,
@@ -137,7 +137,7 @@ module.exports = {
137137
// snapshotSerializers: [],
138138

139139
// The test environment that will be used for testing
140-
testEnvironment: 'node',
140+
// testEnvironment: '../../../scripts/jestEnv.js',
141141

142142
// Options that will be passed to the testEnvironment
143143
// testEnvironmentOptions: {},
@@ -172,7 +172,9 @@ module.exports = {
172172
// timers: "real",
173173

174174
// A map from regular expressions to paths to transformers
175-
// transform: undefined,
175+
transform: {
176+
'^.+\\.(t|j)sx?$': '@swc/jest',
177+
},
176178

177179
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
178180
// transformIgnorePatterns: [

packages/test-apps/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"module": "commonjs",
99
"lib": ["ES2020", "dom"],
1010
"sourceMap": true,
11-
"types": ["jest", "node"]
11+
"types": ["jest", "node", "jest-playwright-preset", "expect-playwright"]
1212
}
1313
}

0 commit comments

Comments
 (0)