Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dev-tools) test command improvements #464

Merged
merged 3 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ jobs:
- name: Run tests
run: |
npm run lint
npm run test cover
npm run cover

- name: Coveralls
if: matrix.node-version == 12
if: matrix.node-version == 18
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions modules/dev-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"prettier-check": "2.0.0",
"tape": "^4.11.0",
"tape-promise": "^4.0.0",
"tap-spec": "^5.0.0",
"typescript": "^5.2.2",
"ts-node": "~10.9.0",
"ts-patch": "^3.1.2",
Expand Down
58 changes: 29 additions & 29 deletions modules/dev-tools/scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ BASEDIR=$(dirname "$0")

MODE=$1

MODULE_DIR=$(dirname $0)/..
TEST_SCRIPT=$MODULE_DIR/dist/test.js
DEV_TOOLS_DIR=$(dirname $0)/..
TEST_SCRIPT=$DEV_TOOLS_DIR/dist/test.js
COVERAGE_TEST=`node $DEV_TOOLS_DIR/dist/helpers/get-config.js ".coverage.test"`

usage() {
# TODO: Add more specific url
Expand All @@ -19,10 +20,18 @@ run_test_script() {
(set -x; NODE_ENV=test node $TEST_SCRIPT $1)
}

run_test_script_pretty() {
run_test_script $1 | tap-spec
}

generate_coverage_report() {
(set -x; npx c8 report --reporter=text --reporter=lcov)
}

run_full_test() {
npm run lint
run_test_script node
run_test_script browser-headless
run_test_script_pretty node
run_test_script_pretty browser-headless
ocular-metrics
}

Expand All @@ -39,11 +48,11 @@ case $MODE in

"fast")
ocular-lint pre-commit
run_test_script node
run_test_script_pretty node
;;

"node")
run_test_script $MODE
run_test_script_pretty node
;;

"node-debug")
Expand All @@ -52,43 +61,34 @@ case $MODE in
;;

"dist")
run_test_script dist
run_test_script_pretty dist
;;

"cover")
run_test_script cover
(set -x; npx c8 report --reporter=lcov)
run_test_script_pretty cover
generate_coverage_report
;;

"ci")
# run by Travis CI
# run by CI
npm run lint
run_test_script browser-headless
ocular-test cover
# node test/start.js bench
# ocular-metrics
;;

"browser")
run_test_script $MODE
if [ "$COVERAGE_TEST" == "browser" ]; then
run_test_script_pretty node
else
run_test_script_pretty browser-headless
fi
run_test_script_pretty cover
generate_coverage_report
ocular-metrics
;;

"browser-headless")
run_test_script $MODE
;;

"bench")
run_test_script $MODE
;;

"bench-browser")
run_test_script $MODE
run_test_script_pretty browser-headless
;;

*)
# default test
# echo "Error: unknown test mode $MODE"
# usage()
run_test_script $MODE
;;

esac
9 changes: 1 addition & 8 deletions modules/dev-tools/src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ console.log(`Running ${mode} tests...`); // eslint-disable-line
switch (mode) {
case 'cover':
if (ocularConfig.coverage.test === 'node') {
runNodeTest(resolveNodeEntry('test'), 'npx c8');
runNodeTest(resolveNodeEntry('test'), 'npx c8 --reporter=none');
} else {
await runBrowserTest({
server: {
Expand Down Expand Up @@ -48,10 +48,6 @@ switch (mode) {
runNodeTest(resolveNodeEntry('test')); // Run the tests
break;

case 'bench':
runNodeTest(resolveNodeEntry('bench')); // Run the benchmarks
break;

case 'browser':
case 'browser-headless':
await runBrowserTest({
Expand Down Expand Up @@ -190,9 +186,6 @@ function writeCoverage(coverage) {
'utf8'
);
}

// Print coverage to console
execShellCommand('npx c8 report --reporter=text');
}

function sourcemapFromDataUrl(url: string): string | null {
Expand Down
Loading
Loading