]> git.ipfire.org Git - thirdparty/vuejs/create-vue.git/commitdiff
fix: fix cypress component testing setup in bare mode
authorHaoqun Jiang <haoqunjiang@gmail.com>
Tue, 21 Jan 2025 08:31:37 +0000 (16:31 +0800)
committerHaoqun Jiang <haoqunjiang@gmail.com>
Tue, 21 Jan 2025 08:31:37 +0000 (16:31 +0800)
.github/workflows/ci.yml
index.ts
utils/trimBoilerplate.ts

index 953590d5961a40963fcc8f731acac024fd976794..92a01cbea5b170fcf4587533608705f9a7562ba3 100644 (file)
@@ -171,6 +171,7 @@ jobs:
         run: pnpm --filter '*${{ matrix.e2e-framework }}*' --filter '!*bare*' --workspace-concurrency 1 test:e2e
 
       - name: Cypress component testing for projects without Vitest
+        working-directory: ./playground
         if: ${{ contains(matrix.e2e-framework, 'cypress') }}
         run: pnpm --filter '*cypress*' --filter '!*vitest*' --workspace-concurrency 1 test:unit
 
index cb6b61e267d774ae442aaada99de55f9981b315e..6ab53ab8557b97dd85d07daa4cc1f586cc31edce 100755 (executable)
--- a/index.ts
+++ b/index.ts
@@ -628,7 +628,7 @@ async function init() {
   }
 
   if (argv.bare) {
-    removeCSSImport(root, needsTypeScript)
+    removeCSSImport(root, needsTypeScript, needsCypressCT)
     if (needsRouter) {
       emptyRouterConfig(root, needsTypeScript)
     }
index ae5ab35b9e1373bcac745efa1683a3e0802bb136..959e58831777a64f6d3b517803936f7e28cccbaa 100644 (file)
@@ -20,10 +20,24 @@ export function trimBoilerplate(rootDir: string) {
   }
 }
 
-export function removeCSSImport(rootDir: string, needsTypeScript: boolean) {
+export function removeCSSImport(
+  rootDir: string,
+  needsTypeScript: boolean,
+  needsCypressCT: boolean,
+) {
   // Remove CSS import in the entry file
   const entryPath = path.resolve(rootDir, needsTypeScript ? 'src/main.ts' : 'src/main.js')
   replaceContent(entryPath, (content) => content.replace("import './assets/main.css'\n\n", ''))
+
+  if (needsCypressCT) {
+    const ctSetupPath = path.resolve(
+      rootDir,
+      needsTypeScript ? 'cypress/support/component.ts' : 'cypress/support/component.js',
+    )
+    replaceContent(ctSetupPath, (content) =>
+      content.replace("import '@/assets/main.css'", "// import '@/assets/main.css'"),
+    )
+  }
 }
 
 export function emptyRouterConfig(rootDir: string, needsTypeScript: boolean) {