Skip to content

Commit

Permalink
Separated tests for each package to have only darkroom use browser
Browse files Browse the repository at this point in the history
  • Loading branch information
Joery-M committed Apr 15, 2024
1 parent 04287de commit ec52f5e
Show file tree
Hide file tree
Showing 13 changed files with 144 additions and 276 deletions.
104 changes: 52 additions & 52 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,57 @@
name: Test

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
push:
branches: ['main']
pull_request:
branches: ['main']

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.12.0] # Latest LTS

steps:
- uses: actions/checkout@v4

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Install pnpm
uses: pnpm/action-setup@v3
with:
version: 8 # Latest major
run_install: false

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install

- name: Build Darkroom
run: pnpm build:darkroom

- name: Build Timeline
run: pnpm build:timeline

- name: Build safelight
run: pnpm build:safelight

- name: Test
run: pnpm test:run
test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.12.0] # Latest LTS

steps:
- uses: actions/checkout@v4

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Install pnpm
uses: pnpm/action-setup@v3
with:
version: 8 # Latest major
run_install: false

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install

- name: Build Darkroom
run: pnpm build:darkroom

- name: Build Timeline
run: pnpm build:timeline

- name: Build safelight
run: pnpm build:safelight

- name: Test
run: pnpm test
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"build:darkroom": "cd packages/darkroom && pnpm build",
"build:timeline": "cd packages/timeline && pnpm build",
"build:safelight": "cd packages/safelight && pnpm build",
"test": "vitest",
"test:run": "vitest run --open false --ui false",
"test": "pnpm run -r test:run",
"dev": "pnpm build:packages && cd packages/safelight && pnpm dev",
"dev:darkroom": "pnpm build:packages && cd packages/darkroom && pnpm dev:web"
},
Expand Down
5 changes: 3 additions & 2 deletions packages/darkroom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"build": "rimraf ./dist/ && vite build && tsc --emitDeclarationOnly",
"build:vite": "vite build",
"build:tsc": "tsc --emitDeclarationOnly",
"test": "vitest"
"test": "vitest",
"test:run": "vitest run --ui false"
},
"dependencies": {
"@endo/static-module-record": "^1.1.1",
Expand Down Expand Up @@ -57,4 +58,4 @@
"vite-plugin-mkcert": "^1.17.5",
"vue-codemirror": "^6.1.1"
}
}
}
1 change: 1 addition & 0 deletions packages/darkroom/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export default defineProject({
test: {
reporters: !process.env.GITHUB_ACTIONS ? ['default', 'github-actions'] : ['default'],
globals: true,
name: 'Darkroom',
browser: {
enabled: true,
headless: true,
Expand Down
8 changes: 7 additions & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
"exports": {
"./*": "./src/*.ts"
},
"scripts": {
"test": "vitest",
"test:run": "vitest run --ui false"
},
"dependencies": {
"@vueuse/core": "^10.9.0",
"@vueuse/shared": "^10.9.0",
Expand All @@ -23,6 +27,8 @@
"@tsconfig/node20": "^20.1.4",
"@types/luxon": "^3.4.2",
"@types/uuid": "^9.0.8",
"@vue/tsconfig": "^0.5.1"
"@vue/tsconfig": "^0.5.1",
"fake-indexeddb": "^5.0.2",
"happy-dom": "^14.7.1"
}
}
8 changes: 7 additions & 1 deletion packages/shared/src/Storage/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ export class SafelightIndexedDB extends Dexie {
project!: Table<StoredProject, string>;

constructor() {
super('SafelightIdb');
// Only during tests
if (global?.vitest) {
super('SafelightIdb', { indexedDB: global.indexedDB, IDBKeyRange: global.IDBKeyRange });
} else {
super('SafelightIdb');
}

this.version(1).stores({
media: 'id, name, contentHash',
project: 'id, name, type'
Expand Down
32 changes: 32 additions & 0 deletions packages/shared/test/Storage/indexedDB/Project.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { IDBKeyRange, indexedDB } from 'fake-indexeddb';
import { expect, test } from 'vitest';
import SimpleProject from '../../../src/Project/SimpleProject';
import IndexedDbStorageController from '../../../src/Storage/IndexedDbStorage';

test('List projects', async () => {
global.indexedDB = indexedDB;
global.IDBKeyRange = IDBKeyRange;

const storage = new IndexedDbStorageController();

const project = new SimpleProject();
await storage.SaveProject(project);

const projects = await storage.getProjects();

expect(projects[0].id).toBe(project.id);
});

test('Retrieve project', async () => {
global.indexedDB = indexedDB;
global.IDBKeyRange = IDBKeyRange;

const storage = new IndexedDbStorageController();

const project = new SimpleProject();
await storage.SaveProject(project);

const loadedProject = await storage.LoadProject(project.id);

expect(loadedProject?.id).toEqual(project.id);
});
8 changes: 3 additions & 5 deletions packages/shared/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ export default defineProject({
test: {
reporters: !process.env.GITHUB_ACTIONS ? ['default', 'github-actions'] : ['default'],
globals: true,
environment: 'jsdom',
environment: 'happy-dom',
name: 'shared',
ui: true,
open: false,
api: {
port: 5125
},
browser: {
name: 'chrome',
enabled: false
}
}
});
7 changes: 4 additions & 3 deletions packages/timeline/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"build": "pnpm \"/build:/\"",
"build:vite": "vite build",
"build:tsc": "vue-tsc --emitDeclarationOnly",
"test": "vitest"
"test": "vitest",
"test:run": "vitest run --ui false"
},
"dependencies": {
"@safelight/shared": "workspace:*",
Expand All @@ -42,10 +43,10 @@
"@vitejs/plugin-vue": "^5.0.4",
"@vue/test-utils": "^2.4.5",
"@vue/tsconfig": "^0.5.1",
"jsdom": "^24.0.0",
"happy-dom": "^14.7.1",
"typescript": "^5.4.5",
"vite": "^5.2.8",
"vitest": "^1.4.0",
"vue-tsc": "^2.0.12"
}
}
}
6 changes: 4 additions & 2 deletions packages/timeline/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export default defineProject({
test: {
reporters: !process.env.GITHUB_ACTIONS ? ['default', 'github-actions'] : ['default'],
globals: true,
environment: 'jsdom',
ui: true
name: 'timeline',
environment: 'happy-dom',
ui: true,
open: false
}
});
Loading

0 comments on commit ec52f5e

Please sign in to comment.