Skip to content

Commit

Permalink
refactoring scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
tompahoward committed Oct 30, 2020
1 parent d02ef94 commit 1ed1680
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 18 deletions.
Empty file added .shellcheckrc
Empty file.
7 changes: 6 additions & 1 deletion package-lock.json

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

36 changes: 20 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"config": {
"DEV_UI_PORT": 3000,
"DEV_API_PORT": 9000,
"TEST_BROWSER_PORT": 5000
"TEST_BROWSER_PORT": 5000,
"TEST_API_PORT": 6060
},
"scripts": {
"env": "env",
Expand All @@ -37,28 +38,30 @@
"browser:base": "NODE_ENV=test webpack serve --mode development --devtool inline-source-map --hot",
"browser:dev": "npm run browser:base -- --port ${npm_package_config_DEV_UI_PORT} --env API_PORT=${npm_package_config_DEV_API_PORT} --hot",
"browser:test": "NODE_ENV=test npm run browser:base -- --port ${npm_package_config_TEST_BROWSER_PORT} --env API_PORT=${npm_package_config_TEST_API_PORT} --open=false",
"lint": "eslint",
"lint-fix": "eslint --fix",
"lint:sh": "shellcheck **/*.sh",
"lint:js": "eslint",
"lint:js:fix": "eslint --fix",
"lint": "npm-run-all --sequential ${npm_lifecycle_event}:*",
"pretest:node-api": "npm run build:main",
"test:node-api": "TESTING=${npm_lifecycle_event#test:}; TEST_PROFILE=${TESTING//:/-}; NODE_ENV=test PORT=${npm_package_config_TEST_API_PORT} cucumber-js -p ${TEST_PROFILE}",
"test:browser-api:chrome:local": "TESTING=${npm_lifecycle_event#test:}; TEST_PROFILE=${TESTING//:/-}; NODE_ENV=test PORT=${npm_package_config_TEST_API_PORT} UI_PORT=${npm_package_config_TEST_BROWSER_PORT} start-server-and-test browser:test http://localhost:${npm_package_config_TEST_BROWSER_PORT} \"cucumber-js -p ${TEST_PROFILE}\"",
"test:browser-api:chrome:saucy": "TESTING=${npm_lifecycle_event#test:}; TEST_PROFILE=${TESTING//:/-}; NODE_ENV=test PORT=${npm_package_config_TEST_API_PORT} UI_PORT=${npm_package_config_TEST_BROWSER_PORT} start-server-and-test browser:test http://localhost:${npm_package_config_TEST_BROWSER_PORT} \"cucumber-js -p ${TEST_PROFILE}\"",
"test:browser-api:firefox:local": "TESTING=${npm_lifecycle_event#test:}; TEST_PROFILE=${TESTING//:/-}; NODE_ENV=test PORT=${npm_package_config_TEST_API_PORT} UI_PORT=${npm_package_config_TEST_BROWSER_PORT} start-server-and-test browser:test http://localhost:${npm_package_config_TEST_BROWSER_PORT} \"cucumber-js -p ${TEST_PROFILE}\"",
"test:browser-api:firefox:saucy": "TESTING=${npm_lifecycle_event#test:}; TEST_PROFILE=${TESTING//:/-}; NODE_ENV=test PORT=${npm_package_config_TEST_API_PORT} UI_PORT=${npm_package_config_TEST_BROWSER_PORT} start-server-and-test browser:test http://localhost:${npm_package_config_TEST_BROWSER_PORT} \"cucumber-js -p ${TEST_PROFILE}\"",
"test:browser-api": "npm-run-all --sequential ${npm_lifecycle_event}:*:$([ -z ${CI+x} ] && echo \"local\" || echo \"saucy\")",
"test:node-api": "scripts/test-node.sh",
"test:browser-api:chrome:local": "scripts/test-browser.sh",
"test:browser-api:chrome:saucy": "scripts/test-browser.sh",
"test:browser-api:firefox:local": "scripts/test-browser.sh",
"test:browser-api:firefox:saucy": "scripts/test-browser.sh",
"test:browser-api": "scripts/for-all-browsers.sh",
"test": "npm-run-all --sequential ${npm_lifecycle_event}:*",
"watch:test:node-api": "nodemon -V -x npm -- run ${npm_lifecycle_event#watch:}",
"watch:test:browser-api:chrome:local": "nodemon -V -x npm -- run ${npm_lifecycle_event#watch:}",
"watch:test:browser-api:firefox:local": "nodemon -V -x npm -- run ${npm_lifecycle_event#watch:}",
"watch:test:browser-api": "nodemon -V -x npm -- run ${npm_lifecycle_event#watch:}",
"watch:test": "nodemon -V -x npm -- run ${npm_lifecycle_event#watch:}",
"cover:node-api": "COVERING=${npm_lifecycle_event#cover:}; COVER_NAME=${COVERING//:/-}; nyc --nycrc-path .nycrc-${COVER_NAME}.yml --clean --temp-dir coverage/${COVER_NAME}/.nyc_output --report-dir coverage/${COVER_NAME} npm run test:${COVERING}",
"cover:browser-api:chrome:local": "COVERING=${npm_lifecycle_event#cover:}; COVER_NAME=${COVERING//:/-}; nyc --nycrc-path .nycrc-${COVER_NAME}.yml --clean --temp-dir coverage/${COVER_NAME}/.nyc_output --report-dir coverage/${COVER_NAME} npm run test:${COVERING}",
"cover:browser-api:firefox:local": "COVERING=${npm_lifecycle_event#cover:}; COVER_NAME=${COVERING//:/-}; nyc --nycrc-path .nycrc-${COVER_NAME}.yml --clean --temp-dir coverage/${COVER_NAME}/.nyc_output --report-dir coverage/${COVER_NAME} npm run test:${COVERING}",
"cover:browser-api:chrome:saucy": "COVERING=${npm_lifecycle_event#cover:}; COVER_NAME=${COVERING//:/-}; nyc --nycrc-path .nycrc-${COVER_NAME}.yml --clean --temp-dir coverage/${COVER_NAME}/.nyc_output --report-dir coverage/${COVER_NAME} npm run test:${COVERING}",
"cover:browser-api:firefox:saucy": "COVERING=${npm_lifecycle_event#cover:}; COVER_NAME=${COVERING//:/-}; nyc --nycrc-path .nycrc-${COVER_NAME}.yml --clean --temp-dir coverage/${COVER_NAME}/.nyc_output --report-dir coverage/${COVER_NAME} npm run test:${COVERING}",
"cover:browser-api": "npm-run-all --sequential ${npm_lifecycle_event}:*:$([ -z ${CI+x} ] && echo \"local\" || echo \"saucy\")",
"cover": "rm -rf coverage && npm-run-all --sequential ${npm_lifecycle_event}:* && scripts/merge-coverage.js && nyc report --clean --check-coverage --report-dir coverage/full",
"cover:node-api": "scripts/cover.sh",
"cover:browser-api:chrome:local": "scripts/cover.sh",
"cover:browser-api:chrome:saucy": "scripts/cover.sh",
"cover:browser-api:firefox:local": "scripts/cover.sh",
"cover:browser-api:firefox:saucy": "scripts/cover.sh",
"cover:browser-api": "scripts/for-all-browsers.sh",
"cover": "scripts/cover-all.sh",
"eslint-check": "eslint --print-config src/server/index.js | eslint-config-prettier-check",
"precommit": "lint-staged && npm run test:node-api",
"npm-check-unused": "depcheck",
Expand All @@ -72,6 +75,7 @@
"cross-fetch": "^3.0.4",
"debug": "^4.1.1",
"http-link-header": "^1.0.2",
"shellcheck": "^0.4.4",
"url-polyfill": "^1.1.7"
},
"devDependencies": {
Expand Down
16 changes: 16 additions & 0 deletions scripts/cover-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

: "${npm_lifecycle_event?This script should be run from npm}"

rm -rf coverage
npm-run-all \
--sequential \
"${npm_lifecycle_event}:*"

scripts/merge-coverage.js

nyc \
report \
--clean \
--check-coverage \
--report-dir coverage/full
14 changes: 14 additions & 0 deletions scripts/cover.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

: "${npm_lifecycle_event?This script should be run from npm}"

COVERING=${npm_lifecycle_event#cover:}
COVER_NAME=${COVERING//:/-}

nyc \
--nycrc-path \
".nycrc-${COVER_NAME}.yml" \
--clean \
--temp-dir "coverage/${COVER_NAME}/.nyc_output" \
--report-dir "coverage/${COVER_NAME}" \
npm run "test:${COVERING}"
7 changes: 7 additions & 0 deletions scripts/for-all-browsers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

: "${npm_lifecycle_event?This script should be run from npm}"

npm-run-all \
--sequential \
"${npm_lifecycle_event}:*:$([ -z ${CI+x} ] && echo "local" || echo "saucy")"
16 changes: 16 additions & 0 deletions scripts/test-browser.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

: "${npm_lifecycle_event?This script should be run from npm}"
: "${npm_package_config_TEST_API_PORT?This script should be run from npm}"
: "${npm_package_config_TEST_BROWSER_PORT?This script should be run from npm}"

TESTING="${npm_lifecycle_event#test:}"
TEST_PROFILE="${TESTING//:/-}"

NODE_ENV=test \
PORT=${npm_package_config_TEST_API_PORT} \
UI_PORT=${npm_package_config_TEST_BROWSER_PORT} \
start-server-and-test \
browser:test \
"http://localhost:${npm_package_config_TEST_BROWSER_PORT}" \
"cucumber-js -p ${TEST_PROFILE}"
11 changes: 11 additions & 0 deletions scripts/test-node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

: "${npm_lifecycle_event?This script should be run from npm}"
: "${npm_package_config_TEST_API_PORT?This script should be run from npm}"

TESTING=${npm_lifecycle_event#test:}
TEST_PROFILE=${TESTING//:/-}

NODE_ENV=test \
PORT=${npm_package_config_TEST_API_PORT} \
cucumber-js -p "${TEST_PROFILE}"
5 changes: 4 additions & 1 deletion src/test/config.js
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export var PORT = Number.parseInt(process.env.PORT || '6060');
export var PORT = Number.parseInt(
process.env.PORT ||
/* istanbul ignore next: because it's only unset when the test are configured correctly */ '6060'
);

0 comments on commit 1ed1680

Please sign in to comment.