Skip to content

Commit 32af8af

Browse files
authored
refactor!: run cypress headlessly by default; add test:*:dev commands (#183)
1 parent 11fc2a1 commit 32af8af

File tree

4 files changed

+21
-30
lines changed

4 files changed

+21
-30
lines changed

scripts/test.mjs

+6-24
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,21 @@ await $`pnpm install`
1919

2020
for (const projectName of projects) {
2121
cd(path.resolve(playgroundDir, projectName))
22-
23-
if (projectName.includes('vitest')) {
24-
console.log(`Running unit tests in ${projectName}`)
25-
await $`pnpm test:unit`
26-
}
27-
28-
cd(path.resolve(playgroundDir, projectName))
29-
3022
const packageJSON = require(path.resolve(playgroundDir, projectName, 'package.json'));
3123

3224
console.log(`Building ${projectName}`)
3325
await $`pnpm build`
34-
35-
if ('cypress' in packageJSON.devDependencies) {
36-
console.log(`Running e2e tests in ${projectName}`)
37-
await $`pnpm test:e2e:ci`
38-
}
26+
3927
if ('@playwright/test' in packageJSON.devDependencies) {
4028
await $`pnpm playwright install --with-deps`
29+
}
30+
31+
if ('test:e2e' in packageJSON.scripts) {
32+
console.log(`Running e2e tests in ${projectName}`)
4133
await $`pnpm test:e2e`
4234
}
4335

44-
if ('test:unit:ci' in packageJSON.scripts) {
45-
// Without Vitest, the project will use Cypress Component Testing for unit testing
46-
// Cypress Component Testing is flaky in CI environment, so we need to tolerate the errors.
47-
try {
48-
await $`pnpm test:unit:ci`
49-
} catch (e) {
50-
console.error(`Component Testing in ${projectName} fails:`)
51-
console.error(e)
52-
process.exit(1)
53-
}
54-
} else if ('test:unit' in packageJSON.scripts) {
36+
if ('test:unit' in packageJSON.scripts) {
5537
console.log(`Running unit tests in ${projectName}`)
5638
await $`pnpm test:unit`
5739
}

template/config/cypress-ct/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"scripts": {
3-
"test:unit": "cypress open --component",
4-
"test:unit:ci": "cypress run --component --quiet --reporter spec"
3+
"test:unit": "cypress run --component",
4+
"test:unit:dev": "cypress open --component"
55
},
66
"dependencies": {
77
"vue": "^3.2.40"

template/config/cypress/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"scripts": {
3-
"test:e2e": "start-server-and-test preview http://localhost:4173/ 'cypress open --e2e'",
4-
"test:e2e:ci": "start-server-and-test preview http://localhost:4173/ 'cypress run --e2e'"
3+
"test:e2e": "start-server-and-test preview :4173 'cypress run --e2e'",
4+
"test:e2e:dev": "start-server-and-test 'vite dev --port 4173' :4173 'cypress open --e2e'"
55
},
66
"devDependencies": {
77
"cypress": "^10.10.0",

utils/generateReadme.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ ${commandFor('test:unit')}
7676
### Run Headed Component Tests with [Cypress Component Testing](https://on.cypress.io/component)
7777
7878
\`\`\`sh
79-
${commandFor('test:unit')} # or \`${commandFor('test:unit:ci')}\` for headless testing
79+
${commandFor('test:unit:dev')} # or \`${commandFor('test:unit')}\` for headless testing
8080
\`\`\`
8181
`
8282
}
@@ -85,9 +85,18 @@ ${commandFor('test:unit')} # or \`${commandFor('test:unit:ci')}\` for headless t
8585
npmScriptsDescriptions += `
8686
### Run End-to-End Tests with [Cypress](https://www.cypress.io/)
8787
88+
\`\`\`sh
89+
${commandFor('test:e2e:dev')}
90+
\`\`\`
91+
92+
This runs the end-to-end tests against the Vite development server.
93+
It is much faster than the production build.
94+
95+
But it's still recommended to test the production build with \`test:e2e\` before deploying (e.g. in CI environments):
96+
8897
\`\`\`sh
8998
${commandFor('build')}
90-
${commandFor('test:e2e')} # or \`${commandFor('test:e2e:ci')}\` for headless testing
99+
${commandFor('test:e2e')}
91100
\`\`\`
92101
`
93102
}

0 commit comments

Comments
 (0)