-
Notifications
You must be signed in to change notification settings - Fork 538
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd89bcc
commit 5cd3b7c
Showing
4 changed files
with
93 additions
and
33 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
58 changes: 58 additions & 0 deletions
58
plugins/node/opentelemetry-instrumentation-pg/test/pg.esm.test.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import * as assert from 'assert'; | ||
import * as testUtils from '@opentelemetry/contrib-test-utils'; | ||
|
||
describe('pg ESM usage', () => { | ||
const testPostgres = process.env.RUN_POSTGRES_TESTS; // For CI: assumes local postgres db is already available | ||
const testPostgresLocally = process.env.RUN_POSTGRES_TESTS_LOCAL; // For local: spins up local postgres db via docker | ||
const shouldTest = testPostgres || testPostgresLocally; // Skips these tests if false (default) | ||
|
||
before(async function () { | ||
const skip = () => { | ||
// this.skip() workaround | ||
// https://github.com/mochajs/mocha/issues/2683#issuecomment-375629901 | ||
this.test!.parent!.pending = true; | ||
this.skip(); | ||
}; | ||
|
||
if (!shouldTest) { | ||
skip(); | ||
} | ||
|
||
if (testPostgresLocally) { | ||
testUtils.startDocker('postgres'); | ||
} | ||
}); | ||
|
||
after(async () => { | ||
if (testPostgresLocally) { | ||
testUtils.cleanUpDocker('postgres'); | ||
} | ||
}); | ||
|
||
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) => { | ||
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); | ||
}, | ||
}); | ||
}); | ||
}); |
This file contains 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