Commit 2e164e1
authored
test(node): Add utility to test esm & cjs instrumentation (#16159)
Today, we do not have a lot of esm-specific node integration tests. Our
tests make it possible to test ESM, but we only use it very rarely,
sticking to cjs tests across the suite mostly. This means that we have a
bunch of gaps around our ESM support.
This PR introduces a new test utility to make it easier to test stuff in
ESM and CJS:
```js
createEsmAndCjsTests(
__dirname,
'scenario.mjs',
'instrument.mjs',
(createRunner, test) => {
test('it works when importing the http module', async () => {
const runner = createRunner(); // normal test as before
});
});
```
This has a few limitations based on how this works - we can make this
more robust in the future, but for now it should be "OK":
1. It requires a .mjs based instrument file as well as an .mjs based
scenario
2. No relative imports are supported (all content must be in these two
files)
3. It simply regex replaces the esm imports with require for the CJS
tests. not perfect, but it kind of works
For tests that are known to fail on e.g. esm or cjs, you can configure
`failsOnEsm: true`. In this case, it will fail if the test _does not
fail_ (by using `test.fails()` to ensure test failure). This way we can
ensure we find out if stuff starts to fail etc.
To make this work, I had to re-write the test runner code a bit, because
it had issues with vitest unhandled rejection handling. Due to the way
we handled test completion with a promise, `test.fails` was not working
as expected, because the test indeed succeeded when it failed, but the
overall test run still failed because an unhandled rejection bubbled up.
Now, this should work as expected...
I re-wrote a few tests already to show how it works, plus added a new
test that shows an ESM test failure when importing http module (😭 )1 parent 2130d35 commit 2e164e1
File tree
59 files changed
+818
-703
lines changed- dev-packages/node-integration-tests
- suites
- anr
- breadcrumbs/process-thread
- child-process
- contextLines/filename-with-spaces
- esm
- import-in-the-middle
- modules-integration
- warn-esm
- express/with-http
- public-api/LocalVariables
- tracing
- ai
- amqplib
- connect
- dataloader
- genericPool
- hapi
- httpIntegration
- kafkajs
- knex
- requests/http-sampled-esm
- utils
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
59 files changed
+818
-703
lines changed| 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 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
6 | | - | |
7 | | - | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
| |||
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
4 | | - | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
4 | | - | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
| |||
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
4 | | - | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
| |||
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
4 | | - | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
110 | | - | |
| 110 | + | |
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| |||
Lines changed: 15 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | 4 | | |
3 | | - | |
4 | | - | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
21 | 22 | | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
27 | 28 | | |
28 | | - | |
| 29 | + | |
| 30 | + | |
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
| 13 | + | |
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
| |||
0 commit comments