Skip to content

Commit

Permalink
refactor: cli e2e (#7211)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasm91 committed Feb 19, 2024
1 parent 870d517 commit 947bcf2
Show file tree
Hide file tree
Showing 26 changed files with 442 additions and 500 deletions.
76 changes: 17 additions & 59 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,38 +135,6 @@ jobs:
run: npm run test:cov
if: ${{ !cancelled() }}

cli-e2e-tests:
name: CLI (e2e)
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./cli

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: "recursive"

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20

- name: Run setup typescript-sdk
run: npm ci && npm run build
working-directory: ./open-api/typescript-sdk

- name: Run npm install (cli)
run: npm ci

- name: Run npm install (server)
run: npm ci && npm run build
working-directory: ./server

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

web-unit-tests:
name: Web
runs-on: ubuntu-latest
Expand Down Expand Up @@ -205,8 +173,8 @@ jobs:
run: npm run test:cov
if: ${{ !cancelled() }}

web-e2e-tests:
name: Web (e2e)
e2e-tests:
name: End-to-End Tests
runs-on: ubuntu-latest
defaults:
run:
Expand All @@ -215,11 +183,22 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: "recursive"

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20

- name: Run setup typescript-sdk
run: npm ci && npm run build
working-directory: ./open-api/typescript-sdk

- name: Run setup cli
run: npm ci && npm run build
working-directory: ./cli

- name: Install dependencies
run: npm ci

Expand All @@ -229,32 +208,11 @@ jobs:
- name: Docker build
run: docker compose build

- name: Run e2e tests
run: npx playwright test

api-e2e-tests:
name: API (e2e)
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./e2e
- name: Run e2e tests (api & cli)
run: npm run test

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

- name: Run setup typescript-sdk
run: npm ci && npm run build
working-directory: ./open-api/typescript-sdk

- name: Install dependencies
run: npm ci

- name: Docker build
run: docker compose build

- name: Run e2e tests
run: npm run test:api
- name: Run e2e tests (web)
run: npx playwright test

mobile-unit-tests:
name: Mobile
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ server-e2e-api:

.PHONY: e2e
e2e:
docker compose -f ./docker/docker-compose.e2e.yml up --build -V --remove-orphans
docker compose -f ./e2e/docker-compose.yml up --build -V --remove-orphans

prod:
docker compose -f ./docker/docker-compose.prod.yml up --build -V --remove-orphans
Expand Down
7 changes: 1 addition & 6 deletions cli/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ module.exports = {
'unicorn/prefer-module': 'off',
curly: 2,
'prettier/prettier': 0,
'unicorn/prevent-abbreviations': [
'error',
{
ignore: ['\\.e2e-spec$', /^ignore/i],
},
],
'unicorn/prevent-abbreviations': 'error',
},
};
1 change: 0 additions & 1 deletion cli/.npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
**/*.spec.js
test/**
upload/**
.editorconfig
.eslintignore
Expand Down
100 changes: 1 addition & 99 deletions cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-unicorn": "^51.0.0",
"glob": "^10.3.1",
"immich": "file:../server",
"mock-fs": "^5.2.0",
"prettier": "^3.2.5",
"prettier-plugin-organize-imports": "^3.2.4",
Expand All @@ -41,15 +40,14 @@
},
"scripts": {
"build": "vite build",
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\" --max-warnings 0",
"lint": "eslint \"src/**/*.ts\" --max-warnings 0",
"lint:fix": "npm run lint -- --fix",
"prepack": "npm run build",
"test": "vitest",
"test:cov": "vitest --coverage",
"format": "prettier --check .",
"format:fix": "prettier --write .",
"check": "tsc --noEmit",
"test:e2e": "vitest --config test/e2e/vitest.config.ts"
"check": "tsc --noEmit"
},
"repository": {
"type": "git",
Expand Down
10 changes: 5 additions & 5 deletions cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const program = new Command()
.version(version)
.description('Command line interface for Immich')
.addOption(
new Option('-d, --config-directory', 'Configuration directory where auth.yml will be stored')
new Option('-d, --config-directory <directory>', 'Configuration directory where auth.yml will be stored')
.env('IMMICH_CONFIG_DIR')
.default(defaultConfigDirectory),
);
Expand Down Expand Up @@ -60,10 +60,10 @@ program
program
.command('login-key')
.description('Login using an API key')
.argument('[instanceUrl]')
.argument('[apiKey]')
.action(async (paths, options) => {
await new LoginCommand(program.opts()).run(paths, options);
.argument('url')
.argument('key')
.action(async (url, key) => {
await new LoginCommand(program.opts()).run(url, key);
});

program
Expand Down
44 changes: 34 additions & 10 deletions cli/src/services/session.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,41 @@
import fs from 'node:fs';
import path from 'node:path';
import yaml from 'yaml';
import {
TEST_AUTH_FILE,
TEST_CONFIG_DIR,
TEST_IMMICH_API_KEY,
TEST_IMMICH_INSTANCE_URL,
createTestAuthFile,
deleteAuthFile,
readTestAuthFile,
spyOnConsole,
} from '../../test/cli-test-utils';
import { SessionService } from './session.service';

const TEST_CONFIG_DIR = '/tmp/immich/';
const TEST_AUTH_FILE = path.join(TEST_CONFIG_DIR, 'auth.yml');
const TEST_IMMICH_INSTANCE_URL = 'https://test/api';
const TEST_IMMICH_API_KEY = 'pNussssKSYo5WasdgalvKJ1n9kdvaasdfbluPg';

const spyOnConsole = () => vi.spyOn(console, 'log').mockImplementation(() => {});

const createTestAuthFile = async (contents: string) => {
if (!fs.existsSync(TEST_CONFIG_DIR)) {
// Create config folder if it doesn't exist
const created = await fs.promises.mkdir(TEST_CONFIG_DIR, { recursive: true });
if (!created) {
throw new Error(`Failed to create config folder ${TEST_CONFIG_DIR}`);
}
}

fs.writeFileSync(TEST_AUTH_FILE, contents);
};

const readTestAuthFile = async (): Promise<string> => {
return await fs.promises.readFile(TEST_AUTH_FILE, 'utf8');
};

const deleteAuthFile = () => {
try {
fs.unlinkSync(TEST_AUTH_FILE);
} catch (error: any) {
if (error.code !== 'ENOENT') {
throw error;
}
}
};

const mocks = vi.hoisted(() => {
return {
getMyUserInfo: vi.fn(() => Promise.resolve({ email: 'admin@example.com' })),
Expand Down

0 comments on commit 947bcf2

Please sign in to comment.