Skip to content

Commit ebc0ff0

Browse files
authored
Switch Jest config to CLI options to allow project-level customization (#168)
* Switch Jest config to inline That way, the project configuration will be inherited. This allows additional customization - for instance, to use the ts-jest preset. * Add a note to the docs about configuring `ts-jest` * Adjust example project to use ts-jest
1 parent 6befa68 commit ebc0ff0

File tree

6 files changed

+91
-17
lines changed

6 files changed

+91
-17
lines changed

docs/introduction/getting-started.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ Below you can find an example config (can also be found in the [example app](htt
3636
}
3737
```
3838

39+
You'll also need to add the `ts-jest` preset to your Jest config if you plan to
40+
write your tests in Typescript:
41+
42+
```bash npm2yarn
43+
npm install --save-dev ts-jest
44+
ts-jest config:init
45+
```
46+
3947
### Add tests
4048

4149
Use the [takeScreenshot](/docs/api/methods#takescreenshotname-string) and [.toMatchBaseline](/docs/api/matchers#tomatchbaselinename-string) apis to implement screenshot tests. File names must end in `.owl.ts`, `.owl.tsx`, `.owl.js` or `.owl.jsx`. [See the example app](https://github.com/FormidableLabs/react-native-owl/tree/main/example) for a more complete example.

example/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
},
1717
"dependencies": {
1818
"react": "18.2.0",
19-
"react-native": "0.71.7"
19+
"react-native": "0.71.7",
20+
"ts-jest": "^29.1.2"
2021
},
2122
"devDependencies": {
2223
"@babel/core": "^7.20.0",
@@ -37,6 +38,6 @@
3738
"typescript": "4.8.4"
3839
},
3940
"jest": {
40-
"preset": "react-native"
41+
"preset": "ts-jest"
4142
}
4243
}

example/yarn.lock

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,13 @@
12971297
dependencies:
12981298
"@sinclair/typebox" "^0.25.16"
12991299

1300+
"@jest/schemas@^29.6.3":
1301+
version "29.6.3"
1302+
resolved "https://registry.yarnpkg.com/@jest/schemas/-/schemas-29.6.3.tgz#430b5ce8a4e0044a7e3819663305a7b3091c8e03"
1303+
integrity sha512-mo5j5X+jIZmJQveBKeS/clAueipV7KgiX1vMgCxam1RNYiqE1w62n0/tJJnHtjW8ZHcQco5gY85jA3mi0L+nSA==
1304+
dependencies:
1305+
"@sinclair/typebox" "^0.27.8"
1306+
13001307
"@jest/source-map@^27.5.1":
13011308
version "27.5.1"
13021309
resolved "https://registry.yarnpkg.com/@jest/source-map/-/source-map-27.5.1.tgz#6608391e465add4205eae073b55e7f279e04e8cf"
@@ -1402,6 +1409,18 @@
14021409
"@types/yargs" "^17.0.8"
14031410
chalk "^4.0.0"
14041411

1412+
"@jest/types@^29.6.3":
1413+
version "29.6.3"
1414+
resolved "https://registry.yarnpkg.com/@jest/types/-/types-29.6.3.tgz#1131f8cf634e7e84c5e77bab12f052af585fba59"
1415+
integrity sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==
1416+
dependencies:
1417+
"@jest/schemas" "^29.6.3"
1418+
"@types/istanbul-lib-coverage" "^2.0.0"
1419+
"@types/istanbul-reports" "^3.0.0"
1420+
"@types/node" "*"
1421+
"@types/yargs" "^17.0.8"
1422+
chalk "^4.0.0"
1423+
14051424
"@jridgewell/gen-mapping@^0.3.0", "@jridgewell/gen-mapping@^0.3.2":
14061425
version "0.3.3"
14071426
resolved "https://registry.yarnpkg.com/@jridgewell/gen-mapping/-/gen-mapping-0.3.3.tgz#7e02e6eb5df901aaedb08514203b096614024098"
@@ -1698,6 +1717,11 @@
16981717
resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.25.24.tgz#8c7688559979f7079aacaf31aa881c3aa410b718"
16991718
integrity sha512-XJfwUVUKDHF5ugKwIcxEgc9k8b7HbznCp6eUfWgu710hMPNIO4aw4/zB5RogDQz8nd6gyCDpU9O/m6qYEWY6yQ==
17001719

1720+
"@sinclair/typebox@^0.27.8":
1721+
version "0.27.8"
1722+
resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.27.8.tgz#6667fac16c436b5434a387a34dedb013198f6e6e"
1723+
integrity sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==
1724+
17011725
"@sinonjs/commons@^1.7.0":
17021726
version "1.8.6"
17031727
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.8.6.tgz#80c516a4dc264c2a69115e7578d62581ff455ed9"
@@ -2468,6 +2492,13 @@ browserslist@^4.21.3, browserslist@^4.21.5:
24682492
node-releases "^2.0.8"
24692493
update-browserslist-db "^1.0.10"
24702494

2495+
bs-logger@0.x:
2496+
version "0.2.6"
2497+
resolved "https://registry.yarnpkg.com/bs-logger/-/bs-logger-0.2.6.tgz#eb7d365307a72cf974cc6cda76b68354ad336bd8"
2498+
integrity sha512-pd8DCoxmbgc7hyPKOvxtqNcjYoOsABPQdcCUjGp3d42VR2CX1ORhk2A87oqqu5R1kk+76nsxZupkmyd+MVtCog==
2499+
dependencies:
2500+
fast-json-stable-stringify "2.x"
2501+
24712502
bser@2.1.1:
24722503
version "2.1.1"
24732504
resolved "https://registry.yarnpkg.com/bser/-/bser-2.1.1.tgz#e6787da20ece9d07998533cfd9de6f5c38f4bc05"
@@ -3502,7 +3533,7 @@ fast-glob@^3.2.9:
35023533
merge2 "^1.3.0"
35033534
micromatch "^4.0.4"
35043535

3505-
fast-json-stable-stringify@^2.0.0, fast-json-stable-stringify@^2.1.0:
3536+
fast-json-stable-stringify@2.x, fast-json-stable-stringify@^2.0.0, fast-json-stable-stringify@^2.1.0:
35063537
version "2.1.0"
35073538
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz#874bf69c6f404c2b5d99c481341399fd55892633"
35083539
integrity sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==
@@ -4840,6 +4871,18 @@ jest-util@^27.2.0, jest-util@^27.5.1:
48404871
graceful-fs "^4.2.9"
48414872
picomatch "^2.2.3"
48424873

4874+
jest-util@^29.0.0:
4875+
version "29.7.0"
4876+
resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-29.7.0.tgz#23c2b62bfb22be82b44de98055802ff3710fc0bc"
4877+
integrity sha512-z6EbKajIpqGKU56y5KBUgy1dt1ihhQJgWzUlZHArA/+X2ad7Cb5iF+AK1EWVL/Bo7Rz9uurpqw6SiBCefUbCGA==
4878+
dependencies:
4879+
"@jest/types" "^29.6.3"
4880+
"@types/node" "*"
4881+
chalk "^4.0.0"
4882+
ci-info "^3.2.0"
4883+
graceful-fs "^4.2.9"
4884+
picomatch "^2.2.3"
4885+
48434886
jest-util@^29.5.0:
48444887
version "29.5.0"
48454888
resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-29.5.0.tgz#24a4d3d92fc39ce90425311b23c27a6e0ef16b8f"
@@ -5051,7 +5094,7 @@ json-stable-stringify-without-jsonify@^1.0.1:
50515094
resolved "https://registry.yarnpkg.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651"
50525095
integrity sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==
50535096

5054-
json5@^2.2.2:
5097+
json5@^2.2.2, json5@^2.2.3:
50555098
version "2.2.3"
50565099
resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.3.tgz#78cd6f1a19bdc12b73db5ad0c61efd66c1e29283"
50575100
integrity sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==
@@ -5153,6 +5196,11 @@ lodash.debounce@^4.0.8:
51535196
resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af"
51545197
integrity sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==
51555198

5199+
lodash.memoize@4.x:
5200+
version "4.1.2"
5201+
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
5202+
integrity sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag==
5203+
51565204
lodash.merge@^4.6.2:
51575205
version "4.6.2"
51585206
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a"
@@ -5221,6 +5269,11 @@ make-dir@^3.0.0:
52215269
dependencies:
52225270
semver "^6.0.0"
52235271

5272+
make-error@1.x:
5273+
version "1.3.6"
5274+
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
5275+
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==
5276+
52245277
makeerror@1.0.12:
52255278
version "1.0.12"
52265279
resolved "https://registry.yarnpkg.com/makeerror/-/makeerror-1.0.12.tgz#3e5dd2079a82e812e983cc6610c4a2cb0eaa801a"
@@ -6582,6 +6635,13 @@ semver@^7.3.2, semver@^7.3.7:
65826635
dependencies:
65836636
lru-cache "^6.0.0"
65846637

6638+
semver@^7.5.3:
6639+
version "7.6.0"
6640+
resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.0.tgz#1a46a4db4bffcccd97b743b5005c8325f23d4e2d"
6641+
integrity sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==
6642+
dependencies:
6643+
lru-cache "^6.0.0"
6644+
65856645
send@0.18.0:
65866646
version "0.18.0"
65876647
resolved "https://registry.yarnpkg.com/send/-/send-0.18.0.tgz#670167cc654b05f5aa4a767f9113bb371bc706be"
@@ -7117,6 +7177,20 @@ tr46@~0.0.3:
71177177
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
71187178
integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==
71197179

7180+
ts-jest@^29.1.2:
7181+
version "29.1.2"
7182+
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-29.1.2.tgz#7613d8c81c43c8cb312c6904027257e814c40e09"
7183+
integrity sha512-br6GJoH/WUX4pu7FbZXuWGKGNDuU7b8Uj77g/Sp7puZV6EXzuByl6JrECvm0MzVzSTkSHWTihsXt+5XYER5b+g==
7184+
dependencies:
7185+
bs-logger "0.x"
7186+
fast-json-stable-stringify "2.x"
7187+
jest-util "^29.0.0"
7188+
json5 "^2.2.3"
7189+
lodash.memoize "4.x"
7190+
make-error "1.x"
7191+
semver "^7.5.3"
7192+
yargs-parser "^21.0.1"
7193+
71207194
tslib@^1.8.1:
71217195
version "1.14.1"
71227196
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
@@ -7579,7 +7653,7 @@ yargs-parser@^20.2.2:
75797653
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.9.tgz#2eb7dc3b0289718fc295f362753845c41a0c94ee"
75807654
integrity sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==
75817655

7582-
yargs-parser@^21.1.1:
7656+
yargs-parser@^21.0.1, yargs-parser@^21.1.1:
75837657
version "21.1.1"
75847658
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-21.1.1.tgz#9096bceebf990d21bb31fa9516e0ede294a77d35"
75857659
integrity sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==

lib/cli/run.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,7 @@ describe('run.ts', () => {
149149
},
150150
};
151151

152-
const jestConfigPath = path.join(__dirname, '..', 'jest-config.json');
153-
154-
const expectedJestCommand = `jest --config=${jestConfigPath} --roots=${path.join(
152+
const expectedJestCommand = `jest --testMatch="**/?(*.)+(owl).[jt]s?(x)" --verbose --roots=${path.join(
155153
process.cwd()
156154
)} --runInBand`;
157155

lib/cli/run.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ export const runHandler = async (args: CliRunOptions) => {
114114

115115
await runProject(config);
116116

117-
const jestConfigPath = path.join(__dirname, '..', 'jest-config.json');
118117
const jestCommandArgs = [
119118
'jest',
120-
`--config=${jestConfigPath}`,
119+
`--testMatch="**/?(*.)+(owl).[jt]s?(x)"`,
120+
'--verbose',
121121
`--roots=${cwd}`,
122122
'--runInBand',
123123
`--globals='${JSON.stringify({ OWL_CLI_ARGS: args })}'`,
@@ -142,9 +142,6 @@ export const runHandler = async (args: CliRunOptions) => {
142142
}.`
143143
);
144144

145-
logger.info(
146-
`[OWL - CLI] Will use the jest config localed at ${jestConfigPath}.`
147-
);
148145
logger.info(`[OWL - CLI] Will set the jest root to ${process.cwd()}.`);
149146

150147
try {

lib/jest-config.json

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

0 commit comments

Comments
 (0)