Skip to content

Commit

Permalink
Make ESM test standalone
Browse files Browse the repository at this point in the history
  • Loading branch information
onurtemizkan committed Dec 6, 2024
1 parent 44e37ea commit 44988a3
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ describe('pg', () => {
if (testPostgresLocally) {
testUtils.cleanUpDocker('postgres');
}

await client.end();
});

Expand Down Expand Up @@ -1087,31 +1088,31 @@ describe('pg', () => {
});
});
});
});

it('should work with ESM usage', async () => {
await testUtils.runTestFixture({
cwd: __dirname,
argv: ['fixtures/use-pg.mjs'],
env: {
NODE_OPTIONS:
'--experimental-loader=@opentelemetry/instrumentation/hook.mjs',
NODE_NO_WARNINGS: '1',
},
checkResult: (err, stdout, stderr) => {
assert.ifError(err);
},
checkCollector: (collector: testUtils.TestCollector) => {
const spans = collector.sortedSpans;

assert.strictEqual(spans.length, 3);

assert.strictEqual(spans[0].name, 'pg.connect');
assert.strictEqual(spans[0].kind, 3);
assert.strictEqual(spans[1].name, 'test-span');
assert.strictEqual(spans[1].kind, 1);
assert.strictEqual(spans[2].name, 'pg.query:SELECT postgres');
assert.strictEqual(spans[2].kind, 3);
},
});
it('should work with ESM usage', async () => {
await testUtils.runTestFixture({
cwd: __dirname,
argv: ['fixtures/use-pg.mjs'],
env: {
NODE_OPTIONS:
'--experimental-loader=@opentelemetry/instrumentation/hook.mjs',
NODE_NO_WARNINGS: '1',
},
checkResult: (err, stdout, stderr) => {
assert.ifError(err);
},
checkCollector: (collector: testUtils.TestCollector) => {
const spans = collector.sortedSpans;

assert.strictEqual(spans.length, 3);

assert.strictEqual(spans[0].name, 'pg.connect');
assert.strictEqual(spans[0].kind, 3);
assert.strictEqual(spans[1].name, 'test-span');
assert.strictEqual(spans[1].kind, 1);
assert.strictEqual(spans[2].name, 'pg.query:SELECT postgres');
assert.strictEqual(spans[2].kind, 3);
},
});
});

0 comments on commit 44988a3

Please sign in to comment.