From ecb41cfb9ecf6e8863bf1411bacf70289f085421 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Tue, 21 Jan 2025 16:31:37 +0800 Subject: [PATCH] fix: fix cypress component testing setup in bare mode --- .github/workflows/ci.yml | 1 + index.ts | 2 +- utils/trimBoilerplate.ts | 16 +++++++++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 953590d5..92a01cbe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/index.ts b/index.ts index cb6b61e2..6ab53ab8 100755 --- 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) } diff --git a/utils/trimBoilerplate.ts b/utils/trimBoilerplate.ts index ae5ab35b..959e5883 100644 --- a/utils/trimBoilerplate.ts +++ b/utils/trimBoilerplate.ts @@ -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) { -- 2.39.5