Skip to content

Commit

Permalink
E2E/integration tests: configure Polly.js HTTP adapter correctly, min…
Browse files Browse the repository at this point in the history
…or tweaks ✅

remotely related: nock/nock#2461

Also silence a warning about the browser being offline.
  • Loading branch information
derhuerst committed Feb 25, 2024
1 parent 9eeafd0 commit 336a9ba
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion test/e2e/lib/util.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Polly's HTTP adapter uses nock [1] underneath, with currenctly monkey-patches the built-in `node:http` module. For this to work, it must be imported quite early, before many other parts of hafas-client.
// Importing the adapter itself has no side effects (or rather: immediately undoes nock's monkey-patching, to re-patch when it is actually getting used). We activate it (by passing it into Polly's core) below.
// remotely related: https://github.com/nock/nock/issues/2461
import NodeHttpAdapter from '@pollyjs/adapter-node-http';

import isRoughlyEqual from 'is-roughly-equal';
import {ok, AssertionError} from 'assert';
import {DateTime} from 'luxon';
Expand Down Expand Up @@ -70,6 +75,11 @@ if (process.env.VCR_MODE && !process.env.VCR_OFF) {
Polly.register(NodeHttpAdapter);
Polly.register(FSPersister);

// https://github.com/Netflix/pollyjs/blob/9b6bede12b7ee998472b8883c9dd01e2159e00a8/packages/%40pollyjs/adapter/src/index.js#L184-L189
if ('navigator' in global && global.navigator && !('onLine' in global.navigator)) {
global.navigator.onLine = true;
}

let mode;
if (process.env.VCR_MODE === 'record') {
mode = 'record';
Expand Down Expand Up @@ -102,7 +112,7 @@ if (process.env.VCR_MODE && !process.env.VCR_OFF) {
keepUnusedRequests: true, // todo: change to false?
},
matchRequestsBy: {
order: false,
order: false, // todo: set to true for better Git diffs?
headers: {
// todo: use an allow-list here?
exclude: [
Expand Down

0 comments on commit 336a9ba

Please sign in to comment.