From de679ad46d16019abdea79c48c7fb1f9635a8ad5 Mon Sep 17 00:00:00 2001 From: Onur Temizkan Date: Fri, 6 Dec 2024 12:42:20 +0000 Subject: [PATCH] fix(test-utils): Don't swallow assertion errors from `checkResult` and `checkCollector` (#2588) Co-authored-by: Marc Pichler --- .../opentelemetry-test-utils/src/test-fixtures.ts | 4 +++- .../test/hapi.test.ts | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/opentelemetry-test-utils/src/test-fixtures.ts b/packages/opentelemetry-test-utils/src/test-fixtures.ts index 37995ffa04..c96c5927b5 100644 --- a/packages/opentelemetry-test-utils/src/test-fixtures.ts +++ b/packages/opentelemetry-test-utils/src/test-fixtures.ts @@ -236,7 +236,7 @@ export async function runTestFixture( const collector = new TestCollector(); await collector.start(); - return new Promise(resolve => { + return new Promise((resolve, reject) => { execFile( process.execPath, opts.argv, @@ -261,6 +261,8 @@ export async function runTestFixture( if (opts.checkCollector) { await opts.checkCollector(collector); } + } catch (err) { + reject(err); } finally { collector.close(); resolve(); diff --git a/plugins/node/opentelemetry-instrumentation-hapi/test/hapi.test.ts b/plugins/node/opentelemetry-instrumentation-hapi/test/hapi.test.ts index af87e04901..48e2c51912 100644 --- a/plugins/node/opentelemetry-instrumentation-hapi/test/hapi.test.ts +++ b/plugins/node/opentelemetry-instrumentation-hapi/test/hapi.test.ts @@ -557,15 +557,24 @@ describe('Hapi Instrumentation - Core Tests', () => { }, checkCollector: (collector: TestCollector) => { const spans = collector.sortedSpans; - assert.strictEqual(spans.length, 2); - assert.strictEqual(spans[0].name, 'GET /route/{param}'); + + assert.strictEqual(spans.length, 3); + + assert.strictEqual(spans[0].name, 'GET'); assert.strictEqual( spans[0].instrumentationScope.name, '@opentelemetry/instrumentation-http' ); - assert.strictEqual(spans[1].name, 'route - /route/{param}'); + + assert.strictEqual(spans[1].name, 'GET /route/{param}'); assert.strictEqual( spans[1].instrumentationScope.name, + '@opentelemetry/instrumentation-http' + ); + + assert.strictEqual(spans[2].name, 'route - /route/{param}'); + assert.strictEqual( + spans[2].instrumentationScope.name, '@opentelemetry/instrumentation-hapi' ); },