Skip to content

Commit 759285a

Browse files
committed
chore: refactor cypress startup to js script
because npm does not support command substitution on windows ref https://github.com/kentcdodds/cross-env/issues/192\#issuecomment-513341729
1 parent 67ae858 commit 759285a

File tree

3 files changed

+52
-240
lines changed

3 files changed

+52
-240
lines changed

package-lock.json

+3-234
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-6
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
"@types/react": "^16.9.0",
1313
"@types/react-dom": "^16.9.0",
1414
"concurrently": "5.3.0",
15-
"cross-env": "7.0.2",
1615
"cypress": "5.3.0",
17-
"get-port-cli": "2.0.0",
16+
"get-port": "5.1.1",
1817
"react": "^16.13.1",
1918
"react-dom": "^16.13.1",
2019
"react-scripts": "3.4.3",
@@ -23,11 +22,9 @@
2322
},
2423
"scripts": {
2524
"start": "react-scripts start",
26-
"test": "cross-env BROWSER=none cross-env REACT_APP_ENV=test cross-env PORT=\"$(get-port 8765)\" concurrently -n app,cypress npm:start npm:start:cypress",
25+
"test": "./scripts/startCypress.js",
2726
"build": "react-scripts build",
28-
"test:jest": "react-scripts test",
29-
"start:cypress": "npm run wait:server && cross-env CYPRESS_BASE_URL=http://localhost:$PORT cypress open",
30-
"wait:server": "wait-on http://localhost:$PORT"
27+
"test:jest": "react-scripts test"
3128
},
3229
"eslintConfig": {
3330
"extends": "react-app"

scripts/startCypress.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env node
2+
3+
const getPort = require('get-port');
4+
const concurrently = require('concurrently');
5+
6+
(async () => {
7+
const PORT = await getPort({ port: 8765 });
8+
const CYPRESS_BASE_URL = `http://localhost:${PORT}`;
9+
10+
return concurrently(
11+
[
12+
{
13+
name: 'app',
14+
command: 'npx --no-install react-scripts start',
15+
env: {
16+
BROWSER: 'none',
17+
PORT,
18+
REACT_APP_ENV: 'test',
19+
...process.env,
20+
},
21+
},
22+
{
23+
name: 'cypress',
24+
command: `npx --no-install wait-on ${CYPRESS_BASE_URL} && npx --no-install cypress open`,
25+
env: {
26+
CYPRESS_BASE_URL,
27+
...process.env,
28+
},
29+
},
30+
],
31+
{
32+
killOthers: ['failure', 'success'],
33+
},
34+
);
35+
})().catch((err) => {
36+
if (
37+
Array.isArray(err) &&
38+
!err.some(({ exitCode }) => ![0, 'SIGTERM'].includes(exitCode))
39+
) {
40+
process.exit(0);
41+
return;
42+
}
43+
44+
console.error(err);
45+
process.exit(err.exitCode || 1);
46+
});

0 commit comments

Comments
 (0)