Skip to content

Commit

Permalink
test: fix fetch tests for Node 18
Browse files Browse the repository at this point in the history
  • Loading branch information
favna committed Jun 1, 2022
1 parent 522c305 commit e92fb02
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@ jobs:
Testing:
name: Unit Tests
runs-on: ubuntu-latest
strategy:
matrix:
node: [16, 18]
steps:
- name: Checkout Project
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3
- name: Use Node.js v16
- name: Use Node.js v{{ matrix.version }}
uses: actions/setup-node@17f8bd926464a1afa4c6a11669539e9c1ba77048 # tag=v3
with:
node-version: 16
node-version: ${{ matrix.version }}
cache: yarn
registry-url: https://registry.npmjs.org/
- name: Install Dependencies
Expand All @@ -48,6 +51,7 @@ jobs:
- name: Run tests
run: yarn test:coverage
- name: Store code coverage report
if: ${{ matrix.node == '18' }}
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # tag=v3
with:
name: coverage
Expand Down
2 changes: 1 addition & 1 deletion jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const config = {
preset: 'ts-jest',
testMatch: ['<rootDir>/packages/**/tests/**/*.test.ts', '<rootDir>/packages/**/tests/**/*.test.js', '<rootDir>/packages/**/tests/**/*.test.tsx'],
collectCoverageFrom: ['<rootDir>/packages/**/src/**/*.ts'],
setupFilesAfterEnv: ['jest-extended/all'],
setupFilesAfterEnv: ['jest-extended/all', '<rootDir>/packages/fetch/tests/jest.setup.js'],
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.dev.json'
Expand Down
1 change: 1 addition & 0 deletions packages/fetch/jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const config = {
preset: 'ts-jest',
testMatch: ['<rootDir>/tests/**/*.test.ts'],
collectCoverageFrom: ['<rootDir>/src/**/*.ts'],
setupFilesAfterEnv: ['<rootDir>/tests/jest.setup.js'],
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tests/tsconfig.json'
Expand Down
2 changes: 1 addition & 1 deletion packages/fetch/tests/fetch.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import nock from 'nock';
import { URL as NodeUrl } from 'node:url';
import { fetch, FetchResultTypes, QueryError, FetchMediaContentTypes } from '../dist';
import { fetch, FetchMediaContentTypes, FetchResultTypes, QueryError } from '../dist';

describe('fetch', () => {
let nockScopeHttp: nock.Scope;
Expand Down
9 changes: 9 additions & 0 deletions packages/fetch/tests/jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const originalGlobalFetch = globalThis.fetch;

globalThis.fetch = undefined;

afterAll(() => {
if (originalGlobalFetch) {
globalThis.fetch = originalGlobalFetch;
}
});

0 comments on commit e92fb02

Please sign in to comment.