-
Notifications
You must be signed in to change notification settings - Fork 395
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
chore: Switch to using Node built-in test runner #2387
Conversation
package.json
Outdated
@@ -161,22 +161,22 @@ | |||
"bench": "node ./bin/run-bench.js", | |||
"docker-env": "./bin/docker-env-vars.sh", | |||
"docs": "rm -rf ./out && jsdoc -c ./jsdoc-conf.jsonc --private -r .", | |||
"integration": "npm run prepare-test && npm run sub-install && time c8 -o ./coverage/integration tap --test-regex='(\\/|^test\\/integration\\/.*\\.tap\\.js)$' --timeout=600 --no-coverage --reporter classic", | |||
"integration:esm": "time c8 -o ./coverage/integration-esm tap --node-arg='--loader=./esm-loader.mjs' --test-regex='(test\\/integration\\/.*\\.tap\\.mjs)$' --timeout=600 --no-coverage --reporter classic", | |||
"integration": "npm run prepare-test && npm run sub-install && time c8 -o ./coverage/integration node --test test/integration/**/*.tap.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like that we have to rely on shell expansion of the globs in all of these scripts. But we don't run CI on Windows, and in-process expansion of the globs isn't supported until Node 22. So it is what it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have notice the default reporter spec
could pose problems in CI. It does not appear there is an equivalent to tap's classic
reporter. If we change to dot
reporter it will reduce I/O and seems to speed up the test runs as well. This may have to be a follow up because --test-reporter
doesn't exist until 18
I did suggest some changes as I noticed the globs didn't account for tests in the direct child of a given test type. However, it also appears my proposed changes to include all tests by chaining globs segfaults in node 16, and does not work in 18 and 20.
I did compare the coverage is still the same, as expected because we're still relying on v8 coverage and c8 to report it.
What problems might those be?
I don't particularly like the # Unit test run without specifying a reporter:
ℹ tests 176
ℹ suites 0
ℹ pass 176
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 31175.115292
real 0m34.861s
user 1m25.072s
sys 0m31.439s # With the dot reporter:
................................................................................................................................................................................
real 0m29.611s
user 1m25.536s
sys 0m32.046s I've done the test multiple times and either reporter is roughly the same amount of time. One key difference is in error reporting. This is what the dot reporter does if there is a test failure: ❯ npm run unit
> newrelic@11.23.1 unit
> rm -f newrelic_agent.log && time c8 -o ./coverage/unit node --test-reporter dot --test test/unit/*.test.js test/unit/**/*.test.js
.......................................X........................................................................................................................................
real 0m28.944s
user 1m25.835s
sys 0m31.681s I think that is really useless. I don't enjoy having to search all of the output of the standard reporter, but at least we can see which test(s) failed. |
🤔 we could report to We could also write a simple reporter that outputs test failures when they occur, and nothing on success. In other words, mimic our versioned tests output. Example: ❯ npm run unit
> newrelic@11.23.1 unit
> rm -f newrelic_agent.log && time c8 -o ./coverage/unit node --test-reporter ./reporter.js --test test/unit/*.test.js test/unit/**/*.test.js
failed: /Users/jsumners/Projects/team-repos/node-newrelic/test/unit/attributes.test.js
real 0m26.942s
user 1m23.630s
sys 0m31.549s I think we could write a much better reporter that shows offending line numbers and such, but the runner in v18 seems to omit a lot of that in my test case (just reporting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the update to globs still isn't running all the tests. i found in node 22 if you wrap each glob in single quotes it works. but that fails in 18 and 20
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall looks great. i do have some failing tests that i suspect are because of time outs though
package.json
Outdated
"ssl": "./bin/ssl.sh", | ||
"sub-install": "node test/bin/install_sub_deps", | ||
"test": "npm run integration && npm run unit", | ||
"third-party-updates": "oss third-party manifest --includeOptDeps && oss third-party notices --includeOptDeps && git add THIRD_PARTY_NOTICES.md third_party_manifest.json", | ||
"unit": "rm -f newrelic_agent.log && time c8 -o ./coverage/unit tap --test-regex='(\\/|^test\\/unit\\/.*\\.test\\.js)$' --timeout=180 --no-coverage --reporter classic", | ||
"unit:scripts": "time c8 -o ./coverage/scripts-unit tap --test-regex='(\\/|^bin\\/test\\/.*\\.test\\.js)$' --timeout=180 --no-coverage --reporter classic", | ||
"unit": "rm -f newrelic_agent.log && time c8 -o ./coverage/unit borp --reporter ./test/lib/test-reporter.mjs 'test/unit/**/*.test.js'", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think a timeout has to be set. the facts.test.js fails
package.json
Outdated
"prepare-test": "npm run ssl && npm run docker-env", | ||
"lint": "eslint ./*.{js,mjs} lib test bin examples", | ||
"lint:fix": "eslint --fix, ./*.{js,mjs} lib test bin examples", | ||
"public-docs": "jsdoc -c ./jsdoc-conf.jsonc && cp examples/shim/*.png out/", | ||
"publish-docs": "./bin/publish-docs.sh", | ||
"services": "DOCKER_PLATFORM=linux/$(uname -m) docker compose up -d --wait", | ||
"services:stop": "docker compose down", | ||
"smoke": "npm run ssl && time tap test/smoke/**/**/*.tap.js --timeout=180 --no-coverage", | ||
"smoke": "npm run ssl && time borp --reporter ./test/lib/test-reporter.mjs 'test/smoke/**/*.tap.js'", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we need to restore the timeout. i have 1 test that fails
const OUTPUT_MODE = process.env.OUTPUT_MODE?.toLowerCase() ?? 'simple' | ||
const isSilent = OUTPUT_MODE === 'quiet' || OUTPUT_MODE === 'silent' | ||
|
||
async function* reporter(source) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nice. we can always add to this.
This PR resolves #2379. It must target the
next
branch because Node.js 16 does not include the test runner.