Skip to content

Commit

Permalink
Port enabling/disabling tests
Browse files Browse the repository at this point in the history
These tests doesn't actually need the complicated setup to work,
so seperated them out into a new suite. Spiritually should be the
same coverage as before, with a new test for `{ enabled: false }`.
  • Loading branch information
chancancode committed Dec 18, 2024
1 parent 5b30f6c commit 2682afc
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { isWrapped } from '@opentelemetry/instrumentation';

import * as assert from 'assert';
import { FetchInstrumentation } from '../src';

describe('fetch', () => {
describe('enabling/disabling', () => {
let fetchInstrumentation: FetchInstrumentation | undefined;

afterEach(() => {
fetchInstrumentation?.disable();
fetchInstrumentation = undefined;
});

it('should wrap global fetch when instantiated', () => {
assert.ok(!isWrapped(window.fetch));
fetchInstrumentation = new FetchInstrumentation();
assert.ok(isWrapped(window.fetch));
});

it('should not wrap global fetch when instantiated with `enabled: false`', () => {
assert.ok(!isWrapped(window.fetch));
fetchInstrumentation = new FetchInstrumentation({ enabled: false });
assert.ok(!isWrapped(window.fetch));
fetchInstrumentation.enable();
assert.ok(isWrapped(window.fetch));
});

it('should unwrap global fetch when disabled', () => {
fetchInstrumentation = new FetchInstrumentation();
assert.ok(isWrapped(window.fetch));
fetchInstrumentation.disable();
assert.ok(!isWrapped(window.fetch));

// Avoids ERROR in the logs when calling `disable()` again during cleanup
fetchInstrumentation = undefined;
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,13 @@ describe('fetch', () => {
clearData();
});

it('should wrap methods', () => {
xit('should wrap methods', () => {
assert.ok(isWrapped(window.fetch));
fetchInstrumentation.enable();
assert.ok(isWrapped(window.fetch));
});

it('should unwrap methods', () => {
xit('should unwrap methods', () => {
assert.ok(isWrapped(window.fetch));
fetchInstrumentation.disable();
assert.ok(!isWrapped(window.fetch));
Expand Down

0 comments on commit 2682afc

Please sign in to comment.