Skip to content

Commit 1f8e451

Browse files
committed
Add a script that makes running jest on windows easier
1 parent 0282ee8 commit 1f8e451

File tree

4 files changed

+30
-1079
lines changed

4 files changed

+30
-1079
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
"eslint": "eslint src",
5151
"format": "prettier --write \"src/**/*.{ts,tsx}\"",
5252
"format:ci": "prettier --list-different \"src/**/*.{ts,tsx}\"",
53-
"test": "jest",
54-
"test-coverage": "jest --coverage",
53+
"test": "node ./scripts/run_jest.mjs",
54+
"test-coverage": "test --coverage",
5555
"docs": "node ./scripts/docs.mjs docs",
5656
"jsdoc": "node ./scripts/docs.mjs",
5757
"autocomplete": "node ./scripts/docs.mjs autocomplete",

scripts/run_jest.mjs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* A script for running jest that automatically handles converting Windows
3+
* style paths to Posix style paths because Jest is fussy about those
4+
*/
5+
import { fork } from 'child_process'
6+
import { Command } from '@commander-js/extra-typings'
7+
import pathlib from 'path'
8+
9+
await new Command()
10+
.argument('[patterns...]', 'Patterns to test')
11+
.allowUnknownOption()
12+
.action(async (patterns, args) => {
13+
const newPatterns = patterns.map(pattern => pattern.split(pathlib.sep).join(pathlib.posix.sep))
14+
15+
const proc = fork('node_modules/jest/bin/jest.js', [
16+
...Object.entries(args),
17+
...newPatterns
18+
])
19+
20+
const code = await new Promise((resolve, reject) => {
21+
proc.on('exit', resolve)
22+
proc.on('error', reject)
23+
})
24+
25+
process.exit(code)
26+
})
27+
.parseAsync()

0 commit comments

Comments
 (0)