Skip to content

chore(site): Make tests faster #6543

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

Merged
merged 8 commits into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Try setup
  • Loading branch information
BrunoQuaresma committed Mar 9, 2023
commit efbffbca032c35a0c0942697ce97bd844ff472b0
17 changes: 8 additions & 9 deletions site/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@ module.exports = {
maxWorkers,
projects: [
{
globals: {
"ts-jest": {
tsconfig: "./tsconfig.test.json",
},
},
coverageReporters: ["text", "lcov"],
displayName: "test",
preset: "ts-jest",
roots: ["<rootDir>"],
setupFilesAfterEnv: ["./jest.setup.ts"],
extensionsToTreatAsEsm: [".ts"],
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
transform: {
"^.+\\.tsx?$": "ts-jest",
"\\.m?jsx?$": "jest-esm-transformer",
"^.+\\.tsx?$": [
"ts-jest",
{ tsconfig: "./tsconfig.test.json", useESM: true },
],
},
testEnvironment: "jsdom",
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
Expand Down
20 changes: 3 additions & 17 deletions site/jest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,16 @@ import { server } from "./src/testHelpers/server"
import "jest-location-mock"
import { TextEncoder, TextDecoder } from "util"
import { Blob } from "buffer"
import { fetch, Request, Response, Headers } from "@remix-run/web-fetch"
import jestFetchMock from "jest-fetch-mock"

jestFetchMock.enableMocks()

global.TextEncoder = TextEncoder
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Polyfill for jsdom
global.TextDecoder = TextDecoder as any
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Polyfill for jsdom
global.Blob = Blob as any

// From REMIX https://github.com/remix-run/react-router/blob/main/packages/react-router-dom/__tests__/setup.ts
if (!global.fetch) {
// Built-in lib.dom.d.ts expects `fetch(Request | string, ...)` but the web
// fetch API allows a URL so @remix-run/web-fetch defines
// `fetch(string | URL | Request, ...)`
// @ts-expect-error -- Polyfill for jsdom
global.fetch = fetch
// Same as above, lib.dom.d.ts doesn't allow a URL to the Request constructor
// @ts-expect-error -- Polyfill for jsdom
global.Request = Request
// web-std/fetch Response does not currently implement Response.error()
// @ts-expect-error -- Polyfill for jsdom
global.Response = Response
global.Headers = Headers
}

// Polyfill the getRandomValues that is used on utils/random.ts
Object.defineProperty(global.self, "crypto", {
value: {
Expand Down
12 changes: 6 additions & 6 deletions site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"@material-ui/icons": "4.5.1",
"@material-ui/lab": "4.0.0-alpha.42",
"@monaco-editor/react": "4.4.6",
"@remix-run/web-fetch": "4.3.2",
"@tanstack/react-query": "4.22.4",
"@testing-library/react-hooks": "8.0.1",
"@types/color-convert": "2.0.0",
Expand All @@ -59,6 +58,7 @@
"front-matter": "4.0.2",
"history": "5.3.0",
"i18next": "21.9.1",
"jest-environment-jsdom": "^29.5.0",
"jest-location-mock": "1.0.9",
"just-debounce-it": "3.1.1",
"lodash": "4.17.21",
Expand Down Expand Up @@ -96,7 +96,7 @@
"@testing-library/jest-dom": "5.16.4",
"@testing-library/react": "13.4.0",
"@testing-library/user-event": "14.4.3",
"@types/jest": "27.4.1",
"@types/jest": "29.4.0",
"@types/node": "14.18.22",
"@types/react": "18.0.15",
"@types/react-dom": "18.0.6",
Expand All @@ -120,17 +120,17 @@
"eslint-plugin-react": "7.31.1",
"eslint-plugin-react-hooks": "4.6.0",
"eslint-plugin-unicorn": "44.0.0",
"jest": "27.5.1",
"jest": "29.5.0",
"jest-canvas-mock": "2.4.0",
"jest-esm-transformer": "1.0.0",
"jest-fetch-mock": "^3.0.3",
"jest-runner-eslint": "1.1.0",
"jest-websocket-mock": "2.4.0",
"monaco-editor": "0.34.1",
"msw": "0.47.0",
"msw": "^1.1.0",
"prettier": "2.8.1",
"resize-observer": "1.0.4",
"semver": "7.3.7",
"ts-jest": "27.1.4",
"ts-jest": "^29.0.5",
"typescript": "4.8.2"
},
"browserslist": [
Expand Down
Loading