diff --git a/.shellcheckrc b/.shellcheckrc new file mode 100644 index 00000000..e69de29b diff --git a/package-lock.json b/package-lock.json index 877a69d4..20569d30 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@mountainpass/waychaser", - "version": "1.3.0", + "version": "1.4.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -15956,6 +15956,11 @@ "integrity": "sha512-mRz/m/JVscCrkMyPqHc/bczi3OQHkLTqXHEFu0zDhK/qfv3UcOA4SVmRCLmos4bhjr9ekVQubj/R7waKapmiQg==", "dev": true }, + "shellcheck": { + "version": "0.4.4", + "resolved": "https://registry.npmjs.org/shellcheck/-/shellcheck-0.4.4.tgz", + "integrity": "sha512-d7LfrgEcGZes825x5Yehm6MkpfSQaDg4nP0VZEv7E2qX84zQXDbCdDvYJg9V9OByG2+h98Ol7nndixgGOj8cRQ==" + }, "side-channel": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.3.tgz", diff --git a/package.json b/package.json index 8d277c06..82dcfded 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", @@ -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": { diff --git a/scripts/cover-all.sh b/scripts/cover-all.sh new file mode 100755 index 00000000..2deb2a55 --- /dev/null +++ b/scripts/cover-all.sh @@ -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 \ No newline at end of file diff --git a/scripts/cover.sh b/scripts/cover.sh new file mode 100755 index 00000000..f362d442 --- /dev/null +++ b/scripts/cover.sh @@ -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}" \ No newline at end of file diff --git a/scripts/for-all-browsers.sh b/scripts/for-all-browsers.sh new file mode 100755 index 00000000..f8c77acb --- /dev/null +++ b/scripts/for-all-browsers.sh @@ -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")" \ No newline at end of file diff --git a/scripts/test-browser.sh b/scripts/test-browser.sh new file mode 100755 index 00000000..b53272ca --- /dev/null +++ b/scripts/test-browser.sh @@ -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}" \ No newline at end of file diff --git a/scripts/test-node.sh b/scripts/test-node.sh new file mode 100755 index 00000000..058e56cc --- /dev/null +++ b/scripts/test-node.sh @@ -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}" \ No newline at end of file diff --git a/src/test/config.js b/src/test/config.js index 652ddad8..9b026980 100644 --- a/src/test/config.js +++ b/src/test/config.js @@ -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' +);