"scripts": {
"dev": "vite",
"build": "vite build",
- "preview": "vite preview --port 4173"
+ "preview": "vite preview"
},
"dependencies": {
"vue": "^3.2.40"
/* Run your local dev server before starting the tests */
webServer: {
- command: 'npm run dev',
+ /**
+ * Use the dev server by default for faster feedback loop.
+ * Use the preview server on CI for more realistic testing.
+ */
+ command: process.env.CI ? 'vite preview --port 5173' : 'vite dev',
port: 5173,
reuseExistingServer: !process.env.CI
}
/* Run your local dev server before starting the tests */
webServer: {
- command: 'npm run dev',
+ /**
+ * Use the dev server by default for faster feedback loop.
+ * Use the preview server on CI for more realistic testing.
+ Playwright will re-use the local server if there is already a dev-server running.
+ */
+ command: process.env.CI ? 'vite preview --port 5173' : 'vite dev',
port: 5173,
reuseExistingServer: !process.env.CI
}
needsVitest,
needsEslint
}) {
- const commandFor = (scriptName) => getCommand(packageManager, scriptName)
+ const commandFor = (scriptName: string, args?: string) =>
+ getCommand(packageManager, scriptName, args)
let readme = `# ${projectName}
# Install browsers for the first run
npx playwright install
+# When testing on CI, must build the project first
+${commandFor('build')}
+
# Runs the end-to-end tests
${commandFor('test:e2e')}
# Runs the tests only on Chromium
-${commandFor('test:e2e -- --project=chromium')}
+${commandFor('test:e2e', '--project=chromium')}
# Runs the tests of a specific file
-${commandFor('test:e2e -- tests/example.spec.ts')}
+${commandFor('test:e2e', 'tests/example.spec.ts')}
# Runs the tests in debug mode
-${commandFor('test:e2e -- --debug')}
+${commandFor('test:e2e', '--debug')}
\`\`\`
`
}
-export default function getCommand(packageManager, scriptName) {
+export default function getCommand(packageManager: string, scriptName: string, args?: string) {
if (scriptName === 'install') {
return packageManager === 'yarn' ? 'yarn' : `${packageManager} install`
}
- return packageManager === 'npm' ? `npm run ${scriptName}` : `${packageManager} ${scriptName}`
+ if (args) {
+ return packageManager === 'npm'
+ ? `npm run ${scriptName} -- ${args}`
+ : `${packageManager} ${scriptName} ${args}`
+ } else {
+ return packageManager === 'npm' ? `npm run ${scriptName}` : `${packageManager} ${scriptName}`
+ }
}