Skip to content

Commit

Permalink
chore: refactor cypress startup to js script
Browse files Browse the repository at this point in the history
because npm does not support command substitution on windows
ref  https://github.com/kentcdodds/cross-env/issues/192\#issuecomment-513341729
  • Loading branch information
Xiphe committed Oct 10, 2020
1 parent 67ae858 commit 759285a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 240 deletions.
237 changes: 3 additions & 234 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
"@types/react": "^16.9.0",
"@types/react-dom": "^16.9.0",
"concurrently": "5.3.0",
"cross-env": "7.0.2",
"cypress": "5.3.0",
"get-port-cli": "2.0.0",
"get-port": "5.1.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.3",
Expand All @@ -23,11 +22,9 @@
},
"scripts": {
"start": "react-scripts start",
"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",
"test": "./scripts/startCypress.js",
"build": "react-scripts build",
"test:jest": "react-scripts test",
"start:cypress": "npm run wait:server && cross-env CYPRESS_BASE_URL=http://localhost:$PORT cypress open",
"wait:server": "wait-on http://localhost:$PORT"
"test:jest": "react-scripts test"
},
"eslintConfig": {
"extends": "react-app"
Expand Down
46 changes: 46 additions & 0 deletions scripts/startCypress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env node

const getPort = require('get-port');
const concurrently = require('concurrently');

(async () => {
const PORT = await getPort({ port: 8765 });
const CYPRESS_BASE_URL = `http://localhost:${PORT}`;

return concurrently(
[
{
name: 'app',
command: 'npx --no-install react-scripts start',
env: {
BROWSER: 'none',
PORT,
REACT_APP_ENV: 'test',
...process.env,
},
},
{
name: 'cypress',
command: `npx --no-install wait-on ${CYPRESS_BASE_URL} && npx --no-install cypress open`,
env: {
CYPRESS_BASE_URL,
...process.env,
},
},
],
{
killOthers: ['failure', 'success'],
},
);
})().catch((err) => {
if (
Array.isArray(err) &&
!err.some(({ exitCode }) => ![0, 'SIGTERM'].includes(exitCode))
) {
process.exit(0);
return;
}

console.error(err);
process.exit(err.exitCode || 1);
});

0 comments on commit 759285a

Please sign in to comment.