Skip to content

Commit c095e92

Browse files
committed
ci: Fixed mongodb teardown issue in tests
1 parent f9e9998 commit c095e92

File tree

60 files changed

+127
-323
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+127
-323
lines changed

common/config/rush/browser-approved-packages.json

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
"name": "@ckpack/vue-color",
1111
"allowedCategories": [ "core", "lib" ]
1212
},
13+
{
14+
"name": "@css-inline/css-inline-linux-x64-gnu",
15+
"allowedCategories": [ "core" ]
16+
},
1317
{
1418
"name": "@ctrl/tinycolor",
1519
"allowedCategories": [ "lib" ]
@@ -314,6 +318,10 @@
314318
"name": "ts-jest",
315319
"allowedCategories": [ "core", "feature", "lib" ]
316320
},
321+
{
322+
"name": "tsconfig-paths",
323+
"allowedCategories": [ "core" ]
324+
},
317325
{
318326
"name": "tslib",
319327
"allowedCategories": [ "application", "core", "feature", "lib" ]

common/config/rush/pnpm-lock.yaml

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/api/jest.setup.ts

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
import log from 'why-is-node-running';
1+
import 'tsconfig-paths/register';
22
import 'reflect-metadata';
3-
import { useDayJsDateTimeAdapter } from '@lyvely/dates';
3+
import { setupTests } from '@/testing';
44

5-
useDayJsDateTimeAdapter();
6-
7-
afterAll(async () => {
8-
//normal cleanup things
9-
await new Promise((resolve) => {
10-
setTimeout(() => {
11-
log();
12-
resolve('');
13-
}, 500);
14-
});
15-
});
5+
export default () => setupTests();

packages/core/api/jest.teardown.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { tearDownTests } from '@/testing';
2+
3+
export default async () => await tearDownTests();

packages/core/api/package.json

+7-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"types": "dist/index.d.ts",
1010
"scripts": {
1111
"build": "gulp clean && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json && gulp copyAssets",
12-
"test": "jest --silent",
12+
"test": "jest",
1313
"lint": "eslint -c .eslintrc.cjs \"src/**/*.ts\" --fix",
1414
"format": "prettier src --write",
1515
"prettier": "prettier src --check",
@@ -104,14 +104,14 @@
104104
"depcheck": "^1.4",
105105
"dependency-cruiser": "^14.1",
106106
"bullmq": "5.1.11",
107-
"why-is-node-running": "^2.2.2",
108-
"cross-env": "^7.0"
107+
"cross-env": "^7.0",
108+
"tsconfig-paths": "^4.2.0"
109109
},
110110
"jest": {
111+
"testEnvironment": "node",
111112
"rootDir": ".",
112-
"setupFilesAfterEnv": [
113-
"<rootDir>/jest.setup.ts"
114-
],
113+
"globalSetup": "<rootDir>/jest.setup.ts",
114+
"globalTeardown": "<rootDir>/jest.teardown.ts",
115115
"testRegex": "[^cypress]*\\.spec\\.ts$",
116116
"moduleFileExtensions": [
117117
"js",
@@ -138,7 +138,6 @@
138138
"collectCoverageFrom": [
139139
"src/**/*.ts"
140140
],
141-
"coverageDirectory": "./coverage",
142-
"testEnvironment": "node"
141+
"coverageDirectory": "./coverage"
143142
}
144143
}

packages/core/api/src/app-config/services/app-config.service.spec.ts

-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ describe('AppConfigService', () => {
3838
await testingModule.afterEach();
3939
});
4040

41-
afterAll(async () => {
42-
return testingModule.afterAll();
43-
});
44-
4541
describe('getAppConfig', () => {
4642
it('inject module config', async () => {
4743
const config: IAppConfig<{ test: { someConfig: boolean } }> = appConfigService.getAppConfig(<any>{});

packages/core/api/src/config/lyvely-config.loader.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { promises as fsPromises } from 'fs';
33
import { join, dirname, isAbsolute } from 'path';
44
import { merge } from '@lyvely/common';
55
import { Logger } from '@nestjs/common';
6-
import { MongoClient } from 'mongodb';
6+
//import { MongoClient } from 'mongodb';
77
import { COLLECTION_CONFIG } from './config.constants';
88

99
const logger = new Logger('loadConfigs');
@@ -39,7 +39,7 @@ export const loadConfigs = (
3939

4040
const { uri, dbName } = mergedConfig.mongodb;
4141
logger.log(`Load db config from uri: ${uri} dbName: ${dbName}`);
42-
const client = new MongoClient(uri);
42+
/* const client = new MongoClient(uri);
4343
4444
try {
4545
await client.connect();
@@ -50,7 +50,8 @@ export const loadConfigs = (
5050
return dbConfig || {};
5151
} finally {
5252
await client.close();
53-
}
53+
}*/
54+
return {};
5455
};
5556

5657
return () => {

packages/core/api/src/content/content.module.spec.ts

-4
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ describe('content module', () => {
5353
return testingModule.afterEach();
5454
});
5555

56-
afterAll(async () => {
57-
return testingModule.afterAll();
58-
});
59-
6056
it('should be defined', () => {
6157
expect(contentService).toBeDefined();
6258
expect(contentTypeRegistry).toBeDefined();

packages/core/api/src/content/daos/content.dao.spec.ts

-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ describe('content dao', () => {
3838
return testingModule.afterEach();
3939
});
4040

41-
afterAll(async () => {
42-
return testingModule.afterAll();
43-
});
44-
4541
async function createTestContent(user: User, profile: Profile, testData = 'Testing...') {
4642
const testContent = new TestContent(
4743
{ profile, user },

packages/core/api/src/content/policies/content-read.policy.spec.ts

-4
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ describe('ContentReadPolicy', () => {
5353
return testingModule.afterEach();
5454
});
5555

56-
afterAll(async () => {
57-
return testingModule.afterAll();
58-
});
59-
6056
it('test custom content read policy', async () => {
6157
class TestContent extends Content {
6258
value: string;

packages/core/api/src/content/schemas/content-score.schema.spec.ts

-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ describe('ContentScore', () => {
3838
return testingModule.afterEach();
3939
});
4040

41-
afterAll(async () => {
42-
return testingModule.afterAll();
43-
});
44-
4541
it('should be defined', () => {
4642
expect(ExtendedTestContentScoreModel).toBeDefined();
4743
});

packages/core/api/src/content/schemas/content.schema.spec.ts

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ describe('Content Model', () => {
2121
profile = userAndProfile.profile;
2222
});
2323

24+
afterEach(async () => {
25+
await testingModule.afterEach();
26+
});
27+
2428
describe('constructor', () => {
2529
it('content meta', async () => {
2630
const content = new Content({ profile, user });

packages/core/api/src/content/services/content-permissions.service.spec.ts

-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ describe('ContentPermissionsService', () => {
2626
return testingModule.afterEach();
2727
});
2828

29-
afterAll(async () => {
30-
return testingModule.afterAll();
31-
});
32-
3329
function registerTestPermission(data?: Partial<IProfilePermission>) {
3430
registerPermissions([
3531
{

packages/core/api/src/content/services/content-score.service.spec.ts

-4
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ describe('ContentScoreService', () => {
5454
return testingModule.afterEach();
5555
});
5656

57-
afterAll(async () => {
58-
return testingModule.afterAll();
59-
});
60-
6157
it('should be defined', () => {
6258
expect(contentScoreService).toBeDefined();
6359
});

packages/core/api/src/content/services/content.service.spec.ts

-4
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ describe('content dao', () => {
3434
return testingModule.afterEach();
3535
});
3636

37-
afterAll(async () => {
38-
return testingModule.afterAll();
39-
});
40-
4137
async function createTestContent(user: User, profile: Profile, archived = false) {
4238
const testContent = new TestContent(
4339
{ profile, user },

packages/core/api/src/core/core.module.spec.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ModuleRegistry } from './components';
2-
import { afterAllTests, afterEachTest, createCoreTestingModule } from './testing';
2+
import { afterEachTest, createCoreTestingModule } from './testing';
33
import { TestingModule } from '@nestjs/testing';
44

55
describe('CoreModule', () => {
@@ -17,10 +17,6 @@ describe('CoreModule', () => {
1717
await afterEachTest(TEST_KEY, testingModule);
1818
});
1919

20-
afterAll(async () => {
21-
await afterAllTests();
22-
});
23-
2420
it('registry is defined', () => {
2521
expect(moduleRegistry).toBeDefined();
2622
});

packages/core/api/src/core/db/abstract.dao.discriminator-transformation.spec.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { InjectModel, Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
22
import { AbstractDao } from './abstract.dao';
33
import { Model, TObjectId } from './db.type';
4-
import { createCoreTestingModule, afterEachTest, afterAllTests } from '../testing/core-test.util';
4+
import { createCoreTestingModule, afterEachTest } from '../testing/core-test.util';
55
import { ModelDefinition } from '@nestjs/mongoose/dist/interfaces';
66
import { Injectable } from '@nestjs/common';
77
import { TestingModule } from '@nestjs/testing';
@@ -107,10 +107,6 @@ describe('AbstractDao', () => {
107107
await afterEachTest(TEST_KEY, testingModule);
108108
});
109109

110-
afterAll(async () => {
111-
await afterAllTests();
112-
});
113-
114110
it('should be defined', () => {
115111
expect(dao).toBeDefined();
116112
});

packages/core/api/src/core/db/abstract.dao.spec.ts

-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
EventTester,
88
getObjectId,
99
afterEachTest,
10-
afterAllTests,
1110
} from '../testing/core-test.util';
1211
import { ModelDefinition } from '@nestjs/mongoose/dist/interfaces';
1312
import { Injectable } from '@nestjs/common';
@@ -88,10 +87,6 @@ describe('AbstractDao', () => {
8887
await afterEachTest(TEST_KEY, testingModule);
8988
});
9089

91-
afterAll(async () => {
92-
await afterAllTests();
93-
});
94-
9590
it('should be defined', () => {
9691
expect(dao).toBeDefined();
9792
});

packages/core/api/src/core/db/abstract.dao.transformation.spec.ts

-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
createCoreTestingModule,
66
EventTester,
77
afterEachTest,
8-
afterAllTests,
98
} from '../testing/core-test.util';
109
import { ModelDefinition } from '@nestjs/mongoose/dist/interfaces';
1110
import { Injectable } from '@nestjs/common';
@@ -123,10 +122,6 @@ describe('AbstractDao Transformations', () => {
123122
await afterEachTest(TEST_KEY, testingModule);
124123
});
125124

126-
afterAll(async () => {
127-
await afterAllTests();
128-
});
129-
130125
describe('transform', () => {
131126
it('transform on findById', async () => {
132127
const v1Model = await ModelV1.create(new TestEntityV1({ numberField: 3 }));

packages/core/api/src/core/services/url-generator.service.spec.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { UrlGenerator } from './url-generator.service';
2-
import { afterAllTests, afterEachTest, createCoreTestingModule } from '../testing';
2+
import { afterEachTest, createCoreTestingModule } from '../testing';
33
import { TestingModule } from '@nestjs/testing';
44

55
describe('UrlGenerator', () => {
@@ -17,10 +17,6 @@ describe('UrlGenerator', () => {
1717
await afterEachTest(TEST_KEY, testingModule);
1818
});
1919

20-
afterAll(async () => {
21-
await afterAllTests();
22-
});
23-
2420
it('should be defined', () => {
2521
expect(urlGenerator).toBeDefined();
2622
});

packages/core/api/src/features/guards/feature.guard.spec.ts

-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { FeatureType } from "@lyvely/interface";
88
describe('ProfileGuard', () => {
99
let testingModule: ILyvelyTestingModule;
1010
let featureGuard: FeatureGuard;
11-
//let featureRegistry: FeatureRegistry;
1211
let context: ExecutionContext;
1312

1413
const TEST_KEY = 'feature-guard';
@@ -23,9 +22,6 @@ describe('ProfileGuard', () => {
2322
return testingModule.afterEach();
2423
});
2524

26-
afterAll(async () => {
27-
return testingModule.afterAll();
28-
});
2925
describe('canActivate()', () => {
3026
it('enabled class level global feature', async () => {
3127
registerFeatures([

packages/core/api/src/files/services/storage.service.spec.ts

-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ describe('StorageService', () => {
2828
return testingModule.afterEach();
2929
});
3030

31-
afterAll(async () => {
32-
return testingModule.afterAll();
33-
});
34-
3531
class TestProvider extends StorageProvider<any> {
3632
async upload(upload: FileUpload): Promise<void> {
3733
/** Nothing to do **/

packages/core/api/src/i18n/components/i18n.component.spec.ts

-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ describe('I18n', () => {
1717
return testingModule.afterEach();
1818
});
1919

20-
afterAll(async () => {
21-
return testingModule.afterAll();
22-
});
23-
2420
it('should be defined', () => {
2521
expect(i18n).toBeDefined();
2622
});

packages/core/api/src/i18n/loaders/i18n.module.loader.spec.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
import { buildTest } from '@/testing';
1+
import { buildTest, ILyvelyTestingModule } from '@/testing';
22
import { i18nITestPlugin } from '../testing';
33
import { I18n } from '../components';
44

55
describe('I18nModuleLoader', () => {
66
let i18n: I18n;
7+
let testingModule: ILyvelyTestingModule;
78

89
beforeEach(async () => {
9-
const test = await buildTest('I18nModuleLoader').plugins([i18nITestPlugin]).compile();
10-
i18n = test.get(I18n);
10+
testingModule = await buildTest('I18nModuleLoader').plugins([i18nITestPlugin]).compile();
11+
i18n = testingModule.get(I18n);
1112
}, 50000);
1213

14+
afterEach(async () => {
15+
await testingModule.afterEach();
16+
});
17+
1318
it('Test module prefix', async () => {
1419
const translation = i18n.t('i18n.test.hello', { locale: 'de' });
1520
expect(translation).toEqual('Hallo');

0 commit comments

Comments
 (0)