test(cli): extract baseCommand for new
This commit is contained in:
parent
56592bdeef
commit
f77f78f459
1 changed files with 11 additions and 12 deletions
|
@ -1,24 +1,26 @@
|
||||||
import { expect, test, vi } from "vitest";
|
import { beforeAll, expect, test, vi } from "vitest";
|
||||||
import { exportedForTest } from "../commands/new.mjs";
|
import { exportedForTest } from "../commands/new.mjs";
|
||||||
import { execSync } from "node:child_process";
|
import { execSync } from "node:child_process";
|
||||||
|
|
||||||
const testFn = exportedForTest.createNew;
|
const testFn = exportedForTest.createNew;
|
||||||
|
const baseCommand = `npm create mcfly@latest`
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
vi.mock('node:child_process');
|
||||||
|
})
|
||||||
|
|
||||||
test("execute create mcfly", () => {
|
test("execute create mcfly", () => {
|
||||||
const command = `npm create mcfly@latest`
|
|
||||||
const param = {stdio: 'inherit'}
|
const param = {stdio: 'inherit'}
|
||||||
vi.mock('node:child_process');
|
|
||||||
|
|
||||||
testFn({dir: undefined})
|
testFn({dir: undefined})
|
||||||
|
|
||||||
expect(execSync).toHaveBeenCalledWith(command, param)
|
expect(execSync).toHaveBeenCalledWith(baseCommand, param)
|
||||||
})
|
})
|
||||||
|
|
||||||
test("execute create mcfly with no dir", () => {
|
test("execute create mcfly with no dir", () => {
|
||||||
const dir = 'fake-dir'
|
const dir = 'fake-dir'
|
||||||
const command = `npm create mcfly@latest ${dir}`
|
const command = `${baseCommand} ${dir}`
|
||||||
const param = {stdio: 'inherit'}
|
const param = {stdio: 'inherit'}
|
||||||
vi.mock('node:child_process');
|
|
||||||
|
|
||||||
testFn({dir: undefined})
|
testFn({dir: undefined})
|
||||||
|
|
||||||
|
@ -27,9 +29,8 @@ test("execute create mcfly with no dir", () => {
|
||||||
|
|
||||||
test("execute create mcfly with dir", () => {
|
test("execute create mcfly with dir", () => {
|
||||||
const dir = 'fake-dir'
|
const dir = 'fake-dir'
|
||||||
const command = `npm create mcfly@latest ${dir}`
|
const command = `${baseCommand} ${dir}`
|
||||||
const param = {stdio: 'inherit'}
|
const param = {stdio: 'inherit'}
|
||||||
vi.mock('node:child_process');
|
|
||||||
|
|
||||||
testFn({dir})
|
testFn({dir})
|
||||||
|
|
||||||
|
@ -38,9 +39,8 @@ test("execute create mcfly with dir", () => {
|
||||||
|
|
||||||
test("execute create mcfly with _dir", () => {
|
test("execute create mcfly with _dir", () => {
|
||||||
const dir = 'fake-dir'
|
const dir = 'fake-dir'
|
||||||
const command = `npm create mcfly@latest ${dir}`
|
const command = `${baseCommand} ${dir}`
|
||||||
const param = {stdio: 'inherit'}
|
const param = {stdio: 'inherit'}
|
||||||
vi.mock('node:child_process');
|
|
||||||
|
|
||||||
testFn({_dir: dir})
|
testFn({_dir: dir})
|
||||||
|
|
||||||
|
@ -49,9 +49,8 @@ test("execute create mcfly with _dir", () => {
|
||||||
|
|
||||||
test("execute create mcfly with dir preferred over _dir", () => {
|
test("execute create mcfly with dir preferred over _dir", () => {
|
||||||
const dir = 'preferred-dir'
|
const dir = 'preferred-dir'
|
||||||
const command = `npm create mcfly@latest ${dir}`
|
const command = `${baseCommand} ${dir}`
|
||||||
const param = {stdio: 'inherit'}
|
const param = {stdio: 'inherit'}
|
||||||
vi.mock('node:child_process');
|
|
||||||
|
|
||||||
testFn({dir: dir, _dir: 'not-preferred'})
|
testFn({dir: dir, _dir: 'not-preferred'})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue