test(node): New Node integration test runner#10117
Merged
AbhiPrasad merged 27 commits intogetsentry:developfrom Jan 11, 2024
Merged
test(node): New Node integration test runner#10117AbhiPrasad merged 27 commits intogetsentry:developfrom
AbhiPrasad merged 27 commits intogetsentry:developfrom
Conversation
Member
|
this sounds nice! Does that work with OpenTelemetry, I wonder? So with |
Collaborator
Author
Yep, that's partly what its for: test('otel with loader', done => {
createRunner(__dirname, 'express-otel.mjs')
.withFlags('--experimental-loader=@opentelemetry/instrumentation/hook.mjs')
.expect({ transaction: EXPRESS_TRANSACTION })
.start(done);
}); |
Collaborator
Author
timfish
commented
Jan 9, 2024
| "type-check": "tsc", | ||
| "pretest": "run-s --silent prisma:init prisma:init:new", | ||
| "test": "ts-node ./utils/run-tests.ts", | ||
| "jest": "jest --config ./jest.config.js", |
Collaborator
Author
There was a problem hiding this comment.
I added this simply because it allows you to call yarn jest -t "name-of-test" --verbose and get debug output very quickly from a single test. yarn test -t "name-of-test" runs through the existing custom test runner code and takes ages...
Hopefully we can migrate to just using the jest runner!
ae4f195 to
aec3278
Compare
61bda50 to
ff1f88a
Compare
AbhiPrasad
approved these changes
Jan 11, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

To aid in adding tests for #9907
Adds a new Node integration test runner that runs the scenario in its own Node process and reads the envelope back from stdout.
I have converted all the
AnrandLocalVariablestests to use this new format.How to use
First, in your test scenario, you need to set the transport to the
loggingTransportfrom@sentry-internal/node-integration-tests. This will cause envelopes to be logged to stdout as a single line of JSON:Then in your test, use the
createRunnerfunction to create your test. ThecreateRunnerargs are the path segments to the scenario. If you pass a typescript entry file,-r ts-node/registergets added to the node args.Every
expectcall adds an expected envelope item. Currently you can expectevent,transactionandsessionbut it's easy to add extra type-safe expectations. You must add anexpectfor every envelope item that will be sent and they must be in the correct order or an error is thrown and the test fails. The expectevent/transaction/sessioncan be a callback or an object that will be tested against the received envelope.If you don't care about specific types of envelope item, you can ignore them:
If you pass
donetostart,donewill be called when all the envelope items have matched the expected anddonewill be passed any errors that occur which ends the test without waiting for the timeout.Example
Here is an Anr test that ensures we get the expected session envelope followed by the expected event envelope:
It's also possible to pass flags to node via the
withFlags()function: