Skip to content

Commit 5b44e38

Browse files
Add support for colocated tests (#182)
1 parent bc6752e commit 5b44e38

6 files changed

+62
-225
lines changed

babel.config.js

-36
This file was deleted.

babel.config.json

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"presets": [
3+
[
4+
"@babel/preset-env",
5+
{
6+
"targets": [
7+
"last 2 chrome versions",
8+
"last 2 firefox versions",
9+
"last 2 safari versions",
10+
"last 2 and_chr versions",
11+
"last 2 ios_saf versions",
12+
"edge >= 18"
13+
],
14+
"modules": false,
15+
"loose": true
16+
}
17+
],
18+
"@babel/preset-react",
19+
"@babel/preset-typescript"
20+
],
21+
"plugins": [
22+
["@babel/plugin-proposal-class-properties"],
23+
"@babel/plugin-proposal-export-namespace-from",
24+
"@babel/plugin-syntax-dynamic-import",
25+
"@babel/plugin-syntax-import-meta",
26+
"@babel/plugin-transform-runtime"
27+
],
28+
"env": {
29+
"development": {
30+
"ignore": [
31+
"**/*.test.ts",
32+
"**/*.test.tsx",
33+
"**/test.ts",
34+
"**/test.tsx"
35+
]
36+
},
37+
"test": {
38+
"presets": ["@babel/preset-env", "@babel/preset-typescript"],
39+
"plugins": ["@babel/plugin-transform-runtime"]
40+
}
41+
}
42+
}

jest.config.js

+4-172
Original file line numberDiff line numberDiff line change
@@ -1,180 +1,12 @@
11
// For a detailed explanation regarding each configuration property, visit:
2-
// https://jestjs.io/docs/en/configuration.html
2+
// https://jestjs.io/docs/configuration
33

4-
// eslint-disable-next-line no-undef
54
module.exports = {
6-
testEnvironment: 'jsdom',
7-
verbose: true,
8-
// All imported modules in your tests should be mocked automatically
9-
// automock: false,
10-
11-
// Stop running tests after the first failure
12-
// bail: false,
13-
14-
// Respect "browser" field in package.json when resolving modules
15-
// browser: false,
16-
17-
// The directory where Jest should store its cached dependency information
18-
// cacheDirectory: "/var/folders/g3/6cmgnryn22l9dddys6yc0rn80000gn/T/jest_dx",
19-
20-
// Automatically clear mock calls and instances between every test
215
clearMocks: true,
22-
23-
// Indicates whether the coverage information should be collected while executing the test
24-
// collectCoverage: false,
25-
26-
// An array of glob patterns indicating a set of files for which coverage information should be collected
27-
// collectCoverageFrom: null,
28-
29-
// The directory where Jest should output its coverage files
306
coverageDirectory: './coverage/',
31-
32-
// An array of regexp pattern strings used to skip coverage collection
33-
// coveragePathIgnorePatterns: [
34-
// "/node_modules/"
35-
// ],
36-
37-
// A list of reporter names that Jest uses when writing coverage reports
38-
// coverageReporters: [
39-
// "json",
40-
// "text",
41-
// "lcov",
42-
// "clover"
43-
// ],
44-
45-
// An object that configures minimum threshold enforcement for coverage results
46-
// coverageThreshold: null,
47-
48-
// Make calling deprecated APIs throw helpful error messages
49-
// errorOnDeprecated: false,
50-
51-
// Force coverage collection from ignored files usin a array of glob patterns
52-
// forceCoverageMatch: [],
53-
54-
// A path to a module which exports an async function that is triggered once before all test suites
55-
// globalSetup: null,
56-
57-
// A path to a module which exports an async function that is triggered once after all test suites
58-
// globalTeardown: null,
59-
60-
// A set of global variables that need to be available in all test environments
61-
// globals: {},
62-
63-
// An array of directory names to be searched recursively up from the requiring module's location
64-
// moduleDirectories: [
65-
// "node_modules"
66-
// ],
67-
68-
// An array of file extensions your modules use
69-
// moduleFileExtensions: [
70-
// "js",
71-
// "json",
72-
// "jsx",
73-
// "node"
74-
// ],
75-
76-
// A map from regular expressions to module names that allow to stub out resources with a single module
77-
// moduleNameMapper: {},
78-
79-
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
80-
// modulePathIgnorePatterns: [],
81-
82-
// Activates notifications for test results
83-
// notify: false,
84-
85-
// An enum that specifies notification mode. Requires { notify: true }
86-
// notifyMode: "always",
87-
88-
// A preset that is used as a base for Jest's configuration
89-
// preset: null,
90-
91-
// Run tests from one or more projects
92-
// projects: null,
93-
94-
// Use this configuration option to add custom reporters to Jest
95-
// reporters: undefined,
96-
97-
// Automatically reset mock state between every test
987
resetMocks: true,
99-
100-
// Reset the module registry before running each individual test
101-
// resetModules: false,
102-
103-
// A path to a custom resolver
104-
// resolver: null,
105-
106-
// Automatically restore mock state between every test
107-
// restoreMocks: false,
108-
109-
// The root directory that Jest should scan for tests and modules within
110-
// rootDir: null,
111-
112-
// A list of paths to directories that Jest should use to search for files in
113-
// roots: [
114-
// "<rootDir>"
115-
// ],
116-
117-
// Allows you to use a custom runner instead of Jest's default test runner
118-
// runner: "jest-runner",
119-
120-
// The paths to modules that run some code to configure or set up the testing environment before each test
121-
// setupFiles: [],
122-
123-
// The paths to modules that runs some code to configure or set up the testing framework before each test
1248
setupFilesAfterEnv: ['<rootDir>jest.setup.js'],
125-
126-
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
127-
// snapshotSerializers: [],
128-
129-
// The test environment that will be used for testing
130-
// testEnvironment: "jest-environment-jsdom",
131-
132-
// Options that will be passed to the testEnvironment
133-
// testEnvironmentOptions: {},
134-
135-
// Adds a location field to test results
136-
// testLocationInResults: false,
137-
138-
// The glob patterns Jest uses to detect test files
139-
testMatch: ['<rootDir>/src/__tests__/**/?(*.)+(spec|test).(j|t)s?(x)'],
140-
141-
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
142-
// testPathIgnorePatterns: [
143-
// "/node_modules/"
144-
// ],
145-
146-
// The regexp pattern Jest uses to detect test files
147-
// testRegex: "",
148-
149-
// This option allows the use of a custom results processor
150-
// testResultsProcessor: null,
151-
152-
// This option allows use of a custom test runner
153-
// testRunner: "jasmine2",
154-
155-
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
156-
// testURL: "http://localhost",
157-
158-
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
159-
// timers: "real",
160-
161-
// A map from regular expressions to paths to transformers
162-
// transform: null,
163-
164-
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
165-
// transformIgnorePatterns: [
166-
// "/node_modules/"
167-
// ],
168-
169-
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
170-
// unmockedModulePathPatterns: undefined,
171-
172-
// Indicates whether each individual test should be reported during the run
173-
// verbose: null,
174-
175-
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
176-
// watchPathIgnorePatterns: [],
177-
178-
// Whether to use watchman for file crawling
179-
// watchman: true,
9+
testEnvironment: 'jsdom',
10+
testMatch: ['<rootDir>/src/**/?(*.)*test.ts?(x)'],
11+
verbose: true,
18012
};

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,11 @@
4545
"main": "build/cjs/index.js",
4646
"module": "build/esm/index.js",
4747
"types": "build/cjs/index.d.ts",
48-
"engines": {
49-
"node": ">=10.0"
50-
},
5148
"scripts": {
5249
"build": "npm run build:clean && npm run build:types-cjs && npm run build:types-esm && npm run build:cjs && npm run build:esm",
53-
"build:cjs": "babel src --out-dir build/cjs --extensions \".ts,.tsx\" --ignore src/__tests__ --presets @babel/env",
50+
"build:cjs": "babel src --out-dir build/cjs --extensions \".ts,.tsx\" --presets @babel/env",
5451
"build:clean": "rm -rf ./build",
55-
"build:esm": "babel src --out-dir build/esm --extensions \".ts,.tsx\" --ignore src/__tests__",
52+
"build:esm": "babel src --out-dir build/esm --extensions \".ts,.tsx\"",
5653
"build:types-cjs": "tsc --emitDeclarationOnly --project tsconfig.build.json --outDir build/cjs && cp src/*.flow build/cjs",
5754
"build:types-esm": "tsc --emitDeclarationOnly --project tsconfig.build.json --outDir build/esm && cp src/*.flow build/esm",
5855
"docs": "npx docsify-cli serve docs",
@@ -138,5 +135,8 @@
138135
"history": "^4 || ^5",
139136
"react": "^16.8.0",
140137
"react-dom": "^16.8.0"
138+
},
139+
"engines": {
140+
"node": ">=10.0"
141141
}
142142
}

tsconfig.build.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"extends": "./tsconfig.json",
33
"include": ["src/**/*"],
4-
"exclude": ["examples/**/*", "src/__tests__/**/*"]
4+
"exclude": ["examples/**/*", "src/__tests__/**/*", "src/**/*test.ts"]
55
}

tsconfig.json

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
{
22
"compilerOptions": {
3-
"target": "esnext",
4-
"module": "esnext",
3+
"baseUrl": ".",
54
"declaration": true,
6-
"outDir": "lib",
75
"esModuleInterop": true,
8-
"moduleResolution": "node",
9-
"strict": true,
10-
"skipLibCheck": true,
11-
"preserveConstEnums": true,
126
"isolatedModules": true,
137
"jsx": "preserve",
14-
"typeRoots": ["./node_modules/@types", "types"],
15-
"baseUrl": ".",
8+
"module": "esnext",
9+
"moduleResolution": "node",
1610
"paths": {
1711
"react-resource-router": ["src"]
18-
}
12+
},
13+
"preserveConstEnums": true,
14+
"skipLibCheck": true,
15+
"strict": true,
16+
"target": "esnext",
17+
"typeRoots": ["./node_modules/@types", "types"],
1918
},
20-
"include": ["src/**/*", "examples/**/*"],
19+
"include": ["examples/**/*", "src/**/*"],
2120
"exclude": ["**/*.js.flow"]
2221
}

0 commit comments

Comments
 (0)