Skip to content

Commit

Permalink
Merge pull request #15 from watonyweng/feat/integrate/vitest
Browse files Browse the repository at this point in the history
feat(cli): support vitest test
  • Loading branch information
caoxiemeihao committed Mar 20, 2023
2 parents b3b962a + 090e7e9 commit 707c26e
Show file tree
Hide file tree
Showing 4 changed files with 797 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ jobs:
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm build
- run: pnpm test
40 changes: 40 additions & 0 deletions __tests__/cli.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { join } from 'node:path'
import type { ExecaSyncReturnValue, SyncOptions } from 'execa'
import { execaCommandSync } from 'execa'
import fs from 'fs-extra'
import { afterEach, beforeAll, expect, test } from 'vitest'

const CLI_PATH = join(__dirname, '..')

const projectName = 'electron-vite-app'
const generatePath = join(__dirname, projectName)

const run = (
args: string[],
options: SyncOptions = {},
): ExecaSyncReturnValue => {
return execaCommandSync(`node ${CLI_PATH} ${args.join(' ')}`, options)
}

const createNonEmptyDir = () => {
// Create the temporary directory
fs.mkdirpSync(generatePath)

// Create a package.json file
const pkgJson = join(generatePath, 'package.json')
fs.writeFileSync(pkgJson, '{ "foo": "bar" }')
}

beforeAll(() => fs.remove(generatePath))
afterEach(() => fs.remove(generatePath))

test('prompts for the project name if none supplied', () => {
const { stdout } = run([])
expect(stdout).toContain('Project name:')
})

test('prompts for project template if none supplied when target dir is current directory', () => {
fs.mkdirpSync(generatePath)
const { stdout } = run(['.'], { cwd: generatePath })
expect(stdout).toContain('Project template:')
})
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
],
"scripts": {
"build": "unbuild",
"prepublishOnly": "npm run build"
"prepublishOnly": "npm run build",
"lint": "eslint .",
"test": "vitest"
},
"dependencies": {
"fs-extra": "^11.1.0",
Expand All @@ -41,8 +43,10 @@
"@types/fs-extra": "^11.0.1",
"@types/node": "^18.11.18",
"@types/prompts": "^2.4.2",
"execa": "^7.1.1",
"typescript": "^4.9.4",
"unbuild": "^1.0.2"
"unbuild": "^1.0.2",
"vitest": "^0.29.3"
},
"engines": {
"node": "^14.18.0 || >=16.0.0"
Expand Down
Loading

0 comments on commit 707c26e

Please sign in to comment.