Skip to content

Commit 2db8226

Browse files
committed
chore: run API tests in parallel
* Finally got roud to this, massive performance improvements
1 parent 43bce1f commit 2db8226

File tree

28 files changed

+150
-394
lines changed

28 files changed

+150
-394
lines changed

.env.example

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
ATLAS_CLUSTER_URI=test
2+
AUTH0_DOMAIN=test
3+
4+
SESSION_SECRET=test
5+
6+
OPEN_FIGI_KEY=test
7+
8+
PLAID_CLIENT_ID=test
9+
PLAID_CLIENT_SECRET=test
10+
PLAID_ENV=sandbox
11+
12+
NODE_ENV=development
13+
14+
POLYGON_REST_URI=https://api.polygon.io/
15+
POLYGON_API_KEY=test
16+
API_URL=test
17+
18+
AUTH0_DOMAIN=test
19+
AUTH0_CLIENT_ID=test
20+
AUTH0_CALLBACK_URL=test
21+
AUTH0_CLIENT_SECRET=test
22+
AUTH0_AUDIENCE=test

.github/workflows/tests.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,3 @@ jobs:
7272

7373
- name: ⚡ Run tests
7474
run: yarn test
75-
env:
76-
OPEN_FIGI_KEY: ${{ secrets.OPEN_FIGI_KEY }}
77-
PLAID_ENV: ${{ secrets.PLAID_ENV }}
78-
PLAID_CLIENT_ID: ${{ secrets.PLAID_CLIENT_ID }}
79-
PLAID_CLIENT_SECRET: ${{ secrets.PLAID_CLIENT_SECRET }}

apps/api/jest.config.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@ const { compilerOptions } = require('./tsconfig.build.json');
33
module.exports = {
44
preset: 'jest-preset',
55
rootDir: '.',
6-
globals: {
7-
'ts-jest': {
8-
tsconfig: '<rootDir>/tsconfig.spec.json',
9-
astTransformers: {
10-
before: ['<rootDir>/tests/e2e-transformer.js'],
6+
transform: {
7+
'^.+\\.[tj]s$': [
8+
'ts-jest',
9+
{
10+
tsconfig: '<rootDir>/tsconfig.spec.json',
11+
astTransformers: {
12+
before: ['<rootDir>/tests/e2e-transformer.js'],
13+
},
1114
},
12-
},
15+
],
1316
},
14-
setupFilesAfterEnv: ['<rootDir>/tests/jest/setup.ts'],
17+
// globalSetup: '<rootDir>/tests/jest/globalSetup.ts',
18+
// globalTeardown: '<rootDir>/tests/jest/globalTeardown.ts',
19+
setupFilesAfterEnv: ['<rootDir>/tests/jest/setupFilesAfterEnv.ts'],
1520
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
1621
prefix: '<rootDir>/',
1722
}),

apps/api/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"scripts": {
55
"build": "nest build",
66
"dev": "NODE_ENV=development nest start --watch",
7-
"test": "jest --runInBand",
7+
"test": "jest --forceExit",
88
"lint": "eslint src",
99
"type-check": "tsc -p ./tsconfig.build.json --noEmit",
1010
"docker": "docker buildx build ../../ -f ./Dockerfile -t eu.gcr.io/baggers-367917/api:latest --cache-from type=gha --cache-to type=gha,mode=max --push",
@@ -51,6 +51,7 @@
5151
"eslint-config-baggers": "*",
5252
"mongodb-memory-server": "^8.10.0",
5353
"timekeeper": "^2.2.0",
54-
"ts-jest": "^29.0.3"
54+
"ts-jest": "^29.0.3",
55+
"tsconfig-paths": "^4.1.0"
5556
}
56-
}
57+
}

apps/api/src/app.module.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,10 @@ import { PolygonService } from './polygon/polygon.service';
2020
import { PolygonModule } from './polygon/polygon.module';
2121
import { env } from './env/env.schema';
2222

23-
import { MongoMemoryServer } from 'mongodb-memory-server';
24-
2523
@Module({
2624
imports: [
2725
AuthModule,
28-
MongooseModule.forRootAsync({
29-
useFactory: async () => {
30-
const mongod = await MongoMemoryServer.create();
31-
32-
const uri = mongod.getUri();
33-
console.log(uri);
34-
35-
return {
36-
uri,
37-
};
38-
},
39-
}),
26+
MongooseModule.forRoot(env.ATLAS_CLUSTER_URI),
4027
GraphQLModule.forRoot<ApolloDriverConfig>({
4128
driver: ApolloDriver,
4229
autoSchemaFile:

apps/api/src/portfolios/portfolios.service.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ export class PortfoliosService {
115115
...p,
116116
holdings: undefined,
117117
transactions: undefined,
118-
top5Holdings: p.holdings.slice(0, 5),
119118
}));
120119
}
121120

apps/api/tests/global.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import { MongoMemoryServer } from 'mongodb-memory-server';
2+
13
export interface global {}
24
declare global {
3-
var __MONGOD__: any;
5+
var __MONGOD__: MongoMemoryServer;
46
}

apps/api/tests/jest/globalSetup.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { INestApplication } from '@nestjs/common';
2+
import { register } from 'tsconfig-paths';
3+
register();
4+
import { setupTestApp } from '../util/db-util';
5+
6+
let app: INestApplication;
7+
8+
export const getApp = () => app;
9+
10+
module.exports = async function () {
11+
if (!app) {
12+
app = await setupTestApp();
13+
console.log('Connected to app, url is ', await app.getUrl());
14+
}
15+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = async function () {
2+
await globalThis.__MONGOD__.stop();
3+
await globalThis.__APP__.close();
4+
};

apps/api/tests/jest/mocks.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)