From 8a8c89bea8932624dc28a525999e867fea8b1c74 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Thu, 15 Sep 2022 15:24:01 -0700 Subject: [PATCH] cherry-pick(#17367): chore: rebuild components on new vite --- packages/playwright-core/src/common/userAgent.ts | 2 +- packages/playwright-test/src/plugins/vitePlugin.ts | 13 +++++++++---- tests/playwright-test/playwright.ct-build.spec.ts | 3 ++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/playwright-core/src/common/userAgent.ts b/packages/playwright-core/src/common/userAgent.ts index 604a85f08276f..b31cc04bc2ab5 100644 --- a/packages/playwright-core/src/common/userAgent.ts +++ b/packages/playwright-core/src/common/userAgent.ts @@ -75,7 +75,7 @@ export function getClientLanguage(): { langName: string, langVersion: string } { return { langName, langVersion }; } -export function getPlaywrightVersion(majorMinorOnly = false) { +export function getPlaywrightVersion(majorMinorOnly = false): string { const packageJson = require('./../../package.json'); return majorMinorOnly ? packageJson.version.split('.').slice(0, 2).join('.') : packageJson.version; } diff --git a/packages/playwright-test/src/plugins/vitePlugin.ts b/packages/playwright-test/src/plugins/vitePlugin.ts index 21593f80ef38a..99ea77867224d 100644 --- a/packages/playwright-test/src/plugins/vitePlugin.ts +++ b/packages/playwright-test/src/plugins/vitePlugin.ts @@ -26,9 +26,10 @@ import { collectComponentUsages, componentInfo } from '../tsxTransform'; import type { FullConfig } from '../types'; import { assert, calculateSha1 } from 'playwright-core/lib/utils'; import type { AddressInfo } from 'net'; +import { getPlaywrightVersion } from 'playwright-core/lib/common/userAgent'; let stoppableServer: any; -const VERSION = 6; +const playwrightVersion = getPlaywrightVersion(); type CtConfig = { ctPort?: number; @@ -65,14 +66,17 @@ export function createPlugin( const registerSource = await fs.promises.readFile(registerSourceFile, 'utf-8'); const registerSourceHash = calculateSha1(registerSource); + const { version: viteVersion } = require('vite/package.json'); try { buildInfo = JSON.parse(await fs.promises.readFile(buildInfoFile, 'utf-8')) as BuildInfo; - assert(buildInfo.version === VERSION); + assert(buildInfo.version === playwrightVersion); + assert(buildInfo.viteVersion === viteVersion); assert(buildInfo.registerSourceHash === registerSourceHash); buildExists = true; } catch (e) { buildInfo = { - version: VERSION, + version: playwrightVersion, + viteVersion, registerSourceHash, components: [], tests: {}, @@ -156,7 +160,8 @@ export function createPlugin( } type BuildInfo = { - version: number, + version: string, + viteVersion: string, registerSourceHash: string, sources: { [key: string]: { diff --git a/tests/playwright-test/playwright.ct-build.spec.ts b/tests/playwright-test/playwright.ct-build.spec.ts index c36449f95762b..1e3ab5d6e62bd 100644 --- a/tests/playwright-test/playwright.ct-build.spec.ts +++ b/tests/playwright-test/playwright.ct-build.spec.ts @@ -37,7 +37,8 @@ test('should work with the empty component list', async ({ runInlineTest }, test expect(output.replace(/\\+/g, '/')).toContain('playwright/.cache/playwright/index.html'); const metainfo = JSON.parse(fs.readFileSync(testInfo.outputPath('playwright/.cache/metainfo.json'), 'utf-8')); - expect(metainfo.version).toEqual(expect.any(Number)); + expect(metainfo.version).toEqual(require('playwright-core/package.json').version); + expect(metainfo.viteVersion).toEqual(require('vite/package.json').version); expect(Object.entries(metainfo.tests)).toHaveLength(1); expect(Object.entries(metainfo.sources)).toHaveLength(8); });