Skip to content

Commit b56500c

Browse files
committed
feat: render unit test files even in --bare mode
1 parent e7603a4 commit b56500c

File tree

8 files changed

+67
-22
lines changed

8 files changed

+67
-22
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ jobs:
5151
verification-script:
5252
- pnpm --filter '!*typescript*' build
5353
- pnpm --filter '*typescript*' build
54-
# bare templates only contain vitest configurations, but do not include unit test files
55-
- pnpm --filter '*vitest*' --filter '!*bare*' test:unit
54+
- pnpm --filter '*vitest*' test:unit
5655
- pnpm --filter '*eslint*' lint --no-fix --max-warnings=0
5756
- pnpm --filter '*prettier*' format --write --check
5857
# FIXME: it's failing now
@@ -173,7 +172,6 @@ jobs:
173172

174173
- name: Cypress component testing for projects without Vitest
175174
if: ${{ contains(matrix.e2e-framework, 'cypress') }}
176-
# bare templates only contain test configurations, but do not include component test files
177-
run: pnpm --filter '*cypress*' --filter '!*vitest*' --filter '!*bare*' --workspace-concurrency 1 test:unit
175+
run: pnpm --filter '*cypress*' --filter '!*vitest*' --workspace-concurrency 1 test:unit
178176

179177
# FIXME: `--with-tests` folders. It's failing now.

index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,21 @@ async function init() {
568568

569569
if (argv.bare) {
570570
trimBoilerplate(root, { needsTypeScript, needsRouter })
571+
render('bare/base')
572+
573+
// TODO: refactor the `render` utility to avoid this kind of manual mapping?
574+
if (needsTypeScript) {
575+
render('bare/typescript')
576+
}
577+
if (needsVitest) {
578+
render('bare/vitest')
579+
}
580+
if (needsCypressCT) {
581+
render('bare/cypress-ct')
582+
}
583+
if (needsNightwatchCT) {
584+
render('bare/nightwatch-ct')
585+
}
571586
}
572587

573588
// Instructions:

template/bare/base/src/App.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script setup></script>
2+
3+
<template>
4+
<h1>Hello World</h1>
5+
</template>
6+
7+
<style scoped></style>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import App from '../App.vue'
2+
3+
describe('App', () => {
4+
it('mounts and renders properly', () => {
5+
cy.mount(App)
6+
cy.get('h1').should('contain', 'Hello World')
7+
})
8+
})
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
describe('App', function () {
2+
before((browser) => {
3+
browser.init()
4+
})
5+
6+
it('mounts and renders properly', async function () {
7+
const appComponent = await browser.mountComponent('/src/App.vue');
8+
9+
browser.expect.element(appComponent).to.be.present;
10+
browser.expect.element('h1').text.to.contain('Hello World');
11+
})
12+
13+
after((browser) => browser.end())
14+
})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script setup lang="ts"></script>
2+
3+
<template>
4+
<h1>Hello World</h1>
5+
</template>
6+
7+
<style scoped></style>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { describe, it, expect } from 'vitest'
2+
3+
import { mount } from '@vue/test-utils'
4+
import App from '../App.vue'
5+
6+
describe('App', () => {
7+
it('mounts renders properly', () => {
8+
const wrapper = mount(App)
9+
expect(wrapper.text()).toContain('Hello World')
10+
})
11+
})

utils/trimBoilerplate.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
import * as fs from 'node:fs'
22
import * as path from 'path'
33

4-
function getBareBoneAppContent(isTs: boolean) {
5-
return `<script setup${isTs ? ' lang="ts"' : ''}>
6-
</script>
7-
8-
<template>
9-
<h1>Hello World</h1>
10-
</template>
11-
12-
<style scoped>
13-
</style>
14-
`
15-
}
16-
174
function replaceContent(filepath: string, replacer: (content: string) => string) {
185
const content = fs.readFileSync(filepath, 'utf8')
196
fs.writeFileSync(filepath, replacer(content))
@@ -24,17 +11,15 @@ export default function trimBoilerplate(rootDir: string, features: Record<string
2411
const srcDir = path.resolve(rootDir, 'src')
2512

2613
for (const filename of fs.readdirSync(srcDir)) {
27-
// Keep `App.vue`, `main.js/ts`, `router`, and `stores` directories
28-
if (['App.vue', 'main.js', 'main.ts', 'router', 'stores'].includes(filename)) {
14+
// Keep `main.js/ts`, `router`, and `stores` directories
15+
// `App.vue` would be re-rendered in the next step
16+
if (['main.js', 'main.ts', 'router', 'stores'].includes(filename)) {
2917
continue
3018
}
3119
const fullpath = path.resolve(srcDir, filename)
3220
fs.rmSync(fullpath, { recursive: true })
3321
}
3422

35-
// Replace the content in `src/App.vue` with a barebone template
36-
replaceContent(path.resolve(rootDir, 'src/App.vue'), () => getBareBoneAppContent(isTs))
37-
3823
// Remove CSS import in the entry file
3924
const entryPath = path.resolve(rootDir, isTs ? 'src/main.ts' : 'src/main.js')
4025
replaceContent(entryPath, (content) => content.replace("import './assets/main.css'\n\n", ''))

0 commit comments

Comments
 (0)