Skip to content

Commit ad4297f

Browse files
authored
chore: upgrade jest to v29 (#194)
1 parent 0bbb6c3 commit ad4297f

16 files changed

+1195
-1139
lines changed

e2e/__snapshots__/e2e.spec.ts.snap

Lines changed: 185 additions & 185 deletions
Large diffs are not rendered by default.

jest.config.ts

Lines changed: 6 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -4,198 +4,25 @@
44
*/
55

66
export default {
7-
// All imported modules in your tests should be mocked automatically
8-
// automock: false,
9-
10-
// Stop running tests after `n` failures
11-
// bail: 0,
12-
13-
// The directory where Jest should store its cached dependency information
14-
// cacheDirectory: "/private/var/folders/pd/mpctclh50bd0bxp2n1th3z_w0000gn/T/jest_dx",
15-
167
// Automatically clear mock calls, instances, contexts and results before every test
178
clearMocks: true,
189

19-
// Indicates whether the coverage information should be collected while executing the test
20-
// collectCoverage: false,
21-
22-
// An array of glob patterns indicating a set of files for which coverage information should be collected
23-
// collectCoverageFrom: undefined,
24-
25-
// The directory where Jest should output its coverage files
26-
// coverageDirectory: undefined,
27-
28-
// An array of regexp pattern strings used to skip coverage collection
29-
// coveragePathIgnorePatterns: [
30-
// "/node_modules/"
31-
// ],
32-
33-
// Indicates which provider should be used to instrument code for coverage
34-
coverageProvider: "v8",
35-
36-
// A list of reporter names that Jest uses when writing coverage reports
37-
// coverageReporters: [
38-
// "json",
39-
// "text",
40-
// "lcov",
41-
// "clover"
42-
// ],
43-
44-
// An object that configures minimum threshold enforcement for coverage results
45-
// coverageThreshold: undefined,
46-
47-
// A path to a custom dependency extractor
48-
// dependencyExtractor: undefined,
49-
50-
// Make calling deprecated APIs throw helpful error messages
51-
// errorOnDeprecated: false,
52-
53-
// The default configuration for fake timers
54-
// fakeTimers: {
55-
// "enableGlobally": false
56-
// },
57-
58-
// Force coverage collection from ignored files using an array of glob patterns
59-
// forceCoverageMatch: [],
60-
61-
// A path to a module which exports an async function that is triggered once before all test suites
62-
// globalSetup: undefined,
63-
64-
// A path to a module which exports an async function that is triggered once after all test suites
65-
// globalTeardown: undefined,
66-
67-
// A set of global variables that need to be available in all test environments
68-
globals: {
69-
"ts-jest": {
70-
useESM: true,
71-
},
72-
},
73-
74-
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
75-
// maxWorkers: "50%",
76-
77-
// An array of directory names to be searched recursively up from the requiring module's location
78-
// moduleDirectories: [
79-
// "node_modules"
80-
// ],
81-
82-
// An array of file extensions your modules use
83-
// moduleFileExtensions: [
84-
// "js",
85-
// "mjs",
86-
// "cjs",
87-
// "jsx",
88-
// "ts",
89-
// "tsx",
90-
// "json",
91-
// "node"
92-
// ],
93-
9410
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
9511
moduleNameMapper: {
12+
// We compile TypeScript to ES6 which requires extensions in module specifiers,
13+
// however adding the extension fails under jest tests. Remove the ".js" extension
14+
// from module names when running tests.
9615
"^(\\.{1,2}/.*)\\.js$": "$1",
9716
},
9817

99-
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
100-
// modulePathIgnorePatterns: [],
101-
102-
// Activates notifications for test results
103-
// notify: false,
104-
105-
// An enum that specifies notification mode. Requires { notify: true }
106-
// notifyMode: "failure-change",
107-
108-
// A preset that is used as a base for Jest's configuration
109-
// preset: undefined,
110-
111-
// Run tests from one or more projects
112-
// projects: undefined,
113-
114-
// Use this configuration option to add custom reporters to Jest
115-
// reporters: undefined,
116-
117-
// Automatically reset mock state before every test
118-
// resetMocks: false,
119-
120-
// Reset the module registry before running each individual test
121-
// resetModules: false,
122-
123-
// A path to a custom resolver
124-
// resolver: undefined,
125-
126-
// Automatically restore mock state and implementation before every test
127-
// restoreMocks: false,
128-
129-
// The root directory that Jest should scan for tests and modules within
130-
// rootDir: undefined,
131-
132-
// A list of paths to directories that Jest should use to search for files in
133-
roots: ["src", "e2e"],
134-
135-
// Allows you to use a custom runner instead of Jest's default test runner
136-
// runner: "jest-runner",
137-
138-
// The paths to modules that run some code to configure or set up the testing environment before each test
139-
// setupFiles: [],
18+
// An array of regexp pattern strings that are matched against all module paths before those paths are to be considered 'visible' to the module loader.
19+
modulePathIgnorePatterns: ["<rootDir>/dist"],
14020

14121
// A list of paths to modules that run some code to configure or set up the testing framework before each test
142-
// setupFilesAfterEnv: [],
143-
144-
// The number of seconds after which a test is considered as slow and reported as such in the results.
145-
// slowTestThreshold: 5,
146-
147-
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
148-
// snapshotSerializers: [],
149-
150-
// The test environment that will be used for testing
151-
// testEnvironment: "jest-environment-node",
152-
153-
// Options that will be passed to the testEnvironment
154-
// testEnvironmentOptions: {},
155-
156-
// Adds a location field to test results
157-
// testLocationInResults: false,
158-
159-
// The glob patterns Jest uses to detect test files
160-
// testMatch: [
161-
// "**/__tests__/**/*.[jt]s?(x)",
162-
// "**/?(*.)+(spec|test).[tj]s?(x)"
163-
// ],
164-
165-
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
166-
// testPathIgnorePatterns: [
167-
// "/node_modules/"
168-
// ],
169-
170-
// The regexp pattern or array of patterns that Jest uses to detect test files
171-
// testRegex: [],
172-
173-
// This option allows the use of a custom results processor
174-
// testResultsProcessor: undefined,
175-
176-
// This option allows use of a custom test runner
177-
// testRunner: "jest-circus/runner",
22+
setupFilesAfterEnv: ["./jest.setup.ts"],
17823

17924
// A map from regular expressions to paths to transformers
18025
transform: {
18126
"^.+\\.ts?$": "ts-jest",
18227
},
183-
184-
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
185-
// transformIgnorePatterns: [
186-
// "/node_modules/",
187-
// "\\.pnp\\.[^\\/]+$"
188-
// ],
189-
190-
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
191-
// unmockedModulePathPatterns: undefined,
192-
193-
// Indicates whether each individual test should be reported during the run
194-
// verbose: undefined,
195-
196-
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
197-
// watchPathIgnorePatterns: [],
198-
199-
// Whether to use watchman for file crawling
200-
// watchman: true,
20128
};

jest.setup.ts

Lines changed: 11 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,9 @@
1-
import { MatcherFunction } from 'expect'
1+
import { expect } from "@jest/globals";
22

3-
declare global {
4-
namespace jest {
5-
interface Matchers<R> {
6-
toThrowErrorContaining<T extends Error>(
7-
errorType: new (...args: any[]) => T,
8-
message: string
9-
): R;
10-
}
11-
interface Expect {
12-
matchesPredicate(predicate: (actual: any) => boolean): any;
13-
}
14-
interface ExpectExtendMap {
15-
matchesPredicate: MatcherFunction<[predicate: (actual: any) => boolean]>;
16-
}
17-
}
18-
}
3+
import { toThrowWithMessage } from "jest-extended";
4+
expect.extend({ toThrowWithMessage });
195

206
expect.extend({
21-
toThrowErrorContaining<T extends Error>(
22-
func: Function,
23-
errorType: new (...args: any[]) => T,
24-
message: string
25-
) {
26-
try {
27-
func();
28-
} catch (e) {
29-
if (!(e instanceof errorType)) {
30-
return {
31-
pass: false,
32-
message: () => `\
33-
Expected error to throw:
34-
35-
${errorType}
36-
37-
But instead it threw:
38-
39-
${e.constructor}
40-
`,
41-
};
42-
}
43-
44-
if (!e.message.includes(message)) {
45-
return {
46-
pass: false,
47-
message: () => `\
48-
Expected error message to contain:
49-
50-
${message}
51-
52-
But instead it was:
53-
54-
${e.message}
55-
`,
56-
};
57-
}
58-
59-
return {
60-
pass: true,
61-
message: () => "",
62-
};
63-
}
64-
65-
return {
66-
pass: false,
67-
message: () => "Expected function to throw but it did not",
68-
};
69-
},
70-
717
matchesPredicate(actual: any, predicate: (actual: any) => boolean) {
728
return {
739
pass: predicate(actual),
@@ -76,4 +12,12 @@ But instead it was:
7612
},
7713
});
7814

15+
declare global {
16+
namespace jest {
17+
interface Expect {
18+
matchesPredicate(predicate: (actual: any) => boolean): any;
19+
}
20+
}
21+
}
22+
7923
export default undefined;

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@
4242
"yaml": "^2.1.1"
4343
},
4444
"devDependencies": {
45+
"@jest/globals": "^29.7.0",
4546
"@octokit/webhooks-methods": "^4.0.0",
4647
"@types/archiver": "^6.0.2",
4748
"@types/diff": "^5.0.2",
4849
"@types/imapflow": "1.0.17",
49-
"@types/jest": "^28.0.0",
50+
"@types/jest": "^29.5.14",
5051
"@types/mailparser": "^3.4.4",
5152
"@types/node": "^18.6.2",
5253
"@types/nodemailer": "^6.4.5",
@@ -57,12 +58,13 @@
5758
"expect": "^28.1.3",
5859
"globby": "^14.0.0",
5960
"imapflow": "^1.0.147",
60-
"jest": "^28.1.3",
61-
"jest-mock": "^28.1.3",
61+
"jest": "^29.7.0",
62+
"jest-extended": "^4.0.2",
63+
"jest-mock": "^29.7.0",
6264
"mailparser": "3.6.6",
6365
"mockttp": "^3.10.0",
6466
"portfinder": "^1.0.32",
65-
"ts-jest": "^28.0.7",
67+
"ts-jest": "^29.2.5",
6668
"ts-node": "^10.9.1",
6769
"typescript": "^5.0.0"
6870
},

0 commit comments

Comments
 (0)