Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into feat/conditionalIntlPolyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew-Mallimo authored Mar 6, 2024
2 parents ce17ecb + 4374848 commit 74b64c2
Show file tree
Hide file tree
Showing 54 changed files with 1,590 additions and 1,344 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/on-main_release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
update_release_draft:
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@v5
- uses: release-drafter/release-drafter@v6
with:
config-name: release-drafter-main.yml # located in .github/ in default branch
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/on-pr_pr-labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
pr-labeler:
runs-on: ubuntu-latest
steps:
- uses: TimonVS/pr-labeler-action@v4
- uses: TimonVS/pr-labeler-action@v5
with:
configuration-path: .github/pr-labeler.yml # optional, .github/pr-labeler.yml is the default value
env:
Expand Down
4 changes: 2 additions & 2 deletions __tests__/server/config/env/runTime.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ expect.extend({
},
});

jest.mock('ip', () => ({
address: () => 'localhost',
jest.mock('../../../../src/server/utils/getIP', () => ({
getIp: () => 'localhost',
}));

jest.mock('yargs', () => ({ argv: { rootModuleName: 'my-module' } }));
Expand Down
9 changes: 4 additions & 5 deletions __tests__/server/plugins/reactHtml/staticErrorPage.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* permissions and limitations under the License.
*/

import util from 'node:util';
import Fastify from 'fastify';
import staticErrorPage, {
setErrorPage,
Expand All @@ -29,10 +30,8 @@ jest.mock('@americanexpress/fetch-enhancers', () => ({
),
}));

jest.spyOn(console, 'info').mockImplementation(() => { });
jest.spyOn(console, 'log').mockImplementation(() => { });
jest.spyOn(console, 'error').mockImplementation(() => { });
jest.spyOn(console, 'warn').mockImplementationOnce(() => { });
jest.spyOn(console, 'error').mockImplementation(() => {});
jest.spyOn(console, 'warn').mockImplementation(util.format);

describe('staticErrorPage', () => {
beforeEach(() => {
Expand Down Expand Up @@ -209,7 +208,7 @@ describe('staticErrorPage', () => {
expect(global.fetch).toHaveBeenCalledTimes(1);
expect(global.fetch).toHaveBeenCalledWith(errorPageUrl);
expect(await data.timeout).toBe(6000);
expect(console.warn).toHaveBeenCalledWith('Failed to fetch custom error page with status:', statusCode);
expect(console.warn.mock.results[0].value).toBe('Failed to fetch custom error page with status: 500');
expect(response.body).toContain('<!DOCTYPE html>');
expect(response.body).toContain('<meta name="application-name" content="one-app">');
expect(response.body).toContain('Sorry, we are unable to load this page at this time. Please try again later.');
Expand Down
4 changes: 2 additions & 2 deletions __tests__/server/utils/cdnCache.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ describe('cacheUtils', () => {
let logSpy;
let errorSpy;
beforeEach(() => {
logSpy = jest.spyOn(console, 'log');
errorSpy = jest.spyOn(console, 'error');
logSpy = jest.spyOn(console, 'log').mockImplementation(() => {});
errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
});

afterEach(() => {
Expand Down
6 changes: 3 additions & 3 deletions __tests__/server/utils/devCdnFactory.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import util from 'node:util';
import fetch from 'node-fetch';
import fs from 'fs';
import rimraf from 'rimraf';
import { rimrafSync } from 'rimraf';
import path from 'path';
import mkdirp from 'mkdirp';
import { ProxyAgent } from 'proxy-agent';
Expand Down Expand Up @@ -695,8 +695,8 @@ describe('one-app-dev-cdn', () => {
});

afterEach(() => {
rimraf.sync(pathToCache);
rimraf.sync(pathToStubs);
rimrafSync(pathToCache);
rimrafSync(pathToStubs);
});

afterAll(() => {
Expand Down
51 changes: 51 additions & 0 deletions __tests__/server/utils/getIP.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2024 American Express Travel Related Services Company, Inc.
*
* 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
*
* http://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 os from 'os';
import { getIp } from '../../../src/server/utils/getIP';

const spy = jest.spyOn(os, 'networkInterfaces');

describe('getIp', () => {
it('returns a valid IP address', () => {
spy.mockReturnValue({
addresses: [
{
address: '1.1.1.1',
family: 'IPv4',
internal: true,
},
{
address: '2.2.2.2',
family: 'IPv4',
internal: false,
},
{
address: '3.3.3.3',
family: 'IPv6',
internal: false,
},
],
});
expect(getIp()).toBe('2.2.2.2');
});
it('returns 127.0.0.1 if no addresses found', () => {
spy.mockReturnValue({
addresses: [],
});
expect(getIp()).toBe('127.0.0.1');
});
});
52 changes: 38 additions & 14 deletions __tests__/server/utils/logging/config/otel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import pino from 'pino';
import ThreadStream from 'thread-stream';
import otelConfig, {
createOtelTransport,
} from '../../../../../src/server/utils/logging/config/otel';
Expand All @@ -33,18 +34,13 @@ jest.mock('node:os', () => ({

jest.spyOn(pino, 'transport');

describe('OpenTelemetry logging', () => {
const originalNodeEnv = process.env.NODE_ENV;
jest.spyOn(console, 'error').mockImplementation(() => {});

describe('OpenTelemetry logging', () => {
beforeEach(() => {
process.env.NODE_ENV = 'production';
jest.clearAllMocks();
});

afterAll(() => {
process.env.NODE_ENV = originalNodeEnv;
});

describe('config', () => {
it('should serialize errors', () => {
expect(otelConfig.serializers.err).toBe(serializeError);
Expand Down Expand Up @@ -101,6 +97,7 @@ describe('OpenTelemetry logging', () => {
it('should include custom resource attributes', () => {
process.env.OTEL_RESOURCE_ATTRIBUTES = 'service.custom.id=XXXXX;deployment.env=qa';
const transport = createOtelTransport();
expect(transport).toBeInstanceOf(ThreadStream);
expect(pino.transport).toHaveBeenCalledTimes(1);
expect(pino.transport.mock.calls[0][0].options.resourceAttributes).toMatchInlineSnapshot(`
{
Expand All @@ -121,6 +118,7 @@ describe('OpenTelemetry logging', () => {
expect(() => {
transport = createOtelTransport();
}).not.toThrow();
expect(transport).toBeInstanceOf(ThreadStream);
expect(pino.transport).toHaveBeenCalledTimes(1);
expect(pino.transport.mock.calls[0][0]).toMatchInlineSnapshot(`
{
Expand Down Expand Up @@ -148,9 +146,25 @@ describe('OpenTelemetry logging', () => {
});
});

it('should include the console exporter in development', () => {
process.env.NODE_ENV = 'development';
it('should include the grpc exporter and not the console exporter by default', () => {
const transport = createOtelTransport();
expect(transport).toBeInstanceOf(ThreadStream);
expect(pino.transport).toHaveBeenCalledTimes(1);
expect(pino.transport.mock.calls[0][0].options.logRecordProcessorOptions)
.toMatchInlineSnapshot(`
{
"exporterOptions": {
"protocol": "grpc",
},
"recordProcessorType": "batch",
}
`);
expect(pino.transport.mock.results[0].value).toBe(transport);
});

it('should include the console exporter when console is true', () => {
const transport = createOtelTransport({ console: true });
expect(transport).toBeInstanceOf(ThreadStream);
expect(pino.transport).toHaveBeenCalledTimes(1);
expect(pino.transport.mock.calls[0][0].options.logRecordProcessorOptions)
.toMatchInlineSnapshot(`
Expand All @@ -172,19 +186,29 @@ describe('OpenTelemetry logging', () => {
expect(pino.transport.mock.results[0].value).toBe(transport);
});

it('should not include the console exporter in production', () => {
process.env.NODE_ENV = 'production';
const transport = createOtelTransport();
it('should include the console exporter and not the grpc exporter when console is true and grpc is false', () => {
const transport = createOtelTransport({ grpc: false, console: true });
expect(transport).toBeInstanceOf(ThreadStream);
expect(pino.transport).toHaveBeenCalledTimes(1);
expect(pino.transport.mock.calls[0][0].options.logRecordProcessorOptions)
.toMatchInlineSnapshot(`
{
"exporterOptions": {
"protocol": "grpc",
"protocol": "console",
},
"recordProcessorType": "batch",
"recordProcessorType": "simple",
}
`);
expect(pino.transport.mock.results[0].value).toBe(transport);
});

it('should log an error and return undefined when attempting to create a transport with no exporter', () => {
const transport = createOtelTransport({ grpc: false });
expect(transport).toBe(undefined);
expect(pino.transport).not.toHaveBeenCalled();
expect(console.error).toHaveBeenCalledTimes(1);
expect(console.error.mock.calls[0][0]).toMatchInlineSnapshot(
'"OTEL DISABLED: attempted to create OpenTelemetry transport without including a processor"'
);
});
});
Loading

0 comments on commit 74b64c2

Please sign in to comment.