diff --git a/globals.d.ts b/globals.d.ts new file mode 100644 index 00000000..9b257065 --- /dev/null +++ b/globals.d.ts @@ -0,0 +1 @@ +declare const __TEST__: boolean; diff --git a/packages/darkroom/tsconfig.json b/packages/darkroom/tsconfig.json index cf4c6458..3fbb398d 100644 --- a/packages/darkroom/tsconfig.json +++ b/packages/darkroom/tsconfig.json @@ -14,6 +14,6 @@ "rootDir": "." }, "files": ["lib/main.ts"], - "include": ["lib/*.ts", "tsconfig.shim.json"], + "include": ["lib/*.ts", "tsconfig.shim.json", "../../globals.d.ts"], "exclude": ["dist"] } diff --git a/packages/darkroom/vite.config.ts b/packages/darkroom/vite.config.ts index 0d762150..fb7fd843 100644 --- a/packages/darkroom/vite.config.ts +++ b/packages/darkroom/vite.config.ts @@ -15,5 +15,8 @@ export default defineConfig({ name: 'darkroom' }, sourcemap: true + }, + define: { + __TEST__: false } }); diff --git a/packages/darkroom/vitest.config.ts b/packages/darkroom/vitest.config.ts index 5d6a2e3d..c73ac8bc 100644 --- a/packages/darkroom/vitest.config.ts +++ b/packages/darkroom/vitest.config.ts @@ -1,8 +1,11 @@ import { defineProject } from 'vitest/config'; export default defineProject({ + define: { + __TEST__: true + }, test: { - reporters: !process.env.GITHUB_ACTIONS ? ['default', 'github-actions'] : ['default'], + reporters: process.env.GITHUB_ACTIONS ? ['default', 'github-actions'] : ['default'], globals: true, name: 'Darkroom', ui: true, diff --git a/packages/safelight/tsconfig.app.json b/packages/safelight/tsconfig.app.json index 87c4c3a9..10118e78 100644 --- a/packages/safelight/tsconfig.app.json +++ b/packages/safelight/tsconfig.app.json @@ -7,7 +7,8 @@ "src/**/*.ts", "src/**/*.vue", "src/**/*.json", - "tsconfig.worker.json" + "tsconfig.worker.json", + "../../globals.d.ts" ], "exclude": ["src/**/__tests__/*"], "compilerOptions": { diff --git a/packages/safelight/tsconfig.node.json b/packages/safelight/tsconfig.node.json index d2c9be64..3853866d 100644 --- a/packages/safelight/tsconfig.node.json +++ b/packages/safelight/tsconfig.node.json @@ -1,6 +1,6 @@ { "extends": "@tsconfig/node20/tsconfig.json", - "include": ["vite.config.*", "buildscripts/*"], + "include": ["vite.config.*", "buildscripts/*", "../../globals.d.ts"], "compilerOptions": { "composite": true, "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo", diff --git a/packages/safelight/vite.config.ts b/packages/safelight/vite.config.ts index 294a2504..30243a11 100644 --- a/packages/safelight/vite.config.ts +++ b/packages/safelight/vite.config.ts @@ -46,6 +46,9 @@ const vueuseRxjsAutoImport = { // https://vitejs.dev/config/ export default defineConfig({ + define: { + __TEST__: false + }, plugins: [ VueRouter({ routesFolder: { diff --git a/packages/shared/src/Storage/db.ts b/packages/shared/src/Storage/db.ts index 5ac49d2e..87b385c9 100644 --- a/packages/shared/src/Storage/db.ts +++ b/packages/shared/src/Storage/db.ts @@ -13,10 +13,7 @@ export class SafelightIndexedDB extends Dexie { timelineItem!: Table; constructor() { - // Only during tests - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - //@ts-ignore - if (window?.vitest) { + if (__TEST__) { super('SafelightIdb', { indexedDB: window.indexedDB, IDBKeyRange: window.IDBKeyRange }); } else { super('SafelightIdb'); diff --git a/packages/shared/tsconfig.json b/packages/shared/tsconfig.json index 05a273a5..b4daa587 100644 --- a/packages/shared/tsconfig.json +++ b/packages/shared/tsconfig.json @@ -1,6 +1,13 @@ { "extends": "@vue/tsconfig/tsconfig.dom.json", - "include": ["*.d.ts", "src/**/*", "types/*.d.ts", "src/**/*.vue", "src/**/*.json"], + "include": [ + "*.d.ts", + "src/**/*", + "types/*.d.ts", + "src/**/*.vue", + "src/**/*.json", + "../../globals.d.ts" + ], "compilerOptions": { "noEmit": false, "moduleResolution": "Bundler", diff --git a/packages/shared/vitest.config.ts b/packages/shared/vitest.config.ts index 0332b242..d9079e7c 100644 --- a/packages/shared/vitest.config.ts +++ b/packages/shared/vitest.config.ts @@ -2,9 +2,12 @@ import Vue from '@vitejs/plugin-vue'; import { defineProject } from 'vitest/config'; export default defineProject({ + define: { + __TEST__: true + }, plugins: [Vue()], test: { - reporters: !process.env.GITHUB_ACTIONS ? ['default', 'github-actions'] : ['default'], + reporters: process.env.GITHUB_ACTIONS ? ['default', 'github-actions'] : ['default'], globals: true, environment: 'happy-dom', name: 'shared', diff --git a/packages/timeline/src/TimeBar.vue b/packages/timeline/src/TimeBar.vue index 7557dafb..b521be85 100644 --- a/packages/timeline/src/TimeBar.vue +++ b/packages/timeline/src/TimeBar.vue @@ -27,7 +27,7 @@ watch(useWindowSize().width, () => { }); onMounted(() => { - if (canvas.value) { + if (canvas.value && !__TEST__) { ctx = canvas.value.getContext('2d') ?? undefined; } drawAll(); diff --git a/packages/timeline/tests/exportComponent.test.ts b/packages/timeline/tests/exportComponent.test.ts index 2087ff3a..c5fd3818 100644 --- a/packages/timeline/tests/exportComponent.test.ts +++ b/packages/timeline/tests/exportComponent.test.ts @@ -1,5 +1,5 @@ import { expect, test } from 'vitest'; -import { Timeline } from '..'; +import { Timeline } from '../src'; test('Main component exports', () => { expect(Timeline).toBeDefined(); diff --git a/packages/timeline/tests/timelineItemRenders.test.ts b/packages/timeline/tests/timelineItemRenders.test.ts index bba38795..31bb6401 100644 --- a/packages/timeline/tests/timelineItemRenders.test.ts +++ b/packages/timeline/tests/timelineItemRenders.test.ts @@ -1,6 +1,6 @@ import { mount } from '@vue/test-utils'; import { expect, test } from 'vitest'; -import { Timeline } from '..'; +import { Timeline } from '../src'; test('Timeline item renders', () => { expect(Timeline).toBeTruthy(); @@ -26,10 +26,11 @@ test('Timeline item renders', () => { test('Multiple timeline items renders', () => { expect(Timeline).toBeTruthy(); - document.write(''); + document.write('
'); const wrapper = mount(Timeline, { attachTo: '#app', props: { + playbackPosition: undefined, items: { '1': { id: '1', diff --git a/packages/timeline/tsconfig.json b/packages/timeline/tsconfig.json index 33eaa8d4..36dd9882 100644 --- a/packages/timeline/tsconfig.json +++ b/packages/timeline/tsconfig.json @@ -23,6 +23,12 @@ "noFallthroughCasesInSwitch": true }, "exclude": ["src/App.vue", "src/main.ts"], - "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"], + "include": [ + "src/**/*.ts", + "src/**/*.d.ts", + "src/**/*.tsx", + "src/**/*.vue", + "../../globals.d.ts" + ], "references": [{ "path": "./tsconfig.node.json" }] } diff --git a/packages/timeline/tsconfig.node.json b/packages/timeline/tsconfig.node.json index 26063d85..f355a1b3 100644 --- a/packages/timeline/tsconfig.node.json +++ b/packages/timeline/tsconfig.node.json @@ -6,5 +6,5 @@ "moduleResolution": "bundler", "allowSyntheticDefaultImports": true }, - "include": ["vite.config.ts"] + "include": ["vite.config.ts", "../../globals.d.ts"] } diff --git a/packages/timeline/vite.config.ts b/packages/timeline/vite.config.ts index dc15bb03..4914644f 100644 --- a/packages/timeline/vite.config.ts +++ b/packages/timeline/vite.config.ts @@ -5,6 +5,9 @@ import { defineConfig } from 'vite'; // https://vitejs.dev/config/ export default defineConfig({ plugins: [vue()], + define: { + __TEST__: false + }, build: { lib: { entry: resolve(__dirname, 'src/index.ts'), diff --git a/packages/timeline/vitest.config.ts b/packages/timeline/vitest.config.ts index 30501044..e9ed3515 100644 --- a/packages/timeline/vitest.config.ts +++ b/packages/timeline/vitest.config.ts @@ -2,9 +2,12 @@ import Vue from '@vitejs/plugin-vue'; import { defineProject } from 'vitest/config'; export default defineProject({ + define: { + __TEST__: true + }, plugins: [Vue()], test: { - reporters: !process.env.GITHUB_ACTIONS ? ['default', 'github-actions'] : ['default'], + reporters: process.env.GITHUB_ACTIONS ? ['default', 'github-actions'] : ['default'], globals: true, name: 'timeline', environment: 'happy-dom',