-
Notifications
You must be signed in to change notification settings - Fork 837
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
5b30f6c
commit 2682afc
Showing
2 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.msw.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,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; | ||
}); | ||
}); | ||
}); |
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