From 67227f7fd63de1fa0245ffdc8af335f9dade6cf7 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Mon, 24 Jun 2024 10:16:20 +0200 Subject: [PATCH] test: download electron in globalSetup instead of a test file (#421) * test: download electron in globalSetup instead of a test file * chore: typecheck fixes --- package.json | 2 +- pnpm-lock.yaml | 70 +++++++++++++++++++-------------------- src/worker/debugger.ts | 1 - src/worker/watcher.ts | 4 +-- test-e2e/downloadSetup.ts | 15 +++++++++ test-e2e/helper.ts | 6 ++-- test-e2e/vitest.config.ts | 3 ++ 7 files changed, 58 insertions(+), 43 deletions(-) create mode 100644 test-e2e/downloadSetup.ts diff --git a/package.json b/package.json index beeb84c2..acc4e312 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a57eb15d..7e13967f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,7 +12,7 @@ patchedDependencies: devDependencies: '@antfu/eslint-config': specifier: ^2.6.4 - version: 2.6.4(@vue/compiler-sfc@3.4.19)(eslint@8.56.0)(typescript@5.4.5)(vitest@1.4.0) + version: 2.6.4(@vue/compiler-sfc@3.4.19)(eslint@8.56.0)(typescript@5.4.5)(vitest@1.6.0) '@babel/parser': specifier: ^7.20.15 version: 7.23.9 @@ -146,8 +146,8 @@ devDependencies: specifier: ^5.4.5 version: 5.4.5 vitest: - specifier: ^1.4.0 - version: 1.4.0(@types/node@20.12.8) + specifier: ^1.6.0 + version: 1.6.0(@types/node@20.12.8) which: specifier: ^4.0.0 version: 4.0.0 @@ -162,7 +162,7 @@ packages: engines: {node: '>=0.10.0'} dev: true - /@antfu/eslint-config@2.6.4(@vue/compiler-sfc@3.4.19)(eslint@8.56.0)(typescript@5.4.5)(vitest@1.4.0): + /@antfu/eslint-config@2.6.4(@vue/compiler-sfc@3.4.19)(eslint@8.56.0)(typescript@5.4.5)(vitest@1.6.0): resolution: {integrity: sha512-dMD/QC5KWS1OltdpKLhfZM7W7y7zils85opk8d4lyNr7yn0OFjZs7eMYtcC6DrrN2kQ1JrFvBM7uB0QdWn5PUQ==} hasBin: true peerDependencies: @@ -213,7 +213,7 @@ packages: eslint-plugin-toml: 0.9.2(eslint@8.56.0) eslint-plugin-unicorn: 50.0.1(eslint@8.56.0) eslint-plugin-unused-imports: 3.1.0(@typescript-eslint/eslint-plugin@6.21.0)(eslint@8.56.0) - eslint-plugin-vitest: 0.3.22(@typescript-eslint/eslint-plugin@6.21.0)(eslint@8.56.0)(typescript@5.4.5)(vitest@1.4.0) + eslint-plugin-vitest: 0.3.22(@typescript-eslint/eslint-plugin@6.21.0)(eslint@8.56.0)(typescript@5.4.5)(vitest@1.6.0) eslint-plugin-vue: 9.21.1(eslint@8.56.0) eslint-plugin-yml: 1.12.2(eslint@8.56.0) eslint-processor-vue-blocks: 0.1.1(@vue/compiler-sfc@3.4.19)(eslint@8.56.0) @@ -1118,32 +1118,32 @@ packages: resolution: {integrity: sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==} dev: true - /@vitest/expect@1.4.0: - resolution: {integrity: sha512-Jths0sWCJZ8BxjKe+p+eKsoqev1/T8lYcrjavEaz8auEJ4jAVY0GwW3JKmdVU4mmNPLPHixh4GNXP7GFtAiDHA==} + /@vitest/expect@1.6.0: + resolution: {integrity: sha512-ixEvFVQjycy/oNgHjqsL6AZCDduC+tflRluaHIzKIsdbzkLn2U/iBnVeJwB6HsIjQBdfMR8Z0tRxKUsvFJEeWQ==} dependencies: - '@vitest/spy': 1.4.0 - '@vitest/utils': 1.4.0 + '@vitest/spy': 1.6.0 + '@vitest/utils': 1.6.0 chai: 4.4.1 dev: true - /@vitest/runner@1.4.0: - resolution: {integrity: sha512-EDYVSmesqlQ4RD2VvWo3hQgTJ7ZrFQ2VSJdfiJiArkCerDAGeyF1i6dHkmySqk573jLp6d/cfqCN+7wUB5tLgg==} + /@vitest/runner@1.6.0: + resolution: {integrity: sha512-P4xgwPjwesuBiHisAVz/LSSZtDjOTPYZVmNAnpHHSR6ONrf8eCJOFRvUwdHn30F5M1fxhqtl7QZQUk2dprIXAg==} dependencies: - '@vitest/utils': 1.4.0 + '@vitest/utils': 1.6.0 p-limit: 5.0.0 pathe: 1.1.2 dev: true - /@vitest/snapshot@1.4.0: - resolution: {integrity: sha512-saAFnt5pPIA5qDGxOHxJ/XxhMFKkUSBJmVt5VgDsAqPTX6JP326r5C/c9UuCMPoXNzuudTPsYDZCoJ5ilpqG2A==} + /@vitest/snapshot@1.6.0: + resolution: {integrity: sha512-+Hx43f8Chus+DCmygqqfetcAZrDJwvTj0ymqjQq4CvmpKFSTVteEOBzCusu1x2tt4OJcvBflyHUE0DZSLgEMtQ==} dependencies: magic-string: 0.30.7 pathe: 1.1.2 pretty-format: 29.7.0 dev: true - /@vitest/spy@1.4.0: - resolution: {integrity: sha512-Ywau/Qs1DzM/8Uc+yA77CwSegizMlcgTJuYGAi0jujOteJOUf1ujunHThYo243KG9nAyWT3L9ifPYZ5+As/+6Q==} + /@vitest/spy@1.6.0: + resolution: {integrity: sha512-leUTap6B/cqi/bQkXUu6bQV5TZPx7pmMBKBQiI0rJA8c3pB56ZsaTbREnF7CJfmvAS4V2cXIBAh/3rVwrrCYgw==} dependencies: tinyspy: 2.2.1 dev: true @@ -1157,8 +1157,8 @@ packages: pretty-format: 29.7.0 dev: true - /@vitest/utils@1.4.0: - resolution: {integrity: sha512-mx3Yd1/6e2Vt/PUC98DcqTirtfxUyAZ32uK82r8rZzbtBeBo+nqgnjx/LvqQdWsrvNtm14VmurNgcf4nqY5gJg==} + /@vitest/utils@1.6.0: + resolution: {integrity: sha512-21cPiuGMoMZwiOHa2i4LXkMkMkCGzA+MVFV70jRwHo95dL4x/ts5GZhML1QWuy7yfp3WzK3lRvZi3JnXTYqrBw==} dependencies: diff-sequences: 29.6.3 estree-walker: 3.0.3 @@ -2251,7 +2251,7 @@ packages: eslint-rule-composer: 0.3.0 dev: true - /eslint-plugin-vitest@0.3.22(@typescript-eslint/eslint-plugin@6.21.0)(eslint@8.56.0)(typescript@5.4.5)(vitest@1.4.0): + /eslint-plugin-vitest@0.3.22(@typescript-eslint/eslint-plugin@6.21.0)(eslint@8.56.0)(typescript@5.4.5)(vitest@1.6.0): resolution: {integrity: sha512-atkFGQ7aVgcuSeSMDqnyevIyUpfBPMnosksgEPrKE7Y8xQlqG/5z2IQ6UDau05zXaaFv7Iz8uzqvIuKshjZ0Zw==} engines: {node: ^18.0.0 || >= 20.0.0} peerDependencies: @@ -2267,7 +2267,7 @@ packages: '@typescript-eslint/eslint-plugin': 6.21.0(@typescript-eslint/parser@6.21.0)(eslint@8.56.0)(typescript@5.4.5) '@typescript-eslint/utils': 6.21.0(eslint@8.56.0)(typescript@5.4.5) eslint: 8.56.0 - vitest: 1.4.0(@types/node@20.12.8) + vitest: 1.6.0(@types/node@20.12.8) transitivePeerDependencies: - supports-color - typescript @@ -4212,8 +4212,8 @@ packages: resolution: {integrity: sha512-N8hW3PG/3aOoZAN5V/NSAEDz0ZixDSSt5b/a05iqtpgfLWMSVuCo7w0k2vVvEjdrIoeGqZzweX2WlyioNIHchA==} dev: true - /tinypool@0.8.2: - resolution: {integrity: sha512-SUszKYe5wgsxnNOVlBYO6IC+8VGWdVGZWAqUxp3UErNBtptZvWbwyUOyzNL59zigz2rCA92QiL3wvG+JDSdJdQ==} + /tinypool@0.8.4: + resolution: {integrity: sha512-i11VH5gS6IFeLY3gMBQ00/MmLncVP7JLXOw1vlgkytLmJK7QnEr7NXf0LBdxfmNPAeyetukOk0bOYrJrFGjYJQ==} engines: {node: '>=14.0.0'} dev: true @@ -4423,8 +4423,8 @@ packages: spdx-expression-parse: 3.0.1 dev: true - /vite-node@1.4.0(@types/node@20.12.8): - resolution: {integrity: sha512-VZDAseqjrHgNd4Kh8icYHWzTKSCZMhia7GyHfhtzLW33fZlG9SwsB6CEhgyVOWkJfJ2pFLrp/Gj1FSfAiqH9Lw==} + /vite-node@1.6.0(@types/node@20.12.8): + resolution: {integrity: sha512-de6HJgzC+TFzOu0NTC4RAIsyf/DY/ibWDYQUcuEA84EMHhcefTUGkjFHKKEJhQN4A+6I0u++kr3l36ZF2d7XRw==} engines: {node: ^18.0.0 || >=20.0.0} hasBin: true dependencies: @@ -4480,15 +4480,15 @@ packages: fsevents: 2.3.3 dev: true - /vitest@1.4.0(@types/node@20.12.8): - resolution: {integrity: sha512-gujzn0g7fmwf83/WzrDTnncZt2UiXP41mHuFYFrdwaLRVQ6JYQEiME2IfEjU3vcFL3VKa75XhI3lFgn+hfVsQw==} + /vitest@1.6.0(@types/node@20.12.8): + resolution: {integrity: sha512-H5r/dN06swuFnzNFhq/dnz37bPXnq8xB2xB5JOVk8K09rUtoeNN+LHWkoQ0A/i3hvbUKKcCei9KpbxqHMLhLLA==} engines: {node: ^18.0.0 || >=20.0.0} hasBin: true peerDependencies: '@edge-runtime/vm': '*' '@types/node': ^18.0.0 || >=20.0.0 - '@vitest/browser': 1.4.0 - '@vitest/ui': 1.4.0 + '@vitest/browser': 1.6.0 + '@vitest/ui': 1.6.0 happy-dom: '*' jsdom: '*' peerDependenciesMeta: @@ -4506,11 +4506,11 @@ packages: optional: true dependencies: '@types/node': 20.12.8 - '@vitest/expect': 1.4.0 - '@vitest/runner': 1.4.0 - '@vitest/snapshot': 1.4.0 - '@vitest/spy': 1.4.0 - '@vitest/utils': 1.4.0 + '@vitest/expect': 1.6.0 + '@vitest/runner': 1.6.0 + '@vitest/snapshot': 1.6.0 + '@vitest/spy': 1.6.0 + '@vitest/utils': 1.6.0 acorn-walk: 8.3.2 chai: 4.4.1 debug: 4.3.4(supports-color@8.1.1) @@ -4522,9 +4522,9 @@ packages: std-env: 3.7.0 strip-literal: 2.0.0 tinybench: 2.6.0 - tinypool: 0.8.2 + tinypool: 0.8.4 vite: 5.1.4(@types/node@20.12.8) - vite-node: 1.4.0(@types/node@20.12.8) + vite-node: 1.6.0(@types/node@20.12.8) why-is-node-running: 2.2.2 transitivePeerDependencies: - less diff --git a/src/worker/debugger.ts b/src/worker/debugger.ts index d1f8291d..5e01ecc8 100644 --- a/src/worker/debugger.ts +++ b/src/worker/debugger.ts @@ -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: () => { diff --git a/src/worker/watcher.ts b/src/worker/watcher.ts index cdf36604..6e8bd254 100644 --- a/src/worker/watcher.ts +++ b/src/worker/watcher.ts @@ -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 (key: T, value: ProvidedContext[T]) => {})('__vscode', { get continuousFiles() { return state.files || [] }, @@ -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) diff --git a/test-e2e/downloadSetup.ts b/test-e2e/downloadSetup.ts new file mode 100644 index 00000000..b50d006b --- /dev/null +++ b/test-e2e/downloadSetup.ts @@ -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 + } +} diff --git a/test-e2e/helper.ts b/test-e2e/helper.ts index 3f0a29bd..8678c750 100644 --- a/test-e2e/helper.ts +++ b/test-e2e/helper.ts @@ -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 @@ -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' @@ -37,7 +35,7 @@ export const test = baseTest.extend<{ launch: LaunchFixture }>({ const teardowns: (() => Promise)[] = [] 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' diff --git a/test-e2e/vitest.config.ts b/test-e2e/vitest.config.ts index ced4c852..003a1bfc 100644 --- a/test-e2e/vitest.config.ts +++ b/test-e2e/vitest.config.ts @@ -12,5 +12,8 @@ export default defineConfig({ setupFiles: [ './assertions.ts', ], + globalSetup: [ + './downloadSetup.ts', + ], }, })