Skip to content

Commit c900b4f

Browse files
committed
Turns out testing with JSDom is first-class in Jest!
1 parent 246c9e9 commit c900b4f

26 files changed

+16989
-18460
lines changed

.babelrc.json

-19
This file was deleted.

.eslintrc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
},
2424
"ignorePatterns": [
2525
"rollup.config.mjs",
26-
"tests/jest.config.js",
26+
"jest.config.js",
2727
"dist/"
2828
],
2929
"overrides": [

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
dist/
22
node_modules
3-
tests/coverage/*
3+
coverage

babel.config.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
'@babel/preset-env',
5+
{
6+
targets: {
7+
node: 'current',
8+
},
9+
},
10+
],
11+
],
12+
plugins: [
13+
'@babel/plugin-transform-runtime',
14+
],
15+
};

tests/jest.config.js jest.config.js

+24-17
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
1-
/*
1+
/**
22
* For a detailed explanation regarding each configuration property, visit:
33
* https://jestjs.io/docs/configuration
44
*/
55

6-
module.exports = {
6+
/** @type {import('jest').Config} */
7+
const config = {
78
// All imported modules in your tests should be mocked automatically
89
// automock: false,
910

1011
// Stop running tests after `n` failures
1112
// bail: 0,
1213

1314
// The directory where Jest should store its cached dependency information
14-
// cacheDirectory: "/private/var/folders/81/m6w95r0j7ms_10c47hdbz4gw0000gn/T/jest_dx",
15+
// cacheDirectory: "/tmp/jest_rs",
1516

16-
// Automatically clear mock calls, instances and results before every test
17+
// Automatically clear mock calls, instances, contexts and results before every test
1718
clearMocks: true,
1819

1920
// Indicates whether the coverage information should be collected while executing the test
20-
// collectCoverage: false,
21+
collectCoverage: true,
2122

2223
// An array of glob patterns indicating a set of files for which coverage information should be collected
2324
// collectCoverageFrom: undefined,
2425

2526
// The directory where Jest should output its coverage files
26-
// coverageDirectory: undefined,
27+
coverageDirectory: "coverage",
2728

2829
// An array of regexp pattern strings used to skip coverage collection
29-
// coveragePathIgnorePatterns: [
30-
// "/node_modules/"
31-
// ],
30+
coveragePathIgnorePatterns: [
31+
"/node_modules/",
32+
"/tests/fixtures/",
33+
],
3234

3335
// Indicates which provider should be used to instrument code for coverage
3436
// coverageProvider: "babel",
@@ -50,6 +52,11 @@ module.exports = {
5052
// Make calling deprecated APIs throw helpful error messages
5153
// errorOnDeprecated: false,
5254

55+
// The default configuration for fake timers
56+
// fakeTimers: {
57+
// "enableGlobally": false
58+
// },
59+
5360
// Force coverage collection from ignored files using an array of glob patterns
5461
// forceCoverageMatch: [],
5562

@@ -73,6 +80,8 @@ module.exports = {
7380
// An array of file extensions your modules use
7481
// moduleFileExtensions: [
7582
// "js",
83+
// "mjs",
84+
// "cjs",
7685
// "jsx",
7786
// "ts",
7887
// "tsx",
@@ -137,7 +146,7 @@ module.exports = {
137146
// snapshotSerializers: [],
138147

139148
// The test environment that will be used for testing
140-
// testEnvironment: "jest-environment-node",
149+
testEnvironment: "jsdom",
141150

142151
// Options that will be passed to the testEnvironment
143152
// testEnvironmentOptions: {},
@@ -165,14 +174,10 @@ module.exports = {
165174
// This option allows use of a custom test runner
166175
// testRunner: "jest-circus/runner",
167176

168-
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
169-
// testURL: "http://localhost",
170-
171-
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
172-
// timers: "real",
173-
174177
// A map from regular expressions to paths to transformers
175-
// transform: undefined,
178+
transform: {
179+
"^.+\\.jsx?$": "babel-jest",
180+
},
176181

177182
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
178183
// transformIgnorePatterns: [
@@ -192,3 +197,5 @@ module.exports = {
192197
// Whether to use watchman for file crawling
193198
// watchman: true,
194199
};
200+
201+
module.exports = config;

0 commit comments

Comments
 (0)