Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: no experimental vm modules #6719

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions docs/docs/developer/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,3 @@ The API e2e tests spin up a test database and execute http requests against the
#### Jobs (e2e)

The Jobs e2e tests spin up a docker test environment where thumbnail generation, library scanning, and other _job_ workflows are validated.

:::note
Note that there is a bug in nodejs \<20.8 that causes segmentation faults when running these tests. If you run into segfaults, ensure you are using at least version 20.8.
:::
/follow
2 changes: 1 addition & 1 deletion server/bin/immich-test
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env bash
NODE_OPTIONS='--experimental-vm-modules' node /usr/src/app/node_modules/.bin/jest --config e2e/$1/jest-e2e.json --runInBand
node /usr/src/app/node_modules/.bin/jest --config e2e/$1/jest-e2e.json --runInBand
60 changes: 41 additions & 19 deletions server/e2e/jobs/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IJobRepository, JobItem, JobItemHandler, QueueName } from '@app/domain';
import { IJobRepository, IMediaRepository, JobItem, JobItemHandler, QueueName } from '@app/domain';
import { AppModule } from '@app/immich';
import { InfraModule, InfraTestModule, dataSource } from '@app/infra';
import { MediaRepository } from '@app/infra/repositories';
import { INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import { DateTime } from 'luxon';
Expand Down Expand Up @@ -53,7 +54,42 @@ export const db = {
},
};

let _handler: JobItemHandler = () => Promise.resolve();
class JobMock implements IJobRepository {
private _handler: JobItemHandler = () => Promise.resolve();
addHandler(_queueName: QueueName, _concurrency: number, handler: JobItemHandler) {
this._handler = handler;
}
addCronJob() {}
updateCronJob() {}
deleteCronJob() {}
validateCronExpression() {}
queue(item: JobItem) {
return this._handler(item);
}
queueAll(items: JobItem[]) {
return Promise.all(items.map(this._handler)).then(() => Promise.resolve());
}
async resume() {}
async empty() {}
async setConcurrency() {}
async getQueueStatus() {
return null as any;
}
async getJobCounts() {
return null as any;
}
async pause() {}
async clear() {
return [];
}
async waitForQueueCompletion() {}
}

class MediaMockRepository extends MediaRepository {
async generateThumbhash() {
return Buffer.from('mock-thumbhash');
}
}

let app: INestApplication;

Expand All @@ -63,23 +99,9 @@ export const testApp = {
.overrideModule(InfraModule)
.useModule(InfraTestModule)
.overrideProvider(IJobRepository)
.useValue({
addHandler: (_queueName: QueueName, _concurrency: number, handler: JobItemHandler) => (_handler = handler),
addCronJob: jest.fn(),
updateCronJob: jest.fn(),
deleteCronJob: jest.fn(),
validateCronExpression: jest.fn(),
queue: (item: JobItem) => _handler(item),
queueAll: (items: JobItem[]) => Promise.all(items.map(_handler)).then(() => Promise.resolve()),
resume: jest.fn(),
empty: jest.fn(),
setConcurrency: jest.fn(),
getQueueStatus: jest.fn(),
getJobCounts: jest.fn(),
pause: jest.fn(),
clear: jest.fn(),
waitForQueueCompletion: jest.fn(),
} as IJobRepository)
.useClass(JobMock)
.overrideProvider(IMediaRepository)
.useClass(MediaMockRepository)
.compile();

app = await moduleFixture.createNestApplication().init();
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"e2e:jobs": "NODE_OPTIONS='--experimental-vm-modules' jest --config e2e/jobs/jest-e2e.json --runInBand",
"e2e:jobs": "jest --config e2e/jobs/jest-e2e.json --runInBand",
"e2e:api": "jest --config e2e/api/jest-e2e.json --runInBand",
"typeorm": "typeorm",
"typeorm:migrations:create": "typeorm migration:create",
Expand Down
Loading