Commit 98979d8
authored
test(node): New Node integration test runner (#10117)
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` and `LocalVariables` 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:
```ts
import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';
Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
transport: loggingTransport,
});
```
Then in your test, use the `createRunner` function to create your test.
The `createRunner` 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
expect `event`, `transaction` and `session` but it's easy to add extra
type-safe expectations. You must add an `expect` 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 expect
`event`/`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:
```ts
createRunner(__dirname, 'basic.js')
.ignore('session', 'sessions')
.expect(//...
```
If you pass `done` to `start`, `done` will be called when all the
envelope items have matched the expected and `done` 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:
```ts
import { assertSentryEvent, assertSentrySession, createRunner } from '../../utils/runner';
const EXPECTED_ANR_EVENT = {
// Ensure we have context
contexts: {
trace: {
span_id: expect.any(String),
trace_id: expect.any(String),
},
device: {
arch: expect.any(String),
},
app: {
app_start_time: expect.any(String),
},
os: {
name: expect.any(String),
},
culture: {
timezone: expect.any(String),
},
},
// and an exception that is our ANR
exception: {
values: [
{
type: 'ApplicationNotResponding',
value: 'Application Not Responding for at least 200 ms',
mechanism: { type: 'ANR' },
stacktrace: {
frames: expect.arrayContaining([
{
colno: expect.any(Number),
lineno: expect.any(Number),
filename: expect.any(String),
function: '?',
in_app: true,
},
{
colno: expect.any(Number),
lineno: expect.any(Number),
filename: expect.any(String),
function: 'longWork',
in_app: true,
},
]),
},
},
],
},
};
test('Anr with session', done => {
createRunner(__dirname, 'basic-session.js')
.expect({ session: { status: 'abnormal', abnormal_mechanism: 'anr_foreground' } })
.expect({ event: EXPECTED_ANR_EVENT })
.start(done);
});
```
It's also possible to pass flags to node via the `withFlags()` function:
```ts
test('With --inspect',done => {
createRunner(__dirname, 'basic.mjs')
.withFlags('--inspect')
.expect({ event: EXPECTED_ANR_EVENT })
.start(done);
});
```1 parent 45ef67e commit 98979d8
File tree
23 files changed
+535
-381
lines changed- .github/workflows
- dev-packages/node-integration-tests
- src
- suites
- anr
- express/tracing
- public-api/LocalVariables
- utils
- packages/node/src/integrations/anr
23 files changed
+535
-381
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
9 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
10 | 17 | | |
11 | 18 | | |
12 | 19 | | |
| |||
15 | 22 | | |
16 | 23 | | |
17 | 24 | | |
| 25 | + | |
18 | 26 | | |
19 | 27 | | |
20 | 28 | | |
21 | 29 | | |
22 | 30 | | |
23 | 31 | | |
| 32 | + | |
24 | 33 | | |
25 | 34 | | |
26 | 35 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
0 commit comments