Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: use default import for fs-extra #11543

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 10 additions & 9 deletions packages/create-vite/__tests__/cli.spec.ts
@@ -1,7 +1,7 @@
import { join } from 'node:path'
import type { ExecaSyncReturnValue, SyncOptions } from 'execa'
import { execaCommandSync } from 'execa'
import { mkdirpSync, readdirSync, remove, writeFileSync } from 'fs-extra'
import fs from 'fs-extra'
import { afterEach, beforeAll, expect, test } from 'vitest'

const CLI_PATH = join(__dirname, '..')
Expand All @@ -19,29 +19,30 @@ const run = (
// Helper to create a non-empty directory
const createNonEmptyDir = () => {
// Create the temporary directory
mkdirpSync(genPath)
fs.mkdirpSync(genPath)

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

// Vue 3 starter template
const templateFiles = readdirSync(join(CLI_PATH, 'template-vue'))
const templateFiles = fs
.readdirSync(join(CLI_PATH, 'template-vue'))
// _gitignore is renamed to .gitignore
.map((filePath) => (filePath === '_gitignore' ? '.gitignore' : filePath))
.sort()

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

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

test('prompts for the framework if none supplied when target dir is current directory', () => {
mkdirpSync(genPath)
fs.mkdirpSync(genPath)
const { stdout } = run(['.'], { cwd: genPath })
expect(stdout).toContain('Select a framework:')
})
Expand Down Expand Up @@ -79,7 +80,7 @@ test('successfully scaffolds a project based on vue starter template', () => {
const { stdout } = run([projectName, '--template', 'vue'], {
cwd: __dirname,
})
const generatedFiles = readdirSync(genPath).sort()
const generatedFiles = fs.readdirSync(genPath).sort()

// Assertions
expect(stdout).toContain(`Scaffolding project in ${genPath}`)
Expand All @@ -90,7 +91,7 @@ test('works with the -t alias', () => {
const { stdout } = run([projectName, '-t', 'vue'], {
cwd: __dirname,
})
const generatedFiles = readdirSync(genPath).sort()
const generatedFiles = fs.readdirSync(genPath).sort()

// Assertions
expect(stdout).toContain(`Scaffolding project in ${genPath}`)
Expand Down