Skip to content

Commit

Permalink
chore: Upgrade nock and delete nock related boilerplate code (no-chan…
Browse files Browse the repository at this point in the history
…gelog) (#12869)
  • Loading branch information
netroy authored Jan 27, 2025
1 parent 0bb65f2 commit f64c6bf
Show file tree
Hide file tree
Showing 154 changed files with 75 additions and 1,483 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"jest-mock": "^29.6.2",
"jest-mock-extended": "^3.0.4",
"lefthook": "^1.7.15",
"nock": "^13.3.2",
"nock": "^14.0.0",
"nodemon": "^3.0.1",
"npm-run-all2": "^7.0.2",
"p-limit": "^3.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/node-execute-functions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ describe('NodeExecuteFunctions', () => {
body: 'Not Found',
headers: {},
statusCode: 404,
statusMessage: null,
statusMessage: 'Not Found',
});
expect(hooks.executeHookFunctions).toHaveBeenCalledWith('nodeFetchedData', [
workflow.id,
Expand Down
1 change: 1 addition & 0 deletions packages/nodes-base/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ process.env.TZ = 'UTC';
module.exports = {
...require('../../jest.config'),
collectCoverageFrom: ['credentials/**/*.ts', 'nodes/**/*.ts', 'utils/**/*.ts'],
globalSetup: '<rootDir>/test/globalSetup.ts',
setupFilesAfterEnv: [
'jest-expect-message',
'n8n-workflow/test/setup.ts',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import nock from 'nock';

import * as getMany from '../../../../v2/actions/base/getMany.operation';
import * as transport from '../../../../v2/transport';
import { createMockExecuteFunction } from '../helpers';
Expand Down Expand Up @@ -33,15 +31,6 @@ jest.mock('../../../../v2/transport', () => {
});

describe('Test AirtableV2, base => getMany', () => {
beforeAll(() => {
nock.disableNetConnect();
});

afterAll(() => {
nock.restore();
jest.unmock('../../../../v2/transport');
});

it('should return all bases', async () => {
const nodeParameters = {
resource: 'base',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import nock from 'nock';

import * as getSchema from '../../../../v2/actions/base/getSchema.operation';
import * as transport from '../../../../v2/transport';
import { createMockExecuteFunction } from '../helpers';
Expand All @@ -15,15 +13,6 @@ jest.mock('../../../../v2/transport', () => {
});

describe('Test AirtableV2, base => getSchema', () => {
beforeAll(() => {
nock.disableNetConnect();
});

afterAll(() => {
nock.restore();
jest.unmock('../../../../v2/transport');
});

it('should return all bases', async () => {
const nodeParameters = {
resource: 'base',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import nock from 'nock';

import * as create from '../../../../v2/actions/record/create.operation';
import * as transport from '../../../../v2/transport';
import { createMockExecuteFunction } from '../helpers';
Expand All @@ -15,18 +13,7 @@ jest.mock('../../../../v2/transport', () => {
});

describe('Test AirtableV2, create operation', () => {
beforeAll(() => {
nock.disableNetConnect();
});

afterAll(() => {
nock.restore();
jest.unmock('../../../../v2/transport');
});

afterEach(() => {
jest.restoreAllMocks();
});
beforeEach(() => jest.clearAllMocks());

it('should create a record, autoMapInputData', async () => {
const nodeParameters = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import nock from 'nock';

import * as deleteRecord from '../../../../v2/actions/record/deleteRecord.operation';
import * as transport from '../../../../v2/transport';
import { createMockExecuteFunction } from '../helpers';
Expand All @@ -15,19 +13,6 @@ jest.mock('../../../../v2/transport', () => {
});

describe('Test AirtableV2, deleteRecord operation', () => {
beforeAll(() => {
nock.disableNetConnect();
});

afterAll(() => {
nock.restore();
jest.unmock('../../../../v2/transport');
});

afterEach(() => {
jest.restoreAllMocks();
});

it('should delete a record', async () => {
const nodeParameters = {
operation: 'deleteRecord',
Expand Down
15 changes: 0 additions & 15 deletions packages/nodes-base/nodes/Airtable/test/v2/node/record/get.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import nock from 'nock';

import * as get from '../../../../v2/actions/record/get.operation';
import * as transport from '../../../../v2/transport';
import { createMockExecuteFunction } from '../helpers';
Expand All @@ -23,19 +21,6 @@ jest.mock('../../../../v2/transport', () => {
});

describe('Test AirtableV2, create operation', () => {
beforeAll(() => {
nock.disableNetConnect();
});

afterAll(() => {
nock.restore();
jest.unmock('../../../../v2/transport');
});

afterEach(() => {
jest.restoreAllMocks();
});

it('should create a record, autoMapInputData', async () => {
const nodeParameters = {
operation: 'get',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import nock from 'nock';

import * as search from '../../../../v2/actions/record/search.operation';
import * as transport from '../../../../v2/transport';
import { createMockExecuteFunction } from '../helpers';
Expand Down Expand Up @@ -49,15 +47,6 @@ jest.mock('../../../../v2/transport', () => {
});

describe('Test AirtableV2, search operation', () => {
beforeAll(() => {
nock.disableNetConnect();
});

afterAll(() => {
nock.restore();
jest.unmock('../../../../v2/transport');
});

it('should return all records', async () => {
const nodeParameters = {
operation: 'search',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import nock from 'nock';

import * as update from '../../../../v2/actions/record/update.operation';
import * as transport from '../../../../v2/transport';
import { createMockExecuteFunction } from '../helpers';
Expand Down Expand Up @@ -40,15 +38,6 @@ jest.mock('../../../../v2/transport', () => {
});

describe('Test AirtableV2, update operation', () => {
beforeAll(() => {
nock.disableNetConnect();
});

afterAll(() => {
nock.restore();
jest.unmock('../../../../v2/transport');
});

it('should update a record by id, autoMapInputData', async () => {
const nodeParameters = {
operation: 'update',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ describe('Test AWS Comprehend Node', () => {

await initBinaryDataService();

nock.disableNetConnect();
const baseUrl = 'https://comprehend.eu-central-1.amazonaws.com';

mock = nock(baseUrl);
Expand All @@ -34,9 +33,6 @@ describe('Test AWS Comprehend Node', () => {
beforeEach(async () => {
mock.post('/').reply(200, response);
});
afterAll(() => {
nock.restore();
});

testWorkflows(workflows);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,17 +291,13 @@ describe('Test AWS Rekogntion Node', () => {
let mock: nock.Scope;

beforeAll(async () => {
nock.disableNetConnect();
mock = nock(baseUrl);
});

beforeEach(async () => {
mock.post('/').reply(200, responseLabels);
});

afterAll(() => {
nock.restore();
});
testWorkflows(workflows);
});
});
5 changes: 0 additions & 5 deletions packages/nodes-base/nodes/Aws/S3/test/V1/AwsS3.node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ describe('Test S3 V1 Node', () => {

await initBinaryDataService();

nock.disableNetConnect();
mock = nock('https://bucket.s3.eu-central-1.amazonaws.com');
});

Expand All @@ -40,10 +39,6 @@ describe('Test S3 V1 Node', () => {
.reply(200, { success: true });
});

afterAll(() => {
nock.restore();
});

testWorkflows(workflows);
});
});
5 changes: 0 additions & 5 deletions packages/nodes-base/nodes/Aws/S3/test/V2/AwsS3.node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ describe('Test S3 V2 Node', () => {

await initBinaryDataService();

nock.disableNetConnect();
mock = nock('https://s3.eu-central-1.amazonaws.com/buc.ket');
});

Expand All @@ -40,10 +39,6 @@ describe('Test S3 V2 Node', () => {
.reply(200, { success: true });
});

afterAll(() => {
nock.restore();
});

testWorkflows(workflows);
});
});
4 changes: 0 additions & 4 deletions packages/nodes-base/nodes/Cron/test/Cron.node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ describe('Cron Node', () => {
},
});

afterAll(() => {
jest.resetAllMocks();
});

it('should return a function to trigger', async () => {
expect(await node.trigger.call(triggerFunctions)).toEqual({
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { INodeTypes } from 'n8n-workflow';
import nock from 'nock';

import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
Expand Down Expand Up @@ -31,16 +30,6 @@ discordApiRequestSpy.mockImplementation(async (method: string) => {
describe('Test DiscordV2, channel => create', () => {
const workflows = ['nodes/Discord/test/v2/node/channel/create.workflow.json'];
const tests = workflowToTests(workflows);

beforeAll(() => {
nock.disableNetConnect();
});

afterAll(() => {
nock.restore();
jest.resetAllMocks();
});

const nodeTypes = setup(tests);

const testNode = async (testData: WorkflowTestData, types: INodeTypes) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { INodeTypes } from 'n8n-workflow';
import nock from 'nock';

import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
Expand Down Expand Up @@ -31,16 +30,6 @@ discordApiRequestSpy.mockImplementation(async (method: string) => {
describe('Test DiscordV2, channel => deleteChannel', () => {
const workflows = ['nodes/Discord/test/v2/node/channel/deleteChannel.workflow.json'];
const tests = workflowToTests(workflows);

beforeAll(() => {
nock.disableNetConnect();
});

afterAll(() => {
nock.restore();
jest.resetAllMocks();
});

const nodeTypes = setup(tests);

const testNode = async (testData: WorkflowTestData, types: INodeTypes) => {
Expand Down
11 changes: 0 additions & 11 deletions packages/nodes-base/nodes/Discord/test/v2/node/channel/get.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { INodeTypes, IRequestOptions } from 'n8n-workflow';
import nock from 'nock';

import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
Expand Down Expand Up @@ -46,16 +45,6 @@ requestApiSpy.mockImplementation(
describe('Test DiscordV2, channel => get', () => {
const workflows = ['nodes/Discord/test/v2/node/channel/get.workflow.json'];
const tests = workflowToTests(workflows);

beforeAll(() => {
nock.disableNetConnect();
});

afterAll(() => {
nock.restore();
jest.resetAllMocks();
});

const nodeTypes = setup(tests);

const testNode = async (testData: WorkflowTestData, types: INodeTypes) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { INodeTypes } from 'n8n-workflow';
import nock from 'nock';

import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
Expand Down Expand Up @@ -107,16 +106,6 @@ discordApiRequestSpy.mockImplementation(async (method: string) => {
describe('Test DiscordV2, channel => getAll', () => {
const workflows = ['nodes/Discord/test/v2/node/channel/getAll.workflow.json'];
const tests = workflowToTests(workflows);

beforeAll(() => {
nock.disableNetConnect();
});

afterAll(() => {
nock.restore();
jest.resetAllMocks();
});

const nodeTypes = setup(tests);

const testNode = async (testData: WorkflowTestData, types: INodeTypes) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { INodeTypes } from 'n8n-workflow';
import nock from 'nock';

import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';
import { getResultNodeData, setup, workflowToTests } from '@test/nodes/Helpers';
Expand Down Expand Up @@ -31,16 +30,6 @@ discordApiRequestSpy.mockImplementation(async (method: string, _) => {
describe('Test DiscordV2, channel => update', () => {
const workflows = ['nodes/Discord/test/v2/node/channel/update.workflow.json'];
const tests = workflowToTests(workflows);

beforeAll(() => {
nock.disableNetConnect();
});

afterAll(() => {
nock.restore();
jest.resetAllMocks();
});

const nodeTypes = setup(tests);

const testNode = async (testData: WorkflowTestData, types: INodeTypes) => {
Expand Down
Loading

0 comments on commit f64c6bf

Please sign in to comment.