-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
test(node): New Node integration test runner #10117
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
Conversation
this sounds nice! Does that work with OpenTelemetry, I wonder? So with |
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);
}); |
@@ -15,6 +22,7 @@ | |||
"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", |
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 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
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.
Looks good!
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
Anr
andLocalVariables
tests to use this new format.How to use
First, in your test scenario, you need to set the transport to the
loggingTransport
from@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
createRunner
function to create your test. ThecreateRunner
args are the path segments to the scenario. If you pass a typescript entry file,-r ts-node/register
gets added to the node args.Every
expect
call adds an expected envelope item. Currently you can expectevent
,transaction
andsession
but it's easy to add extra type-safe expectations. You must add anexpect
for 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
/session
can 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
done
tostart
,done
will be called when all the envelope items have matched the expected anddone
will 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: