diff --git a/.travis.yml b/.travis.yml index 11fec8b3cb..625c0d2de4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,25 +14,25 @@ matrix: fast_finish: true include: - node_js: '9' - env: TARGET=test-node COVERAGE=true + env: TARGET=test.node COVERAGE=true - node_js: '8' - env: TARGET=test-node + env: TARGET=test.node - node_js: '6' - env: TARGET=test-node + env: TARGET=test.node - node_js: '4' - env: TARGET=test-node + env: TARGET=test.node - node_js: '8' env: TARGET=lint - node_js: '8' - env: TARGET=test-browser + env: TARGET=test.browser before_install: scripts/travis-before-install.sh before_script: scripts/travis-before-script.sh -script: make $TARGET +script: npm start $TARGET -after_success: npm run coveralls +after_success: npm start coveralls notifications: email: false diff --git a/Makefile b/Makefile deleted file mode 100644 index 5071e1b639..0000000000 --- a/Makefile +++ /dev/null @@ -1,172 +0,0 @@ -BROWSERIFY := "node_modules/.bin/browserify" -KARMA := "node_modules/.bin/karma" -MOCHA := "bin/mocha" -NYC := "node_modules/.bin/nyc" - -ifdef COVERAGE -define test_node -$(NYC) --no-clean --report-dir coverage/reports/$(1) $(MOCHA) -endef -else -test_node := $(MOCHA) -endif - -TM_BUNDLE = JavaScript\ mocha.tmbundle -SRC = $(shell find lib -name "*.js" -type f | LC_ALL=C sort) -TESTS = $(shell find test -name "*.js" -type f | sort) - -all: mocha.js - -mocha.js: $(SRC) browser-entry.js - @printf "==> [Browser :: build]\n" - mkdir -p ${@D} - $(BROWSERIFY) ./browser-entry \ - --plugin ./scripts/dedefine \ - --ignore 'fs' \ - --ignore 'glob' \ - --ignore 'path' \ - --ignore 'supports-color' > $@ - -clean: - @printf "==> [Clean]\n" - rm -f mocha.js - -lint: - @printf "==> [Test :: Lint]\n" - npm run lint - npm run markdownlint - -test-node: test-bdd test-tdd test-qunit test-exports test-unit test-integration test-jsapi test-compilers test-requires test-reporters test-only test-global-only - -test-browser: clean mocha.js test-browser-unit test-browser-bdd test-browser-qunit test-browser-tdd test-browser-esm - -test: lint test-node test-browser - -test-browser-unit: - @printf "==> [Test :: Browser]\n" - NODE_PATH=. $(KARMA) start --single-run - -test-browser-bdd: - @printf "==> [Test :: Browser :: BDD]\n" - MOCHA_TEST=bdd $(MAKE) test-browser-unit - -test-browser-qunit: - @printf "==> [Test :: Browser :: QUnit]\n" - MOCHA_TEST=qunit $(MAKE) test-browser-unit - -test-browser-tdd: - @printf "==> [Test :: Browser :: TDD]\n" - MOCHA_TEST=tdd $(MAKE) test-browser-unit - -test-browser-esm: - @printf "==> [Test :: Browser :: ESM]\n" - MOCHA_TEST=esm $(MAKE) test-browser-unit - -test-jsapi: - @printf "==> [Test :: JS API]\n" - node test/jsapi - -test-unit: - @printf "==> [Test :: Unit]\n" - $(call test_node,unit) test/unit/*.spec.js \ - test/node-unit/*.spec.js \ - --growl - -test-integration: - @printf "==> [Test :: Integrations]\n" - $(call test_node,integration) --timeout 5000 --slow 500 \ - test/integration/*.spec.js - -test-compilers: - @printf "==> [Test :: Compilers]\n" - $(call test_node,compilers-coffee) --compilers coffee:coffee-script/register \ - test/compiler - - $(call test_node,compilers-custom) \ - --compilers foo:./test/compiler-fixtures/foo.fixture \ - test/compiler - - $(call test_node,compilers-multiple) \ - --compilers coffee:coffee-script/register,foo:./test/compiler-fixtures/foo.fixture \ - test/compiler - -test-requires: - @printf "==> [Test :: Requires]\n" - $(call test_node,requires) --compilers coffee:coffee-script/register \ - --require test/require/a.js \ - --require test/require/b.coffee \ - --require test/require/c.js \ - --require test/require/d.coffee \ - test/require/require.spec.js - -test-bdd: - @printf "==> [Test :: BDD]\n" - $(call test_node,bdd) --ui bdd \ - test/interfaces/bdd.spec - -test-tdd: - @printf "==> [Test :: TDD]\n" - $(call test_node,tdd) --ui tdd \ - test/interfaces/tdd.spec - -test-qunit: - @printf "==> [Test :: QUnit]\n" - $(call test_node,qunit) --ui qunit \ - test/interfaces/qunit.spec - -test-exports: - @printf "==> [Test :: Exports]\n" - $(call test_node,exports) --ui exports \ - test/interfaces/exports.spec - -test-reporters: - @printf "==> [Test :: Reporters]\n" - $(call test_node,reporters) test/reporters/*.spec.js - -test-only: - @printf "==> [Test :: Only]\n" - $(call test_node,only-tdd) --ui tdd \ - test/only/tdd.spec - - $(call test_node,only-bdd) --ui bdd \ - test/only/bdd.spec - - $(call test_node,only-bdd-require) --ui qunit \ - test/only/bdd-require.spec - -test-global-only: - @printf "==> [Test :: Global Only]\n" - $(call test_node,global-only-tdd) --ui tdd \ - test/only/global/tdd.spec - - $(call test_node,global-only-bdd) --ui bdd \ - test/only/global/bdd.spec - - $(call test_node,global-only-qunit) --ui qunit \ - test/only/global/qunit.spec - -test-mocha: - @printf "==> [Test :: Mocha]\n" - $(call test_node,mocha) test/mocha - -non-tty: - @printf "==> [Test :: Non-TTY]\n" - $(call test_node,non-tty-dot) --reporter dot \ - test/interfaces/bdd.spec 2>&1 > /tmp/dot.out - - @echo dot: - @cat /tmp/dot.out - - $(call test_node,non-tty-list) --reporter list \ - test/interfaces/bdd.spec 2>&1 > /tmp/list.out - - @echo list: - @cat /tmp/list.out - - $(call test_node,non-tty-spec) --reporter spec \ - test/interfaces/bdd.spec 2>&1 > /tmp/spec.out - - @echo spec: - @cat /tmp/spec.out - -.PHONY: test-jsapi test-compilers watch test test-node test-bdd test-tdd test-qunit test-exports test-unit test-integration non-tty tm clean test-browser test-browser-unit test-browser-bdd test-browser-qunit test-browser-tdd test-browser-exports lint test-only test-global-only diff --git a/appveyor.yml b/appveyor.yml index 1583df4d0d..3708cd8691 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -12,7 +12,6 @@ install: - set PATH=%APPDATA%\npm;c:\MinGW\bin;%PATH% - npm install -g npm - npm install - - copy c:\MinGW\bin\mingw32-make.exe c:\MinGW\bin\make.exe matrix: fast_finish: true build: off @@ -22,7 +21,7 @@ clone_depth: 1 test_script: - node --version - npm --version - - make test-node + - npm start test.node skip_commits: message: /\[ci\s+skip\]/ diff --git a/netlify.toml b/netlify.toml index 1683cf27b1..bef8d91e1d 100644 --- a/netlify.toml +++ b/netlify.toml @@ -10,4 +10,4 @@ [build] publish = "docs/_dist/" - command = "npm run buildDocs" + command = "npm start buildDocs" diff --git a/package-scripts.js b/package-scripts.js new file mode 100644 index 0000000000..7aa256d231 --- /dev/null +++ b/package-scripts.js @@ -0,0 +1,226 @@ +'use strict'; + +const path = require('path'); + +/** + * Generates a command to run mocha tests with or without test coverage + * as desired for the current runmode. + * @param {string} testName The name of the test to be used for coverage reporting. + * @param {string} mochaParams Parameters for the mocha CLI to execute the desired test. + * @returns {string} Command string to be executed by nps. + */ +function test (testName, mochaParams) { + const coverageCommand = `nyc --no-clean --report-dir coverage/reports/${testName}`; + const mochaCommand = `node ${path.join('bin', 'mocha')}`; // Include 'node' and path.join for Windows compatibility + return `${process.env.COVERAGE ? coverageCommand : ''} ${mochaCommand} ${mochaParams}`.trim(); +} + +module.exports = { + scripts: { + build: `browserify ./browser-entry --plugin ./scripts/dedefine --ignore 'fs' --ignore 'glob' --ignore 'path' --ignore 'supports-color' > mocha.js`, + lint: { + default: 'nps lint.all', + all: { + script: 'nps lint.code lint.markdown', + description: 'Lint code and markdown' + }, + code: { + script: 'eslint . "bin/*"', + description: 'Run eslint on mocha JS code' + }, + markdown: { + script: 'markdownlint "*.md" "docs/**/*.md" ".github/*.md"', + description: 'Lint Markdown files' + } + }, + clean: { + script: 'rm -f mocha.js', + description: 'Delete mocha.js build artifact' + }, + test: { + default: 'nps test.all', + all: { + script: 'nps lint.code test.node test.browser', + description: 'Lint code and runs node / browser environment tests' + }, + node: { + default: 'nps test.node.all', + all: { + script: `nps ${[ + 'test.node.bdd', + 'test.node.tdd', + 'test.node.qunit', + 'test.node.exports', + 'test.node.unit', + 'test.node.integration', + 'test.node.jsapi', + 'test.node.compilers', + 'test.node.requires', + 'test.node.reporters', + 'test.node.only' + ].join(' ')}`, + description: 'Run all tests for node environment' + }, + bdd: { + script: test('bdd', '--ui bdd test/interfaces/bdd.spec'), + description: 'Test Node BDD interface' + }, + tdd: { + script: test('tdd', '--ui tdd test/interfaces/tdd.spec'), + description: 'Test Node TDD interface' + }, + qunit: { + script: test('qunit', '--ui qunit test/interfaces/qunit.spec'), + description: 'Test Node QUnit interace' + }, + exports: { + script: test('exports', '--ui exports test/interfaces/exports.spec'), + description: 'Test Node exports interface' + }, + unit: { + script: test('unit', '"test/unit/*.spec.js" "test/node-unit/*.spec.js" --growl'), + description: 'Run Node unit tests' + }, + integration: { + script: test('integration', '--timeout 5000 --slow 500 "test/integration/*.spec.js"'), + description: 'Run Node integration tests' + }, + jsapi: { + script: 'node test/jsapi', + description: 'Test Mocha JavaScript API' + }, + compilers: { + default: 'nps test.node.compilers.all', + all: { + script: 'nps test.node.compilers.coffee test.node.compilers.custom test.node.compilers.multiple', + description: 'Test deprecated --compilers flag' + }, + coffee: { + script: test('compilers-coffee', '--compilers coffee:coffee-script/register test/compiler'), + description: 'Run coffeescript compiler tests using deprecated --compilers flag' + }, + custom: { + script: test('compilers-custom', '--compilers foo:./test/compiler-fixtures/foo.fixture test/compiler'), + description: 'Run custom compiler test using deprecated --compilers flag' + }, + multiple: { + script: test('compilers-multiple', '--compilers coffee:coffee-script/register,foo:./test/compiler-fixtures/foo.fixture test/compiler'), + description: 'Test deprecated --compilers flag using multiple compilers' + } + }, + requires: { + script: test('requires', ['--require coffee-script/register', + '--require test/require/a.js', + '--require test/require/b.coffee', + '--require test/require/c.js', + '--require test/require/d.coffee', + 'test/require/require.spec.js'].join(' ')), + description: 'Test --require flag' + }, + reporters: { + script: test('reporters', '"test/reporters/*.spec.js"'), + description: 'Test reporters' + }, + only: { + default: 'nps test.node.only.all', + all: { + script: `nps ${[ + 'test.node.only.bdd', + 'test.node.only.tdd', + 'test.node.only.bddRequire', + 'test.node.only.globalBdd', + 'test.node.only.globalTdd', + 'test.node.only.globalQunit' + ].join(' ')} `, + description: 'Run all tests for .only()' + }, + bdd: { + script: test('only-bdd', '--ui bdd test/only/bdd.spec'), + description: 'Test .only() with BDD interface' + }, + tdd: { + script: test('only-tdd', '--ui tdd test/only/tdd.spec'), + description: 'Test .only() with TDD interface' + }, + bddRequire: { + script: test('only-bdd-require', '--ui qunit test/only/bdd-require.spec'), + description: 'Test .only() with require("mocha") interface' + }, + globalBdd: { + script: test('global-only-bdd', '--ui bdd test/only/global/bdd.spec'), + description: 'Test .only() in root suite with BDD interface' + }, + globalTdd: { + script: test('global-only-tdd', '--ui tdd test/only/global/tdd.spec'), + description: 'Test .only() in root suite with TDD interface' + }, + globalQunit: { + script: test('global-only-qunit', '--ui qunit test/only/global/qunit.spec'), + description: 'Test .only() in root suite with QUnit interface' + } + } + }, + browser: { + default: 'nps test.browser.all', + all: { + script: 'nps clean build.mochajs test.browser.unit test.browser.bdd test.browser.tdd test.browser.qunit test.browser.esm', + description: 'Compile Mocha and run all tests in browser environment' + }, + unit: { + script: 'NODE_PATH=. karma start --single-run', + description: 'Run unit tests for Mocha in browser' + }, + bdd: { + script: 'MOCHA_TEST=bdd nps test.browser.unit', + description: 'Test BDD interface in browser' + }, + tdd: { + script: 'MOCHA_TEST=tdd nps test.browser.unit', + description: 'Test TDD interface in browser' + }, + qunit: { + script: 'MOCHA_TEST=qunit nps test.browser.unit', + description: 'Test QUnit interface in browser' + }, + esm: { + script: 'MOCHA_TEST=esm nps test.browser.unit', + description: 'Test mocha ESM support' + } + }, + nonTTY: { + default: 'nps test.nonTTY.all', + all: { + script: 'nps test.nonTTY.dot test.nonTTY.list test.nonTTY.spec', + description: 'Run all tests for non-TTY terminals' + }, + dot: { + script: test('non-tty-dot', '--reporter dot test/interfaces/bdd.spec 2>&1 > /tmp/dot.out && echo "dot:" && cat /tmp/dot.out'), + description: 'Test non-TTY dot reporter' + }, + list: { + script: test('non-tty-list', '--reporter list test/interfaces/bdd.spec 2>&1 > /tmp/list.out && echo "list:" && cat /tmp/list.out'), + description: 'Test non-TTY list reporter' + }, + spec: { + script: test('non-tty-dot', '--reporter spec test/interfaces/bdd.spec 2>&1 > /tmp/spec.out && echo "spec:" && cat /tmp/spec.out'), + description: 'Test non-TTY spec reporter' + } + } + }, + coveralls: { + script: 'nyc report --reporter=text-lcov | coveralls', + description: 'Send code coverage report to coveralls (run during CI)' + }, + prebuildDocs: 'rm -rf docs/_dist && node scripts/docs-update-toc.js', + buildDocs: { + script: 'nps prebuildDocs && bundle exec jekyll build --source ./docs --destination ./docs/_site --config ./docs/_config.yml --safe --drafts && nps postbuildDocs', + description: 'Build documentation' + }, + postbuildDocs: 'buildProduction docs/_site/index.html --outroot docs/_dist --canonicalroot https://mochajs.org/ --optimizeimages --svgo --inlinehtmlimage 9400 --inlinehtmlscript 0 --asyncscripts && cp docs/_headers docs/_dist/_headers && node scripts/netlify-headers.js >> docs/_dist/_headers', + prewatchDocs: 'node scripts/docs-update-toc.js', + watchDocs: { + script: 'nps prewatchDocs && bundle exec jekyll serve --source ./docs --destination ./docs/_site --config ./docs/_config.yml --safe --drafts --watch', + description: 'Watch documentation for changes' + } + } +}; diff --git a/package.json b/package.json index 7a9ec8d5b5..3bf0e2f0a9 100644 --- a/package.json +++ b/package.json @@ -300,16 +300,9 @@ "node": ">= 4.0.0" }, "scripts": { - "lint": "eslint . bin/*", - "markdownlint": "markdownlint \"*.md\" \"docs/**/*.md\" \".github/*.md\"", - "test": "make clean && make test", - "prepublishOnly": "npm test && make clean && make mocha.js", - "coveralls": "nyc report --reporter=text-lcov | coveralls", - "prebuildDocs": "rm -rf docs/_dist && node scripts/docs-update-toc.js", - "buildDocs": "bundle exec jekyll build --source ./docs --destination ./docs/_site --config ./docs/_config.yml --safe --drafts", - "postbuildDocs": "buildProduction docs/_site/index.html --outroot docs/_dist --canonicalroot https://mochajs.org/ --optimizeimages --svgo --inlinehtmlimage 9400 --inlinehtmlscript 0 --asyncscripts && cp docs/_headers docs/_dist/_headers && node scripts/netlify-headers.js >> docs/_dist/_headers", - "prewatchDocs": "node scripts/docs-update-toc.js", - "watchDocs": "bundle exec jekyll serve --source ./docs --destination ./docs/_site --config ./docs/_config.yml --safe --drafts --watch" + "prepublishOnly": "nps test clean build", + "start": "nps", + "test": "nps test" }, "dependencies": { "browser-stdout": "1.3.0", @@ -347,6 +340,7 @@ "karma-sauce-launcher": "^1.2.0", "markdown-toc": "^1.2.0", "markdownlint-cli": "^0.6.0", + "nps": "^5.7.1", "nyc": "^11.2.1", "rimraf": "^2.5.2", "svgo": "^0.7.2", diff --git a/scripts/travis-before-script.sh b/scripts/travis-before-script.sh index ef097cef28..19ebc4b13b 100755 --- a/scripts/travis-before-script.sh +++ b/scripts/travis-before-script.sh @@ -4,4 +4,4 @@ mkdir -p .karma # ensure we are building a non-broken bundle for AMD -make mocha.js && [[ -z "$(grep 'define.amd' mocha.js)" ]] || exit 1 +npm start build.mochajs && [[ -z "$(grep 'define.amd' mocha.js)" ]] || exit 1