[testing/nodejs] Support gathering coverage data.

- Update istanbul and mocha to their most recent versions. The istanbul
  CLI has been replaced by the nyc CLI. This is required in order to
  exclude tests from test sets and to exclude certain files (closure
  cases) from instrumentation.
- Add support for gathering and reporting coverage data under the
  `PULUMI_TEST_COVERAGE_PATH` environment variable.
This commit is contained in:
Pat Gavlin 2021-10-19 10:53:54 -07:00
parent c72bd3568a
commit 960a044abc
4 changed files with 20 additions and 13 deletions

View file

@ -4,3 +4,4 @@
/node_modules/
/custom_node/
/runtime/native/node_dev/
.nyc_output/

View file

@ -46,25 +46,28 @@ install_plugin:: build
install:: install_package install_plugin
istanbul_tests:: $(TEST_ALL_DEPS)
$(RUN_TESTSUITE) istanbul ./node_modules/.bin/istanbul test --print none _mocha -- --timeout 120000 --exclude 'bin/tests/automation/**/*.spec.js' 'bin/tests/**/*.spec.js'
./node_modules/.bin/istanbul report text-summary
./node_modules/.bin/istanbul report text
$(RUN_TESTSUITE) istanbul-with-mocks ./node_modules/.bin/istanbul test --print none _mocha -- 'bin/tests_with_mocks/**/*.spec.js'
unit_tests:: $(TEST_ALL_DEPS)
$(RUN_TESTSUITE) unit-nodejs ./node_modules/.bin/nyc -x 'bin/tests/runtime/*ClosureCases*.js' -s mocha --timeout 120000 --exclude 'bin/tests/automation/**/*.spec.js' --exclude 'bin/tests/runtime/closureLoader.spec.js' 'bin/tests/**/*.spec.js'
$(RUN_TESTSUITE) unit-nodejs mocha --timeout 120000 'bin/tests/runtime/closureLoader.spec.js'
$(RUN_TESTSUITE) unit-with-mocks-nodejs ./node_modules/.bin/nyc -s mocha 'bin/tests_with_mocks/**/*.spec.js'
auto_tests:: $(TEST_ALL_DEPS)
$(RUN_TESTSUITE) auto-nodejs ./node_modules/.bin/istanbul test --print none _mocha -- --timeout 120000 'bin/tests/automation/**/*.spec.js'
./node_modules/.bin/istanbul report text-summary
./node_modules/.bin/istanbul report text
$(RUN_TESTSUITE) auto-nodejs ./node_modules/.bin/nyc -s mocha --timeout 120000 'bin/tests/automation/**/*.spec.js'
sxs_tests:: $(TEST_ALL_DEPS)
pushd tests/sxs_ts_3.6 && yarn ; tsc ; popd
pushd tests/sxs_ts_latest && yarn ; tsc ; popd
test_fast:: sxs_tests istanbul_tests
test_fast:: sxs_tests unit_tests
ifneq ($(PULUMI_TEST_COVERAGE_PATH),)
if [ -e .nyc_output ]; then ./node_modules/.bin/nyc report -r cobertura --report-dir $(PULUMI_TEST_COVERAGE_PATH); fi
endif
$(GO_TEST_FAST) ${PROJECT_PKGS}
test_all:: sxs_tests istanbul_tests auto_tests
test_all:: sxs_tests unit_tests auto_tests
ifneq ($(PULUMI_TEST_COVERAGE_PATH),)
if [ -e .nyc_output ]; then ./node_modules/.bin/nyc report -r cobertura --report-dir $(PULUMI_TEST_COVERAGE_PATH); fi
endif
$(GO_TEST) ${PROJECT_PKGS}
dist:: build

View file

@ -39,13 +39,16 @@
"eslint": "^7.32.0",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-import": "^2.23.4",
"istanbul": "^0.4.5",
"mocha": "^3.5.0"
"nyc": "^15.1.0",
"mocha": "^9.0.0"
},
"pulumi": {
"comment": "Do not remove. Marks this as as a deployment-time-only package"
},
"engines": {
"node": ">=8.13.0 || >=10.10.0"
},
"mocha": {
"require": ["ts-node/register", "source-map-support/register"]
}
}

View file

@ -6,7 +6,7 @@
"module": "commonjs",
"moduleResolution": "node",
"declaration": true,
"sourceMap": false,
"sourceMap": true,
"stripInternal": true,
"experimentalDecorators": true,
"pretty": true,