Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Node 19 to CI Tests #320

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [14, 16, 18]
node: [14, 16, 18, 19]
steps:
# Setup environment and checkout the project master
- name: Setup Node.js environment
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"eslint-plugin-jest-formatting": "^3.1.0",
"eslint-plugin-simple-import-sort": "^7.0.0",
"jest": "^29.2.2",
"mockttp": "^3.2.3",
"mockttp": "^3.6.2",
"prettier": "2.3.2",
"rimraf": "^3.0.2",
"ts-jest": "^29.0.3",
Expand Down
9 changes: 5 additions & 4 deletions src/core/events/events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ const mockServer = getLocal();
const config = new Config(NodeFileSystem);
const timers = new MockTimers();
const crypto = new NodeCrypto();
const Connection = 'close';

describe('events', () => {
beforeEach(async () => {
Expand All @@ -179,7 +180,7 @@ describe('events', () => {
});

it('handles retry', async () => {
const endpoint = await mockServer.forGet('/test').thenJson(200, {});
const endpoint = await mockServer.forGet('/test').thenJson(200, {}, { Connection });
const events = new Events(timers);

const profile = new BoundProfileProvider(
Expand Down Expand Up @@ -266,7 +267,7 @@ describe('events', () => {
});

it('passes unhandled http responses to unhandled-http (201)', async () => {
const endpoint = await mockServer.forGet('/test').thenJson(201, {});
const endpoint = await mockServer.forGet('/test').thenJson(201, {}, { Connection });

const events = new Events(timers);
const profile = new BoundProfileProvider(
Expand Down Expand Up @@ -300,7 +301,7 @@ describe('events', () => {
});

it('passes unhandled http responses to unhandled-http (400)', async () => {
const endpoint = await mockServer.forGet('/test').thenJson(400, {});
const endpoint = await mockServer.forGet('/test').thenJson(400, {}, { Connection });

const events = new Events(timers);
const profile = new BoundProfileProvider(
Expand Down Expand Up @@ -334,7 +335,7 @@ describe('events', () => {
});

it('does not pass handled http response to unhandled-http (200)', async () => {
const endpoint = await mockServer.forGet('/test').thenJson(200, {});
const endpoint = await mockServer.forGet('/test').thenJson(200, {}, { Connection });

const events = new Events(timers);
const profile = new BoundProfileProvider(
Expand Down
75 changes: 40 additions & 35 deletions src/core/events/failure/event-adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import type { FileSystemError } from '../../errors';
import { bindResponseError, NotFoundError } from '../../errors';
import { Provider, ProviderConfiguration } from '../../provider';

const Connection = 'close';

const astMetadata: AstMetadata = {
sourceChecksum: 'checksum',
astVersion: {
Expand Down Expand Up @@ -488,7 +490,7 @@ describe('event-adapter', () => {

// Without retry policy
it('does not use retry policy - returns after HTTP 200', async () => {
const endpoint = await mockServer.forGet('/first').thenJson(200, {});
const endpoint = await mockServer.forGet('/first').thenJson(200, {}, { Connection });
const client = createMockClient();
client.addBoundProfileProvider(
firstMockProfileDocument,
Expand All @@ -508,7 +510,7 @@ describe('event-adapter', () => {
});

it('does not use retry policy - aborts after HTTP 500', async () => {
const endpoint = await mockServer.forGet('/first').thenJson(500, {});
const endpoint = await mockServer.forGet('/first').thenJson(500, {}, { Connection });
const client = createMockClient();

client.addBoundProfileProvider(
Expand Down Expand Up @@ -568,7 +570,7 @@ describe('event-adapter', () => {

// Circuit breaker
it('use circuit-breaker policy - aborts after HTTP 500', async () => {
const endpoint = await mockServer.forGet('/first').thenJson(500, {});
const endpoint = await mockServer.forGet('/first').thenJson(500, {}, { Connection });
const superJson = normalizeSuperJsonDocument(
{
profiles: {
Expand Down Expand Up @@ -639,6 +641,9 @@ describe('event-adapter', () => {
return {
statusCode: 200,
json: {},
headers: {
Connection
}
};
});

Expand Down Expand Up @@ -703,8 +708,8 @@ describe('event-adapter', () => {
});

it('use circuit-breaker policy - switch providers after HTTP 500, using default provider', async () => {
const endpoint = await mockServer.forGet('/first').thenJson(500, {});
const secondEndpoint = await mockServer.forGet('/second').thenJson(200, {});
const endpoint = await mockServer.forGet('/first').thenJson(500, {}, { Connection });
const secondEndpoint = await mockServer.forGet('/second').thenJson(200, {}, { Connection });
const superJson = normalizeSuperJsonDocument(
{
profiles: {
Expand Down Expand Up @@ -773,8 +778,8 @@ describe('event-adapter', () => {
});

it('use circuit-breaker policy - do not switch providers after HTTP 500 - using provider from user', async () => {
const endpoint = await mockServer.forGet('/first').thenJson(500, {});
const secondEndpoint = await mockServer.forGet('/second').thenJson(200, {});
const endpoint = await mockServer.forGet('/first').thenJson(500, {}, { Connection });
const secondEndpoint = await mockServer.forGet('/second').thenJson(200, {}, { Connection });
const superJson = normalizeSuperJsonDocument(
{
profiles: {
Expand Down Expand Up @@ -841,8 +846,8 @@ describe('event-adapter', () => {
});

it('use circuit-breaker policy - do not switch providers after HTTP 500, providerFailover is false', async () => {
const endpoint = await mockServer.forGet('/first').thenJson(500, {});
const secondEndpoint = await mockServer.forGet('/second').thenJson(200, {});
const endpoint = await mockServer.forGet('/first').thenJson(500, {}, { Connection });
const secondEndpoint = await mockServer.forGet('/second').thenJson(200, {}, { Connection });
const superJson = normalizeSuperJsonDocument(
{
profiles: {
Expand Down Expand Up @@ -911,8 +916,8 @@ describe('event-adapter', () => {
});

it('use circuit-breaker policy - switch providers after HTTP 500, use implict priority array', async () => {
const endpoint = await mockServer.forGet('/first').thenJson(500, {});
const secondEndpoint = await mockServer.forGet('/second').thenJson(200, {});
const endpoint = await mockServer.forGet('/first').thenJson(500, {}, { Connection });
const secondEndpoint = await mockServer.forGet('/second').thenJson(200, {}, { Connection });
const superJson = normalizeSuperJsonDocument(
{
profiles: {
Expand Down Expand Up @@ -981,8 +986,8 @@ describe('event-adapter', () => {
});

it('use two circuit-breaker policies - switch providers after HTTP 500', async () => {
const endpoint = await mockServer.forGet('/first').thenJson(500, {});
const secondEndpoint = await mockServer.forGet('/second').thenJson(200, {});
const endpoint = await mockServer.forGet('/first').thenJson(500, {}, { Connection });
const secondEndpoint = await mockServer.forGet('/second').thenJson(200, {}, { Connection });
const superJson = normalizeSuperJsonDocument(
{
profiles: {
Expand Down Expand Up @@ -1072,12 +1077,12 @@ describe('event-adapter', () => {
endpointCalls += 1;

if (endpointCalls > 2) {
return { statusCode: 200, json: {} };
return { statusCode: 200, json: {}, headers: { Connection } };
} else {
return { statusCode: 500, json: {} };
return { statusCode: 500, json: {}, headers: { Connection } };
}
});
const secondEndpoint = await mockServer.forGet('/second').thenJson(200, {});
const secondEndpoint = await mockServer.forGet('/second').thenJson(200, {}, { Connection });

const superJson = normalizeSuperJsonDocument(
{
Expand Down Expand Up @@ -1165,7 +1170,7 @@ describe('event-adapter', () => {
return { statusCode: 500, json: {} };
}
});
const secondEndpoint = await mockServer.forGet('/second').thenJson(200, {});
const secondEndpoint = await mockServer.forGet('/second').thenJson(200, {}, { Connection });

const superJson = normalizeSuperJsonDocument(
{
Expand Down Expand Up @@ -1249,13 +1254,13 @@ describe('event-adapter', () => {
endpointCalls += 1;

if (endpointCalls > 2) {
return { statusCode: 200, json: {} };
return { statusCode: 200, json: {}, headers: { Connection } };
} else {
return { statusCode: 500, json: {} };
return { statusCode: 500, json: {}, headers: { Connection } };
}
});
const secondEndpoint = await mockServer.forGet('/second').thenJson(200, {});
const thirdEndpoint = await mockServer.forGet('/third').thenJson(200, {});
const secondEndpoint = await mockServer.forGet('/second').thenJson(200, {}, { Connection });
const thirdEndpoint = await mockServer.forGet('/third').thenJson(200, {}, { Connection });

const superJson = normalizeSuperJsonDocument(
{
Expand Down Expand Up @@ -1366,8 +1371,8 @@ describe('event-adapter', () => {
});

it('use circuit-breaker policy - switch providers after HTTP 500, using provider from user and abort policy', async () => {
const endpoint = await mockServer.forGet('/first').thenJson(500, {});
const secondEndpoint = await mockServer.forGet('/second').thenJson(200, {});
const endpoint = await mockServer.forGet('/first').thenJson(500, {}, { Connection });
const secondEndpoint = await mockServer.forGet('/second').thenJson(200, {}, { Connection });

const superJson = normalizeSuperJsonDocument(
{
Expand Down Expand Up @@ -1447,13 +1452,13 @@ describe('event-adapter', () => {
* Bind
*/
it('use abort policy - switch providers after error in bind', async () => {
const endpoint = await mockServer.forGet('/first').thenJson(200, {});
const endpoint = await mockServer.forGet('/first').thenJson(200, {}, { Connection });
const bindEndpoint = await mockServer
.forPost('/registry/bind')
.thenJson(400, {
detail: 'Invalid request',
title: 'test',
});
}, { Connection });

const superJson = normalizeSuperJsonDocument(
{
Expand Down Expand Up @@ -1524,13 +1529,13 @@ describe('event-adapter', () => {
});

it('use default policy - switch providers after error in bind', async () => {
const endpoint = await mockServer.forGet('/first').thenJson(200, {});
const endpoint = await mockServer.forGet('/first').thenJson(200, {}, { Connection });
const bindEndpoint = await mockServer
.forPost('/registry/bind')
.thenJson(400, {
detail: 'Invalid request',
title: 'test',
});
}, { Connection });

const superJson = normalizeSuperJsonDocument(
{
Expand Down Expand Up @@ -1600,13 +1605,13 @@ describe('event-adapter', () => {
});

it('use default policy - fail after error in bind', async () => {
const endpoint = await mockServer.forGet('/first').thenJson(200, {});
const endpoint = await mockServer.forGet('/first').thenJson(200, {}, { Connection });
const bindEndpoint = await mockServer
.forPost('/registry/bind')
.thenJson(400, {
detail: 'Invalid request',
title: 'test',
});
}, { Connection });

const superJson = normalizeSuperJsonDocument(
{
Expand Down Expand Up @@ -1677,13 +1682,13 @@ describe('event-adapter', () => {
});

it('use circuit breaker policy - switch providers after error in bind', async () => {
const endpoint = await mockServer.forGet('/first').thenJson(200, {});
const endpoint = await mockServer.forGet('/first').thenJson(200, {}, { Connection });
const bindEndpoint = await mockServer
.forPost('/registry/bind')
.thenJson(400, {
detail: 'Invalid request',
title: 'test',
});
}, { Connection });

const superJson = normalizeSuperJsonDocument(
{
Expand Down Expand Up @@ -1764,8 +1769,8 @@ describe('event-adapter', () => {
});

it('preserves hook context within one client', async () => {
const endpoint = await mockServer.forGet('/first').thenJson(500, {});
const secondEndpoint = await mockServer.forGet('/second').thenJson(200, {});
const endpoint = await mockServer.forGet('/first').thenJson(500, {}, { Connection });
const secondEndpoint = await mockServer.forGet('/second').thenJson(200, {}, { Connection });
const superJson = normalizeSuperJsonDocument(
{
profiles: {
Expand Down Expand Up @@ -1859,8 +1864,8 @@ describe('event-adapter', () => {
});

it('does not preserve hook context across clients', async () => {
const endpoint = await mockServer.forGet('/first').thenJson(500, {});
const secondEndpoint = await mockServer.forGet('/second').thenJson(200, {});
const endpoint = await mockServer.forGet('/first').thenJson(500, {}, { Connection });
const secondEndpoint = await mockServer.forGet('/second').thenJson(200, {}, { Connection });
const superJson = normalizeSuperJsonDocument(
{
profiles: {
Expand Down
3 changes: 2 additions & 1 deletion src/core/events/reporter/reporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ const mockMapDocumentFailure: MapDocumentNode = {
};

const mockServer = getLocal();
const Connection = 'close';

describe('MetricReporter', () => {
let eventEndpoint: MockedEndpoint;
Expand All @@ -259,7 +260,7 @@ describe('MetricReporter', () => {
await mockServer.start();
eventEndpoint = await mockServer
.forPost('/insights/sdk_event')
.thenJson(202, {});
.thenJson(202, {}, { Connection });
});

afterEach(async () => {
Expand Down
8 changes: 5 additions & 3 deletions src/core/interpreter/http/http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const fetchInstance = new NodeFetch(timers);
const crypto = new NodeCrypto();
const http = new HttpClient(fetchInstance, crypto);

const Connection = 'close';

describe('HttpClient', () => {
let baseUrl: string;

Expand All @@ -26,7 +28,7 @@ describe('HttpClient', () => {
});

it('gets basic response', async () => {
await mockServer.forGet('/valid').thenJson(200, { response: 'valid' });
await mockServer.forGet('/valid').thenJson(200, { response: 'valid' }, { Connection });
const response = await http.request('/valid', {
method: 'get',
accept: 'application/json',
Expand All @@ -39,7 +41,7 @@ describe('HttpClient', () => {
it('gets error response', async () => {
await mockServer
.forGet('/invalid')
.thenJson(404, { error: { message: 'Not found' } });
.thenJson(404, { error: { message: 'Not found' } }, { Connection });
const response = await http.request('/invalid', {
method: 'get',
accept: 'application/json',
Expand Down Expand Up @@ -166,7 +168,7 @@ describe('HttpClient', () => {
await mockServer.forPost('/data').thenCallback(async req => {
return {
status: 200,
headers: { 'content-type': 'application/json' },
headers: { 'content-type': 'application/json', Connection },
body: JSON.stringify({
contentType: req.headers['content-type'],
body: await req.body.getText(),
Expand Down
Loading