From b363902e1b4c1e0fe46893aea4f65264158ace5a Mon Sep 17 00:00:00 2001 From: Sander Date: Thu, 29 Dec 2022 02:04:23 +0100 Subject: [PATCH] feat(ct): https (#19697) --- package-lock.json | 20 +++++++++++ package.json | 1 + .../playwright-test/src/plugins/vitePlugin.ts | 9 ++--- .../playwright.ct-build.spec.ts | 34 ++++++++++++++++++- 4 files changed, 59 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index e917cc2355cba..ade3aab01f1c6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,6 +31,7 @@ "@types/xml2js": "^0.4.9", "@typescript-eslint/eslint-plugin": "^5.10.2", "@typescript-eslint/parser": "^5.10.2", + "@vitejs/plugin-basic-ssl": "^1.0.1", "@vitejs/plugin-react": "^3.0.0", "@zip.js/zip.js": "^2.4.2", "ansi-to-html": "^0.7.2", @@ -1677,6 +1678,18 @@ "url": "https://opencollective.com/typescript-eslint" } }, + "node_modules/@vitejs/plugin-basic-ssl": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@vitejs/plugin-basic-ssl/-/plugin-basic-ssl-1.0.1.tgz", + "integrity": "sha512-pcub+YbFtFhaGRTo1832FQHQSHvMrlb43974e2eS8EKleR3p1cDdkJFPci1UhwkEf1J9Bz+wKBSzqpKp7nNj2A==", + "dev": true, + "engines": { + "node": ">=14.6.0" + }, + "peerDependencies": { + "vite": "^3.0.0 || ^4.0.0" + } + }, "node_modules/@vitejs/plugin-react": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/@vitejs/plugin-react/-/plugin-react-3.0.0.tgz", @@ -7142,6 +7155,13 @@ "eslint-visitor-keys": "^3.0.0" } }, + "@vitejs/plugin-basic-ssl": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@vitejs/plugin-basic-ssl/-/plugin-basic-ssl-1.0.1.tgz", + "integrity": "sha512-pcub+YbFtFhaGRTo1832FQHQSHvMrlb43974e2eS8EKleR3p1cDdkJFPci1UhwkEf1J9Bz+wKBSzqpKp7nNj2A==", + "dev": true, + "requires": {} + }, "@vitejs/plugin-react": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/@vitejs/plugin-react/-/plugin-react-3.0.0.tgz", diff --git a/package.json b/package.json index f1c032774bf99..d5e7abd87fc01 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "@types/xml2js": "^0.4.9", "@typescript-eslint/eslint-plugin": "^5.10.2", "@typescript-eslint/parser": "^5.10.2", + "@vitejs/plugin-basic-ssl": "^1.0.1", "@vitejs/plugin-react": "^3.0.0", "@zip.js/zip.js": "^2.4.2", "ansi-to-html": "^0.7.2", diff --git a/packages/playwright-test/src/plugins/vitePlugin.ts b/packages/playwright-test/src/plugins/vitePlugin.ts index 796edda018af9..08800fa9b63e1 100644 --- a/packages/playwright-test/src/plugins/vitePlugin.ts +++ b/packages/playwright-test/src/plugins/vitePlugin.ts @@ -94,7 +94,7 @@ export function createPlugin( const sourcesDirty = !buildExists || hasNewComponents || await checkSources(buildInfo); viteConfig.root = rootDir; - viteConfig.preview = { port }; + viteConfig.preview = { port, ...viteConfig.preview }; viteConfig.build = { outDir }; @@ -152,9 +152,10 @@ export function createPlugin( stoppableServer = stoppable(previewServer.httpServer, 0); const isAddressInfo = (x: any): x is AddressInfo => x?.address; const address = previewServer.httpServer.address(); - if (isAddressInfo(address)) - process.env.PLAYWRIGHT_TEST_BASE_URL = `http://localhost:${address.port}`; - + if (isAddressInfo(address)) { + const protocol = viteConfig.preview.https ? 'https:' : 'http:'; + process.env.PLAYWRIGHT_TEST_BASE_URL = `${protocol}//localhost:${address.port}`; + } }, teardown: async () => { diff --git a/tests/playwright-test/playwright.ct-build.spec.ts b/tests/playwright-test/playwright.ct-build.spec.ts index 82c8edfe97cb6..b3a892eecb21a 100644 --- a/tests/playwright-test/playwright.ct-build.spec.ts +++ b/tests/playwright-test/playwright.ct-build.spec.ts @@ -296,4 +296,36 @@ test('should not use global config for preview', async ({ runInlineTest }) => { const result2 = await runInlineTest({}, { workers: 1 }); expect(result2.exitCode).toBe(0); expect(result2.passed).toBe(1); -}); \ No newline at end of file +}); + +test('should work with https enabled', async ({ runInlineTest }) => { + const result = await runInlineTest({ + 'playwright/index.html': ``, + 'playwright/index.js': `//@no-header`, + 'playwright.config.js': ` + //@no-header + import basicSsl from '@vitejs/plugin-basic-ssl'; + export default { + use: { + ignoreHTTPSErrors: true, + ctViteConfig: { + plugins: [basicSsl()], + preview: { + https: true + } + } + }, + }; + `, + 'http.test.tsx': ` + //@no-header + import { test, expect } from '@playwright/experimental-ct-react'; + + test('pass', async ({ page }) => { + await expect(page).toHaveURL(/https:.*/); + }); + `, + }, { workers: 1 }); + expect(result.exitCode).toBe(0); + expect(result.passed).toBe(1); +});