Skip to content

Commit

Permalink
cherry-pick(microsoft#17367): chore: rebuild components on new vite
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman authored and aslushnikov committed Sep 19, 2022
1 parent e1681a3 commit 8a8c89b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/playwright-core/src/common/userAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
13 changes: 9 additions & 4 deletions packages/playwright-test/src/plugins/vitePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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: {},
Expand Down Expand Up @@ -156,7 +160,8 @@ export function createPlugin(
}

type BuildInfo = {
version: number,
version: string,
viteVersion: string,
registerSourceHash: string,
sources: {
[key: string]: {
Expand Down
3 changes: 2 additions & 1 deletion tests/playwright-test/playwright.ct-build.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down

0 comments on commit 8a8c89b

Please sign in to comment.