Skip to content

Commit

Permalink
chore: migrate ct to vite5 (#29033)
Browse files Browse the repository at this point in the history
Closes #28607
  • Loading branch information
pavelfeldman authored Jan 19, 2024
1 parent 54c57fd commit 71a48c2
Show file tree
Hide file tree
Showing 12 changed files with 831 additions and 984 deletions.
1,777 changes: 810 additions & 967 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@
"@typescript-eslint/eslint-plugin": "^6.13.2",
"@typescript-eslint/parser": "^6.13.2",
"@typescript-eslint/utils": "^6.13.2",
"@vitejs/plugin-basic-ssl": "^1.0.1",
"@vitejs/plugin-react": "^3.1.0",
"@vitejs/plugin-basic-ssl": "^1.1.0",
"@vitejs/plugin-react": "^4.2.1",
"@zip.js/zip.js": "^2.7.29",
"chokidar": "^3.5.3",
"colors": "^1.4.0",
Expand All @@ -100,7 +100,7 @@
"socksv5": "0.0.6",
"ssim.js": "^3.5.0",
"typescript": "^5.3.2",
"vite": "^4.4.12",
"vite": "^5.0.11",
"ws": "^8.5.0",
"xml2js": "^0.5.0",
"yaml": "^2.2.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-ct-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"dependencies": {
"playwright-core": "1.42.0-next",
"vite": "^4.4.12",
"vite": "^5.0.11",
"playwright": "1.42.0-next"
},
"bin": {
Expand Down
13 changes: 7 additions & 6 deletions packages/playwright-ct-core/src/vitePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,18 @@

import type { Suite } from 'playwright/types/testReporter';
import type { PlaywrightTestConfig as BasePlaywrightTestConfig, FullConfig } from 'playwright/test';

import type http from 'http';
import type { InlineConfig, Plugin, ResolveFn, ResolvedConfig, UserConfig } from 'vite';
import type { TestRunnerPlugin } from '../../playwright/src/plugins';
import type { AddressInfo } from 'net';
import type { PluginContext } from 'rollup';
import { debug } from 'playwright-core/lib/utilsBundle';

import fs from 'fs';
import path from 'path';
import { stoppable } from 'playwright/lib/utilsBundle';
import { assert, calculateSha1 } from 'playwright-core/lib/utils';
import { getPlaywrightVersion } from 'playwright-core/lib/utils';
import { getUserData, internalDependenciesForTestFile, setExternalDependencies } from 'playwright/lib/transform/compilationCache';
import { version as viteVersion, build, preview, mergeConfig } from 'vite';
import { source as injectedSource } from './generated/indexSource';
import type { ImportInfo } from './tsxTransform';

Expand Down Expand Up @@ -90,14 +88,17 @@ export function createPlugin(
outDir: use.ctCacheDir ? path.resolve(configDir, use.ctCacheDir) : path.resolve(templateDir, '.cache')
},
preview: {
https: baseURL.protocol.startsWith('https:'),
https: baseURL.protocol.startsWith('https:') ? {} : undefined,
host: baseURL.hostname,
port: use.ctPort || Number(baseURL.port) || 3100
},
// Vite preview server will otherwise always return the index.html with 200.
appType: 'custom',
appType: 'mpa',
};

// Vite 5 refuses to support CJS.
const { version: viteVersion, build, preview, mergeConfig } = await import('vite');

// Apply user config on top of the base config. This could have changed root and build.outDir.
const userConfig = typeof use.ctViteConfig === 'function' ? await use.ctViteConfig() : (use.ctViteConfig || {});
const baseAndUserConfig = mergeConfig(baseConfig, userConfig);
Expand Down Expand Up @@ -217,7 +218,7 @@ export function createPlugin(
}

const previewServer = await preview(finalConfig);
stoppableServer = stoppable(previewServer.httpServer, 0);
stoppableServer = stoppable(previewServer.httpServer as http.Server, 0);
const isAddressInfo = (x: any): x is AddressInfo => x?.address;
const address = previewServer.httpServer.address();
if (isAddressInfo(address)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-ct-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"dependencies": {
"@playwright/experimental-ct-core": "1.42.0-next",
"@vitejs/plugin-react": "^4.0.0"
"@vitejs/plugin-react": "^4.2.1"
},
"bin": {
"playwright": "cli.js"
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-ct-react17/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"dependencies": {
"@playwright/experimental-ct-core": "1.42.0-next",
"@vitejs/plugin-react": "^4.0.0"
"@vitejs/plugin-react": "^4.2.1"
},
"bin": {
"playwright": "cli.js"
Expand Down
4 changes: 2 additions & 2 deletions tests/components/ct-react-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"devDependencies": {
"@types/react": "^18.0.26",
"@types/react-dom": "^18.0.10",
"@vitejs/plugin-react": "^3.1.0",
"@vitejs/plugin-react": "^4.2.1",
"typescript": "^4.5.4",
"vite": "^4.2.1"
"vite": "^5.0.11"
}
}
2 changes: 1 addition & 1 deletion tests/components/ct-solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"devDependencies": {
"typescript": "^4.7.4",
"vite": "^4.2.1",
"vite": "^5.0.11",
"vite-plugin-solid": "^2.6.1"
}
}
2 changes: 1 addition & 1 deletion tests/components/ct-svelte-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"svelte-check": "^3.6.2",
"tslib": "^2.6.2",
"typescript": "^5.3.3",
"vite": "^5.0.8"
"vite": "^5.0.11"
},
"dependencies": {
"svelte": "^4.2.8",
Expand Down
2 changes: 1 addition & 1 deletion tests/components/ct-vue-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"devDependencies": {
"@vitejs/plugin-vue": "^4.1.0",
"@vue/tsconfig": "^0.1.3",
"vite": "^4.2.1",
"vite": "^5.0.11",
"vue-tsc": "^1.0.0"
}
}
2 changes: 2 additions & 0 deletions tests/installation/playwright-component-testing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import { test } from './npmTest';
import path from 'path';

test.slow();

test('pnpm: @playwright/experimental-ct-react should work', async ({ exec, tmpWorkspace, writeFiles }) => {
await exec('pnpm add @playwright/experimental-ct-react react react-dom');
await exec('pnpm exec playwright install');
Expand Down
1 change: 1 addition & 0 deletions tests/playwright-test/playwright-test-fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ const TSCONFIG = {
'rootDir': '.',
'lib': ['esnext', 'dom', 'DOM.Iterable'],
'noEmit': true,
'skipLibCheck': true,
},
'exclude': [
'node_modules'
Expand Down

0 comments on commit 71a48c2

Please sign in to comment.