Skip to content

Commit

Permalink
refactor(server): e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasm91 committed Jan 10, 2024
1 parent b5a0397 commit ea5491a
Show file tree
Hide file tree
Showing 50 changed files with 855 additions and 434 deletions.
23 changes: 20 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,25 @@ concurrency:
cancel-in-progress: true

jobs:
e2e-tests:
name: Server (e2e)
server-e2e-api:
name: Server (e2e-api)
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./server

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Run npm install
run: npm ci

- name: Run e2e tests
run: npm run e2e:api

server-e2e-jobs:
name: Server (e2e-jobs)
runs-on: ubuntu-latest

steps:
Expand All @@ -21,7 +38,7 @@ jobs:
submodules: "recursive"

- name: Run e2e tests
run: make test-server-e2e
run: make server-e2e-jobs

doc-tests:
name: Docs
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ stage:
pull-stage:
docker compose -f ./docker/docker-compose.staging.yml pull

test-server-e2e:
docker compose -f ./server/test/docker-compose.server-e2e.yml up --renew-anon-volumes --abort-on-container-exit --exit-code-from immich-server --remove-orphans --build
server-e2e-jobs:
docker compose -f ./server/e2e/docker-compose.server-e2e.yml up --renew-anon-volumes --abort-on-container-exit --exit-code-from immich-server --remove-orphans --build

prod:
docker compose -f ./docker/docker-compose.prod.yml up --build -V --remove-orphans
Expand Down
6 changes: 3 additions & 3 deletions cli/test/e2e/login-key.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { api } from '@test/api';
import { restoreTempFolder, testApp } from 'immich/test/test-utils';
import { LoginResponseDto } from 'src/api/open-api';
import { APIKeyCreateResponseDto } from '@app/domain';
import { api } from '@test/../e2e/api/client';
import { restoreTempFolder, testApp } from '@test/../e2e/jobs/utils';
import { LoginResponseDto } from 'src/api/open-api';
import LoginKey from 'src/commands/login/key';
import { LoginError } from 'src/cores/errors/login-error';
import { CLI_BASE_OPTIONS, spyOnConsole } from 'test/cli-test-utils';
Expand Down
6 changes: 3 additions & 3 deletions cli/test/e2e/server-info.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { api } from '@test/api';
import { restoreTempFolder, testApp } from 'immich/test/test-utils';
import { APIKeyCreateResponseDto } from '@app/domain';
import { api } from '@test/../e2e/api/client';
import { restoreTempFolder, testApp } from '@test/../e2e/jobs/utils';
import { LoginResponseDto } from 'src/api/open-api';
import ServerInfo from 'src/commands/server-info';
import { APIKeyCreateResponseDto } from '@app/domain';
import { CLI_BASE_OPTIONS, spyOnConsole } from 'test/cli-test-utils';

describe(`server-info (e2e)`, () => {
Expand Down
2 changes: 1 addition & 1 deletion cli/test/e2e/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ export default async () => {
}

process.env.NODE_ENV = 'development';
process.env.IMMICH_CONFIG_FILE = path.normalize(`${__dirname}/../../../server/test/e2e/immich-e2e-config.json`);
process.env.IMMICH_CONFIG_FILE = path.normalize(`${__dirname}/../../../server/e2e/jobs/immich-e2e-config.json`);
process.env.TZ = 'Z';
};
6 changes: 3 additions & 3 deletions cli/test/e2e/upload.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { api } from '@test/api';
import { IMMICH_TEST_ASSET_PATH, restoreTempFolder, testApp } from 'immich/test/test-utils';
import { APIKeyCreateResponseDto } from '@app/domain';
import { api } from '@test/../e2e/api/client';
import { IMMICH_TEST_ASSET_PATH, restoreTempFolder, testApp } from '@test/../e2e/jobs/utils';
import { LoginResponseDto } from 'src/api/open-api';
import Upload from 'src/commands/upload';
import { APIKeyCreateResponseDto } from '@app/domain';
import { CLI_BASE_OPTIONS, spyOnConsole } from 'test/cli-test-utils';

describe(`upload (e2e)`, () => {
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/developer/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ Note that there is a bug in nodejs <20.8 that causes segmentation faults when ru

To perform a full e2e test, you need to run e2e tests inside docker. The easiest way to do that is to run `make test-e2e` in the root directory. This will build and start a docker-compose consisting of the server, microservices, and a postgres database. It will then perform the tests and exit.

If you manually install the dependencies (see the DOCKERFILE) on your development machine, you can also run the full e2e tests manually by setting the `IMMICH_RUN_ALL_TESTS` environment value to true, i.e. `IMMICH_RUN_ALL_TESTS=true npm run test:e2e`.
If you manually install the dependencies (see the DOCKERFILE) on your development machine, you can also run the full e2e tests manually by setting the `IMMICH_RUN_ALL_TESTS` environment value to true, i.e. `IMMICH_RUN_ALL_TESTS=true npm run e2e:jobs`.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"moduleFileExtensions": ["js", "json", "ts"],
"modulePaths": ["<rootDir>"],
"rootDir": "../..",
"globalSetup": "<rootDir>/test/e2e/setup.ts",
"globalSetup": "<rootDir>/e2e/api/setup.ts",
"testEnvironment": "node",
"testRegex": ".e2e-spec.ts$",
"testMatch": ["**/e2e/api/specs/*.e2e-spec.[tj]s"],
"testTimeout": 60000,
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
Expand Down
16 changes: 16 additions & 0 deletions server/e2e/api/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { PostgreSqlContainer } from '@testcontainers/postgresql';

export default async () => {
const pg = await new PostgreSqlContainer('tensorchord/pgvecto-rs:pg14-v0.1.11')
.withDatabase('immich')
.withUsername('postgres')
.withPassword('postgres')
.withReuse()
.withCommand(['-c', 'fsync=off', '-c', 'shared_preload_libraries=vectors.so'])
.start();

process.env.DB_URL = pg.getConnectionUri();
process.env.NODE_ENV = 'development';
process.env.LOG_LEVEL = 'fatal';
process.env.TZ = 'Z';
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { AlbumResponseDto, LoginResponseDto, ReactionType } from '@app/domain';
import { ActivityController } from '@app/immich';
import { AssetFileUploadResponseDto } from '@app/immich/api-v1/asset/response-dto/asset-file-upload-response.dto';
import { ActivityEntity } from '@app/infra/entities';
import { api } from '@test/api';
import { errorStub, userDto, uuidStub } from '@test/fixtures';
import { testApp } from '@test/test-utils';
import request from 'supertest';
import { api } from '../client';
import { testApp } from '../utils';

describe(`${ActivityController.name} (e2e)`, () => {
let server: any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { AlbumResponseDto, LoginResponseDto } from '@app/domain';
import { AlbumController } from '@app/immich';
import { AssetFileUploadResponseDto } from '@app/immich/api-v1/asset/response-dto/asset-file-upload-response.dto';
import { SharedLinkType } from '@app/infra/entities';
import { api } from '@test/api';
import { errorStub, userDto, uuidStub } from '@test/fixtures';
import { testApp } from '@test/test-utils';
import request from 'supertest';
import { api } from '../client';
import { testApp } from '../utils';

const user1SharedUser = 'user1SharedUser';
const user1SharedLink = 'user1SharedLink';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import { AssetController } from '@app/immich';
import { AssetEntity, AssetType, SharedLinkType } from '@app/infra/entities';
import { AssetRepository } from '@app/infra/repositories';
import { INestApplication } from '@nestjs/common';
import { api } from '@test/api';
import { errorStub, userDto, uuidStub } from '@test/fixtures';
import { generateAsset, testApp, today, yesterday } from '@test/test-utils';
import { randomBytes } from 'crypto';
import request from 'supertest';
import { api } from '../client';
import { generateAsset, testApp, today, yesterday } from '../utils';

const makeUploadDto = (options?: { omit: string }): Record<string, any> => {
const dto: Record<string, any> = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AuthController } from '@app/immich';
import { api } from '@test/api';
import {
adminSignupStub,
changePasswordStub,
Expand All @@ -9,8 +8,9 @@ import {
loginStub,
uuidStub,
} from '@test/fixtures';
import { testApp } from '@test/test-utils';
import request from 'supertest';
import { api } from '../client';
import { testApp } from '../utils';

const name = 'Immich Admin';
const password = 'Password123';
Expand Down
Loading

0 comments on commit ea5491a

Please sign in to comment.