Skip to content

Commit

Permalink
test: Fixed all testing environments
Browse files Browse the repository at this point in the history
Added \_\_TEST\_\_ global. Fixed github actions reporter
  • Loading branch information
Joery-M committed May 22, 2024
1 parent 7810405 commit 4044deb
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 17 deletions.
1 change: 1 addition & 0 deletions globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare const __TEST__: boolean;
2 changes: 1 addition & 1 deletion packages/darkroom/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
3 changes: 3 additions & 0 deletions packages/darkroom/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ export default defineConfig({
name: 'darkroom'
},
sourcemap: true
},
define: {
__TEST__: false
}
});
5 changes: 4 additions & 1 deletion packages/darkroom/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
3 changes: 2 additions & 1 deletion packages/safelight/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"src/**/*.ts",
"src/**/*.vue",
"src/**/*.json",
"tsconfig.worker.json"
"tsconfig.worker.json",
"../../globals.d.ts"
],
"exclude": ["src/**/__tests__/*"],
"compilerOptions": {
Expand Down
2 changes: 1 addition & 1 deletion packages/safelight/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 3 additions & 0 deletions packages/safelight/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ const vueuseRxjsAutoImport = {

// https://vitejs.dev/config/
export default defineConfig({
define: {
__TEST__: false
},
plugins: [
VueRouter({
routesFolder: {
Expand Down
5 changes: 1 addition & 4 deletions packages/shared/src/Storage/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ export class SafelightIndexedDB extends Dexie {
timelineItem!: Table<StoredSimpleTimelineItem, string>;

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');
Expand Down
9 changes: 8 additions & 1 deletion packages/shared/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 4 additions & 1 deletion packages/shared/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion packages/timeline/src/TimeBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ watch(useWindowSize().width, () => {
});
onMounted(() => {
if (canvas.value) {
if (canvas.value && !__TEST__) {
ctx = canvas.value.getContext('2d') ?? undefined;
}
drawAll();
Expand Down
2 changes: 1 addition & 1 deletion packages/timeline/tests/exportComponent.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from 'vitest';
import { Timeline } from '..';
import { Timeline } from '../src';

test('Main component exports', () => {
expect(Timeline).toBeDefined();
Expand Down
5 changes: 3 additions & 2 deletions packages/timeline/tests/timelineItemRenders.test.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -26,10 +26,11 @@ test('Timeline item renders', () => {
test('Multiple timeline items renders', () => {
expect(Timeline).toBeTruthy();

document.write('<app id="app"></app>');
document.write('<div id="app"></div>');
const wrapper = mount(Timeline, {
attachTo: '#app',
props: {
playbackPosition: undefined,
items: {
'1': {
id: '1',
Expand Down
8 changes: 7 additions & 1 deletion packages/timeline/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" }]
}
2 changes: 1 addition & 1 deletion packages/timeline/tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
"include": ["vite.config.ts", "../../globals.d.ts"]
}
3 changes: 3 additions & 0 deletions packages/timeline/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
5 changes: 4 additions & 1 deletion packages/timeline/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 4044deb

Please sign in to comment.