Skip to content

Commit 11fc2a1

Browse files
refactor(playwright)!: use prod bundle & preview server on CI (vuejs#182)
Co-authored-by: Max Schmitt <max@schmitt.mx>
1 parent 55f563f commit 11fc2a1

File tree

5 files changed

+28
-9
lines changed

5 files changed

+28
-9
lines changed

template/base/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"scripts": {
33
"dev": "vite",
44
"build": "vite build",
5-
"preview": "vite preview --port 4173"
5+
"preview": "vite preview"
66
},
77
"dependencies": {
88
"vue": "^3.2.40"

template/config/playwright/playwright.config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ const config = {
9999

100100
/* Run your local dev server before starting the tests */
101101
webServer: {
102-
command: 'npm run dev',
102+
/**
103+
* Use the dev server by default for faster feedback loop.
104+
* Use the preview server on CI for more realistic testing.
105+
*/
106+
command: process.env.CI ? 'vite preview --port 5173' : 'vite dev',
103107
port: 5173,
104108
reuseExistingServer: !process.env.CI
105109
}

template/config/playwright/playwright.config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ const config: PlaywrightTestConfig = {
9898

9999
/* Run your local dev server before starting the tests */
100100
webServer: {
101-
command: 'npm run dev',
101+
/**
102+
* Use the dev server by default for faster feedback loop.
103+
* Use the preview server on CI for more realistic testing.
104+
Playwright will re-use the local server if there is already a dev-server running.
105+
*/
106+
command: process.env.CI ? 'vite preview --port 5173' : 'vite dev',
102107
port: 5173,
103108
reuseExistingServer: !process.env.CI
104109
}

utils/generateReadme.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export default function generateReadme({
2525
needsVitest,
2626
needsEslint
2727
}) {
28-
const commandFor = (scriptName) => getCommand(packageManager, scriptName)
28+
const commandFor = (scriptName: string, args?: string) =>
29+
getCommand(packageManager, scriptName, args)
2930

3031
let readme = `# ${projectName}
3132
@@ -99,14 +100,17 @@ ${commandFor('test:e2e')} # or \`${commandFor('test:e2e:ci')}\` for headless tes
99100
# Install browsers for the first run
100101
npx playwright install
101102
103+
# When testing on CI, must build the project first
104+
${commandFor('build')}
105+
102106
# Runs the end-to-end tests
103107
${commandFor('test:e2e')}
104108
# Runs the tests only on Chromium
105-
${commandFor('test:e2e -- --project=chromium')}
109+
${commandFor('test:e2e', '--project=chromium')}
106110
# Runs the tests of a specific file
107-
${commandFor('test:e2e -- tests/example.spec.ts')}
111+
${commandFor('test:e2e', 'tests/example.spec.ts')}
108112
# Runs the tests in debug mode
109-
${commandFor('test:e2e -- --debug')}
113+
${commandFor('test:e2e', '--debug')}
110114
\`\`\`
111115
`
112116
}

utils/getCommand.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
export default function getCommand(packageManager, scriptName) {
1+
export default function getCommand(packageManager: string, scriptName: string, args?: string) {
22
if (scriptName === 'install') {
33
return packageManager === 'yarn' ? 'yarn' : `${packageManager} install`
44
}
55

6-
return packageManager === 'npm' ? `npm run ${scriptName}` : `${packageManager} ${scriptName}`
6+
if (args) {
7+
return packageManager === 'npm'
8+
? `npm run ${scriptName} -- ${args}`
9+
: `${packageManager} ${scriptName} ${args}`
10+
} else {
11+
return packageManager === 'npm' ? `npm run ${scriptName}` : `${packageManager} ${scriptName}`
12+
}
713
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy