Skip to content

Commit 648e15e

Browse files
committed
chore: sync test script
1 parent 5e51982 commit 648e15e

File tree

3 files changed

+75
-10
lines changed

3 files changed

+75
-10
lines changed

__tests__/cli.spec.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { afterEach, beforeAll, expect, test } from 'vitest'
77
const CLI_PATH = join(__dirname, '..')
88

99
const projectName = 'electron-vite-app'
10-
const generatePath = join(__dirname, projectName)
10+
const genPath = join(__dirname, projectName)
1111

1212
const run = (
1313
args: string[],
@@ -18,23 +18,40 @@ const run = (
1818

1919
const createNonEmptyDir = () => {
2020
// Create the temporary directory
21-
fs.mkdirpSync(generatePath)
21+
fs.mkdirpSync(genPath)
2222

2323
// Create a package.json file
24-
const pkgJson = join(generatePath, 'package.json')
24+
const pkgJson = join(genPath, 'package.json')
2525
fs.writeFileSync(pkgJson, '{ "foo": "bar" }')
2626
}
2727

28-
beforeAll(() => fs.remove(generatePath))
29-
afterEach(() => fs.remove(generatePath))
28+
beforeAll(() => fs.remove(genPath))
29+
afterEach(() => fs.remove(genPath))
3030

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

36-
test('prompts for project template if none supplied when target dir is current directory', () => {
37-
fs.mkdirpSync(generatePath)
38-
const { stdout } = run(['.'], { cwd: generatePath })
36+
test('prompts for the framework if none supplied when target dir is current directory', () => {
37+
fs.mkdirpSync(genPath)
38+
const { stdout } = run(['.'], { cwd: genPath })
3939
expect(stdout).toContain('Project template:')
4040
})
41+
42+
test('prompts for the framework if none supplied', () => {
43+
const { stdout } = run([projectName])
44+
expect(stdout).toContain('Project template:')
45+
})
46+
47+
test('asks to overwrite non-empty target directory', () => {
48+
createNonEmptyDir()
49+
const { stdout } = run([projectName], { cwd: __dirname })
50+
expect(stdout).toContain(`Target directory "${projectName}" is not empty.`)
51+
})
52+
53+
test('asks to overwrite non-empty current directory', () => {
54+
createNonEmptyDir()
55+
const { stdout } = run(['.'], { cwd: genPath })
56+
expect(stdout).toContain(`Current directory is not empty.`)
57+
})

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,27 @@
3131
"starter"
3232
],
3333
"scripts": {
34+
"preinstall": "npx only-allow pnpm",
3435
"watch": "vite build --watch",
3536
"build": "vite build",
3637
"prepublishOnly": "npm run build",
37-
"lint": "eslint .",
3838
"test": "vitest run"
3939
},
4040
"dependencies": {
4141
"prompts": "^2.4.2"
4242
},
4343
"devDependencies": {
44+
"@types/fs-extra": "^11.0.1",
4445
"@types/node": "^18.11.18",
4546
"@types/prompts": "^2.4.2",
4647
"execa": "^7.1.1",
48+
"fs-extra": "^11.1.1",
4749
"typescript": "^4.9.4",
4850
"vite": "^4.3.9",
4951
"vitest": "^0.29.3"
5052
},
5153
"engines": {
5254
"node": "^14.18.0 || >=16.0.0"
53-
}
55+
},
56+
"packageManager": "[email protected]"
5457
}

pnpm-lock.yaml

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)