Skip to content

Commit

Permalink
test: download electron in globalSetup instead of a test file (#421)
Browse files Browse the repository at this point in the history
* test: download electron in globalSetup instead of a test file

* chore: typecheck fixes
  • Loading branch information
sheremet-va authored Jun 24, 2024
1 parent 0fe01b5 commit 67227f7
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 43 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
"tsup": "^8.0.1",
"tsx": "^4.7.1",
"typescript": "^5.4.5",
"vitest": "^1.4.0",
"vitest": "^1.6.0",
"which": "^4.0.0",
"ws": "^8.16.0"
},
Expand Down
70 changes: 35 additions & 35 deletions pnpm-lock.yaml

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

1 change: 0 additions & 1 deletion src/worker/debugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export class VitestDebugger {
ctx: VitestCore,
private vitest: Vitest,
) {
// @ts-expect-error not released yet
const inspector = ctx.config.inspector
Object.defineProperty(ctx.config, 'inspector', {
get: () => {
Expand Down
4 changes: 2 additions & 2 deletions src/worker/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class VitestWatcher {
constructor(ctx: VitestCore) {
// eslint-disable-next-line ts/no-this-alias
const state = this
ctx.getCoreWorkspaceProject().provide('__vscode', {
;(ctx.getCoreWorkspaceProject().provide as <T extends keyof ProvidedContext>(key: T, value: ProvidedContext[T]) => {})('__vscode', {
get continuousFiles() {
return state.files || []
},
Expand All @@ -23,7 +23,7 @@ export class VitestWatcher {
get rerunTriggered() {
return state.rerunTriggered ?? false
},
} satisfies ProvidedContext['__vscode'])
})

// @ts-expect-error modifying a private property
const originalScheduleRerun = ctx.scheduleRerun.bind(ctx)
Expand Down
15 changes: 15 additions & 0 deletions test-e2e/downloadSetup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { download } from '@vscode/test-electron'
import type { GlobalSetupContext } from 'vitest/node'

export default async function downloadVscode({ provide }: GlobalSetupContext) {
if (process.env.VSCODE_E2E_DOWNLOAD_PATH)
provide('executablePath', process.env.VSCODE_E2E_DOWNLOAD_PATH)
else
provide('executablePath', await download())
}

declare module 'vitest' {
export interface ProvidedContext {
executablePath: string
}
}
6 changes: 2 additions & 4 deletions test-e2e/helper.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import fs from 'node:fs'
import os from 'node:os'
import path from 'node:path'
import { download } from '@vscode/test-electron'
import { _electron } from '@playwright/test'
import type { Page } from '@playwright/test'
import type { Awaitable } from 'vitest'
import { test as baseTest } from 'vitest'
import { test as baseTest, inject } from 'vitest'
import { VSCodeTester } from './tester'

// based on
Expand All @@ -26,7 +25,6 @@ type LaunchFixture = (options: {
}>

const defaultConfig = process.env as {
VSCODE_E2E_DOWNLOAD_PATH?: string
VSCODE_E2E_EXTENSION_PATH?: string
VSCODE_E2E_WORKSPACE_PATH?: string
VSCODE_E2E_TRACE?: 'on' | 'off'
Expand All @@ -37,7 +35,7 @@ export const test = baseTest.extend<{ launch: LaunchFixture }>({
const teardowns: (() => Promise<void>)[] = []

await use(async (options) => {
const executablePath = defaultConfig.VSCODE_E2E_DOWNLOAD_PATH ?? await download()
const executablePath = inject('executablePath')
const extensionPath = options.extensionPath ?? defaultConfig.VSCODE_E2E_EXTENSION_PATH
const workspacePath = options.workspacePath ?? defaultConfig.VSCODE_E2E_WORKSPACE_PATH
const trace = (options.trace ?? defaultConfig.VSCODE_E2E_TRACE) === 'on'
Expand Down
3 changes: 3 additions & 0 deletions test-e2e/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ export default defineConfig({
setupFiles: [
'./assertions.ts',
],
globalSetup: [
'./downloadSetup.ts',
],
},
})

0 comments on commit 67227f7

Please sign in to comment.