Skip to content

Commit

Permalink
require 95% test and function test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jj22ee committed Aug 20, 2024
1 parent 3fb10bc commit 38a18e5
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"prepublishOnly": "npm run compile",
"tdd": "yarn test -- --watch-extensions ts --watch",
"test": "nyc ts-mocha --timeout 10000 -p tsconfig.json --require '@opentelemetry/contrib-test-utils' 'test/**/*.ts'",
"test:coverage": "nyc --all --check-coverage --functions 95 --lines 95 ts-mocha --timeout 10000 -p tsconfig.json --require '@opentelemetry/contrib-test-utils' 'test/**/*.ts'",
"watch": "tsc -w"
},
"bugs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ describe('AwsOpenTelemetryConfiguratorTest', () => {
awsOtelConfigurator = new AwsOpentelemetryConfigurator([]);
});

// Cleanup any span processors to avoid unit test conflicts
after(() => {
(awsOtelConfigurator as any).spanProcessors.forEach((spanProcessor: SpanProcessor) => {
spanProcessor.shutdown();
});
});

// The probability of this passing once without correct IDs is low, 20 times is inconceivable.
it('ProvideGenerateXrayIdsTest', () => {
const tracerProvider: NodeTracerProvider = new NodeTracerProvider(awsOtelConfigurator.configure());
Expand Down Expand Up @@ -262,6 +269,11 @@ describe('AwsOpenTelemetryConfiguratorTest', () => {
delete process.env.OTEL_METRIC_EXPORT_INTERVAL;
delete process.env.OTEL_AWS_APPLICATION_SIGNALS_ENABLED;
}

// shut down exporters for test cleanup
spanProcessors.forEach(spanProcessor => {
spanProcessor.shutdown();
});
});

it('ApplicationSignalsExporterProviderTest', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,52 @@
// SPDX-License-Identifier: Apache-2.0
// Modifications Copyright The OpenTelemetry Authors. Licensed under the Apache License 2.0 License.

import { NodeSDK } from '@opentelemetry/sdk-node';
import * as assert from 'assert';
import { spawnSync, SpawnSyncReturns } from 'child_process';
import expect from 'expect';
import { setAwsDefaultEnvironmentVariables } from '../src/register';

// The OpenTelemetry Authors code
// Extend register.test.ts functionality to also test exported span with Application Signals enabled
describe('Register', function () {
it('Requires without error', () => {
const originalPrototypeStart = NodeSDK.prototype.start
NodeSDK.prototype.start = () => {}
try {
require('../src/register');
} catch(err: unknown) {
assert.fail(`require register unexpectedly failed: ${err}`);
}

NodeSDK.prototype.start = originalPrototypeStart
})

it('Tests AWS Default Environment Variables', () => {
this.beforeEach(() => {
delete process.env.OTEL_EXPORTER_OTLP_PROTOCOL
delete process.env.OTEL_PROPAGATORS
delete process.env.OTEL_NODE_DISABLED_INSTRUMENTATIONS
})

it('sets AWS Default Environment Variables', () => {
setAwsDefaultEnvironmentVariables();
expect(process.env.OTEL_EXPORTER_OTLP_PROTOCOL).toEqual('http/protobuf');
expect(process.env.OTEL_PROPAGATORS).toEqual('xray,tracecontext,b3,b3multi');
expect(process.env.OTEL_NODE_DISABLED_INSTRUMENTATIONS).toEqual('fs');
})

it('Does not set AWS Default Environment Variables', () => {
process.env.OTEL_EXPORTER_OTLP_PROTOCOL = 'customProtocol';
process.env.OTEL_PROPAGATORS = 'customPropagators';
process.env.OTEL_NODE_DISABLED_INSTRUMENTATIONS = 'customDisabledInstrumentations';
setAwsDefaultEnvironmentVariables();
expect(process.env.OTEL_EXPORTER_OTLP_PROTOCOL).toEqual('customProtocol');
expect(process.env.OTEL_PROPAGATORS).toEqual('customPropagators');
expect(process.env.OTEL_NODE_DISABLED_INSTRUMENTATIONS).toEqual('customDisabledInstrumentations');
})
});

it('can load auto instrumentation from command line', () => {
const proc: SpawnSyncReturns<Buffer> = spawnSync(
process.execPath,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"compile": "lerna run compile",
"prewatch": "npm run precompile",
"test": "lerna run test",
"test:coverage": "lerna run test:coverage",
"test:ci:changed": "lerna run test --since origin/main",
"test:browser": "lerna run test:browser --concurrency 1",
"test-all-versions": "npm run --if-present --workspaces test-all-versions",
Expand Down

0 comments on commit 38a18e5

Please sign in to comment.