Skip to content

Commit

Permalink
test: use default import for fs-extra
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Dec 31, 2022
1 parent f12a1ab commit eab9e65
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions packages/create-vite/__tests__/cli.spec.ts
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit eab9e65

Please sign in to comment.