Skip to content

Commit

Permalink
[RND-496] Use global setup for jest (#233)
Browse files Browse the repository at this point in the history
* Global setTimeout
* Fixing lint errors
* Fixing dev mode message
  • Loading branch information
andonyns authored Apr 18, 2023
1 parent 2d0121b commit dc1b4b1
Show file tree
Hide file tree
Showing 45 changed files with 23 additions and 86 deletions.
3 changes: 2 additions & 1 deletion Meadowlark-js/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ node_modules/
jest.ci-config.js
jest.e2e-config.js
jest-mongodb-config.js
jest.config.js
jest.config.js
global-setup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const rootDir = '../../../../../';
// eslint-disable-next-line import/no-extraneous-dependencies
const defaultConfig = require('../../../../../tests/config/jest.config');
const defaultConfig = require(`${rootDir}/tests/config/jest.config`);

module.exports = {
displayName: 'Integration Tests: Mongodb',
Expand All @@ -15,5 +16,6 @@ module.exports = {
statements: 60,
},
},
rootDir,
workerIdleMemoryLimit: '200MB',
};
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import { deleteDocumentById } from '../../src/repository/Delete';
import { upsertDocument } from '../../src/repository/Upsert';
import { setupConfigForIntegration } from './Config';

jest.setTimeout(40000);

const newUpsertRequest = (): UpsertRequest => ({
meadowlarkId: '' as MeadowlarkId,
resourceInfo: NoResourceInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import { rejectByOwnershipSecurity } from '../../src/repository/OwnershipSecurit
import { upsertDocument } from '../../src/repository/Upsert';
import { setupConfigForIntegration } from './Config';

jest.setTimeout(40000);

describe('given the getById where resource info is a Descriptor', () => {
let client;
let result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import { getDocumentById } from '../../src/repository/Get';
import { upsertDocument } from '../../src/repository/Upsert';
import { setupConfigForIntegration } from './Config';

jest.setTimeout(40000);

const newGetRequest = (): GetRequest => ({
documentUuid: '' as DocumentUuid,
resourceInfo: NoResourceInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import { securityMiddleware } from '../../src/security/SecurityMiddleware';
import { upsertDocument } from '../../src/repository/Upsert';
import { setupConfigForIntegration } from './Config';

jest.setTimeout(40000);

describe('given the upsert where no document id is specified', () => {
let client;
let result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import { updateDocumentById } from '../../src/repository/Update';
import { upsertDocument } from '../../src/repository/Upsert';
import { setupConfigForIntegration } from './Config';

jest.setTimeout(40000);

const newUpdateRequest = (): UpdateRequest => ({
meadowlarkId: '' as MeadowlarkId,
documentUuid: '' as DocumentUuid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ import { getDocumentCollection, getNewClient } from '../../src/repository/Db';
import { upsertDocument } from '../../src/repository/Upsert';
import { setupConfigForIntegration } from './Config';

jest.setTimeout(40000);

const newUpsertRequest = (): UpsertRequest => ({
meadowlarkId: '' as MeadowlarkId,
resourceInfo: NoResourceInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import { getAuthorizationCollection, getNewClient } from '../../../src/repositor
import { createAuthorizationClientDocument } from '../../../src/repository/authorization/CreateAuthorizationClient';
import { setupConfigForIntegration } from '../Config';

jest.setTimeout(40000);

const clientId = 'clientId';

const newCreateAuthorizationClientRequest = (): CreateAuthorizationClientRequest => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import { createAuthorizationClientDocument } from '../../../src/repository/autho
import { getAllAuthorizationClientDocuments } from '../../../src/repository/authorization/GetAllAuthorizationClients';
import { setupConfigForIntegration } from '../Config';

jest.setTimeout(40000);

const clientId = 'clientId';

const TRACE_ID = 'traceId';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import { createAuthorizationClientDocument } from '../../../src/repository/autho
import { getAuthorizationClientDocument } from '../../../src/repository/authorization/GetAuthorizationClient';
import { setupConfigForIntegration } from '../Config';

jest.setTimeout(40000);

const clientId = 'clientId';

const newCreateAuthorizationClientRequest = (): CreateAuthorizationClientRequest => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import { createAuthorizationClientDocument } from '../../../src/repository/autho
import { AuthorizationDocument } from '../../../src/model/AuthorizationDocument';
import { setupConfigForIntegration } from '../Config';

jest.setTimeout(40000);

const clientId = 'clientId';
const clientIdDifferent = 'clientIdDifferent';
const clientIdSame = 'clientIdSame';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import { getAuthorizationCollection, getNewClient } from '../../../src/repositor
import { tryCreateBootstrapAuthorizationAdminDocument } from '../../../src/repository/authorization/TryCreateBootstrapAuthorizationAdmin';
import { setupConfigForIntegration } from '../Config';

jest.setTimeout(40000);

const clientId = 'clientId';

const newCreateAuthorizationClientRequest = (): CreateAuthorizationClientRequest => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import { updateAuthorizationClientDocument } from '../../../src/repository/autho
import { createAuthorizationClientDocument } from '../../../src/repository/authorization/CreateAuthorizationClient';
import { setupConfigForIntegration } from '../Config';

jest.setTimeout(40000);

const clientIdSame = 'clientIdSame';
const clientIdDifferent = 'clientIdDifferent';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ import {
import { upsertDocument } from '../../../src/repository/Upsert';
import { setupConfigForIntegration } from '../Config';

jest.setTimeout(10000);

const documentUuid = '2edb604f-eab0-412c-a242-508d6529214d' as DocumentUuid;

// A bunch of setup stuff
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { newPathComponents } from '@edfi/meadowlark-core/src/model/PathComponent
import { securityMiddleware } from '../../src/security/SecurityMiddleware';
import * as OwnershipSecurity from '../../src/repository/OwnershipSecurity';

jest.setTimeout(40000);

describe('given the upsert where response already posted', () => {
let result;
const mongoClientMock = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import * as utilities from '@edfi/meadowlark-utilities';
import { deleteDocumentById } from '../../src/repository/Delete';
import * as DB from '../../src/repository/Db';

jest.setTimeout(40000);

describe('given a transaction on a resource', () => {
const retryNumberOfTimes = 2;
let mongoClientMock = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import * as utilities from '@edfi/meadowlark-utilities';
import { updateDocumentById } from '../../src/repository/Update';
import * as DB from '../../src/repository/Db';

jest.setTimeout(40000);

describe('given a transaction on a resource', () => {
const retryNumberOfTimes = 2;
let mongoClientMock = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import * as utilities from '@edfi/meadowlark-utilities';
import { upsertDocument } from '../../src/repository/Upsert';
import * as DB from '../../src/repository/Db';

jest.setTimeout(40000);

describe('given a transaction on a resource', () => {
const retryNumberOfTimes = 2;
let mongoClientMock = {};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const rootDir = '../../../../../';
// eslint-disable-next-line import/no-extraneous-dependencies
const defaultConfig = require('../../../../../tests/config/jest.config');
const defaultConfig = require(`${rootDir}/tests/config/jest.config`);

module.exports = {
displayName: 'Integration Tests: OpenSearch',
globalSetup: './test/setup/Setup.ts',
globalTeardown: './test/setup/Teardown.ts',
globalSetup: '<rootDir>/backends/meadowlark-opensearch-backend/test/setup/Setup.ts',
globalTeardown: '<rootDir>/backends/meadowlark-opensearch-backend/test/setup/Teardown.ts',
...defaultConfig,
testMatch: ['**/meadowlark-opensearch-backend/test/integration/**/*.(spec|test).[jt]s?(x)'],
coverageThreshold: {
Expand All @@ -15,5 +16,6 @@ module.exports = {
statements: 60,
},
},
rootDir,
workerIdleMemoryLimit: '200MB',
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const rootDir = '../../../../../';
// eslint-disable-next-line import/no-extraneous-dependencies
const defaultConfig = require('../../../../../tests/config/jest.config');
const defaultConfig = require(`${rootDir}/tests/config/jest.config`);

module.exports = {
displayName: 'Integration Tests: Postgresql',
Expand All @@ -13,5 +14,6 @@ module.exports = {
statements: 60,
},
},
rootDir,
workerIdleMemoryLimit: '200MB',
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import type { PoolClient, QueryResult } from 'pg';
import { resetSharedClient, getSharedClient } from '../../src/repository/Db';
import { setupConfigForIntegration } from './Config';

jest.setTimeout(40000);

describe('Test Connection to Postgres Successful', () => {
let client: PoolClient;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ import { upsertDocument } from '../../src/repository/Upsert';
import { findDocumentByIdSql } from '../../src/repository/SqlHelper';
import { setupConfigForIntegration } from './Config';

jest.setTimeout(40000);

const newUpsertRequest = (): UpsertRequest => ({
meadowlarkId: '' as MeadowlarkId,
resourceInfo: NoResourceInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import { upsertDocument } from '../../src/repository/Upsert';
import { SecurityResult } from '../../src/security/SecurityResult';
import { setupConfigForIntegration } from './Config';

jest.setTimeout(40000);

describe('given the upsert where no document id is specified', () => {
let client: PoolClient;
let result: SecurityResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import { findDocumentByIdSql } from '../../src/repository/SqlHelper';
import { upsertDocument } from '../../src/repository/Upsert';
import { setupConfigForIntegration } from './Config';

jest.setTimeout(40000);

const newGetRequest = (): GetRequest => ({
documentUuid: 'deb6ea15-fa93-4389-89a8-1428fb617490' as DocumentUuid,
resourceInfo: NoResourceInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ import { upsertDocument } from '../../src/repository/Upsert';
import { deleteAll } from './TestHelper';
import { setupConfigForIntegration } from './Config';

jest.setTimeout(40000);

describe('given the upsert where no document id is specified', () => {
let client: PoolClient;
let result: MiddlewareModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ import { getDocumentById } from '../../src/repository/Get';
import { findDocumentByIdSql } from '../../src/repository/SqlHelper';
import { setupConfigForIntegration } from './Config';

jest.setTimeout(40000);

const newUpsertRequest = (): UpsertRequest => ({
meadowlarkId: '' as MeadowlarkId,
resourceInfo: NoResourceInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ import { upsertDocument } from '../../src/repository/Upsert';
import { setupConfigForIntegration } from './Config';
import { deleteAll, retrieveReferencesByDocumentIdSql, verifyAliasId } from './TestHelper';

jest.setTimeout(40000);

const newUpsertRequest = (): UpsertRequest => ({
meadowlarkId: '' as MeadowlarkId,
resourceInfo: NoResourceInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ import { upsertDocument } from '../../../src/repository/Upsert';
import { deleteAll } from '../TestHelper';
import { setupConfigForIntegration } from '../Config';

jest.setTimeout(10000);

// A bunch of setup stuff
const newUpsertRequest = (): UpsertRequest => ({
meadowlarkId: '' as MeadowlarkId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import { FrontendRequest, newFrontendRequest, newFrontendRequestMiddleware } fro
import { MiddlewareModel } from '../../src/middleware/MiddlewareModel';
import { setupMockConfiguration } from '../ConfigHelper';

jest.setTimeout(40000);

const newAxiosResponse = () => ({ status: 0, data: {}, headers: {}, config: {}, statusText: '' });

describe('given a previous middleware has created a response', () => {
Expand Down
2 changes: 0 additions & 2 deletions Meadowlark-js/services/meadowlark-fastify/test/Delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import * as MeadowlarkConnection from '../src/handler/MeadowlarkConnection';
import { buildService } from '../src/Service';
import { setupMockConfiguration } from './ConfigHelper';

jest.setTimeout(40000);

describe('given a DELETE of a school by id', () => {
const schoolDeleteByIdRequest: InjectOptions = {
method: 'DELETE',
Expand Down
2 changes: 0 additions & 2 deletions Meadowlark-js/services/meadowlark-fastify/test/Get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import * as MeadowlarkConnection from '../src/handler/MeadowlarkConnection';
import { buildService } from '../src/Service';
import { setupMockConfiguration } from './ConfigHelper';

jest.setTimeout(40000);

describe('given a GET', () => {
let mockGet: any;
let service: FastifyInstance;
Expand Down
2 changes: 0 additions & 2 deletions Meadowlark-js/services/meadowlark-fastify/test/Post.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import * as MeadowlarkConnection from '../src/handler/MeadowlarkConnection';
import { buildService } from '../src/Service';
import { setupMockConfiguration } from './ConfigHelper';

jest.setTimeout(40000);

const schoolPostRequest: InjectOptions = {
method: 'POST',
url: '/local/v3.3b/ed-fi/schools',
Expand Down
2 changes: 0 additions & 2 deletions Meadowlark-js/services/meadowlark-fastify/test/Put.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import { buildService } from '../src/Service';
import { setupMockConfiguration } from './ConfigHelper';
import * as MeadowlarkConnection from '../src/handler/MeadowlarkConnection';

jest.setTimeout(40000);

const schoolPutRequest: InjectOptions = {
method: 'PUT',
url: '/local/v3.3b/ed-fi/schools',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import * as MeadowlarkConnection from '../../src/handler/MeadowlarkConnection';
import { buildService } from '../../src/Service';
import { setupMockConfiguration } from '../ConfigHelper';

jest.setTimeout(40000);

const createClientRequest: InjectOptions = {
method: 'POST',
url: '/local/oauth/clients',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import * as MeadowlarkConnection from '../../src/handler/MeadowlarkConnection';
import { buildService } from '../../src/Service';
import { setupMockConfiguration } from '../ConfigHelper';

jest.setTimeout(40000);

const requestTokenRequest: InjectOptions = {
method: 'POST',
url: '/local/oauth/token',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import * as MeadowlarkConnection from '../../src/handler/MeadowlarkConnection';
import { buildService } from '../../src/Service';
import { setupMockConfiguration } from '../ConfigHelper';

jest.setTimeout(40000);

const updateClientRequest: InjectOptions = {
method: 'PUT',
url: '/local/oauth/clients/890',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import * as MeadowlarkConnection from '../../src/handler/MeadowlarkConnection';
import { buildService } from '../../src/Service';
import { setupMockConfiguration } from '../ConfigHelper';

jest.setTimeout(40000);

const verifyTokenRequest: InjectOptions = {
method: 'POST',
url: '/local/oauth/verify',
Expand Down
2 changes: 1 addition & 1 deletion Meadowlark-js/tests/config/e2e/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// eslint-disable-next-line import/no-extraneous-dependencies
const defaultConfig = require('./../jest.config.js');
const defaultConfig = require('../jest.config.js');

module.exports = {
displayName: 'E2E Tests',
Expand Down
1 change: 1 addition & 0 deletions Meadowlark-js/tests/config/global-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jest.setTimeout(40000)
1 change: 1 addition & 0 deletions Meadowlark-js/tests/config/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ module.exports = {
transformIgnorePatterns: ['<rootDir>.*(node_modules)(?!.*meadowlark-.*).*$'],
modulePathIgnorePatterns: ['dist*', 'docs*'],
setupFiles: ['dotenv/config'],
setupFilesAfterEnv: ['<rootDir>/tests/config/global-setup.js'],
rootDir: '../../..',
};
Loading

0 comments on commit dc1b4b1

Please sign in to comment.