diff --git a/packages/cli/test/new.test.js b/packages/cli/test/new.test.js index b76cabc..6daf923 100644 --- a/packages/cli/test/new.test.js +++ b/packages/cli/test/new.test.js @@ -1,24 +1,26 @@ -import { expect, test, vi } from "vitest"; +import { beforeAll, expect, test, vi } from "vitest"; import { exportedForTest } from "../commands/new.mjs"; import { execSync } from "node:child_process"; const testFn = exportedForTest.createNew; +const baseCommand = `npm create mcfly@latest` + +beforeAll(() => { + vi.mock('node:child_process'); +}) test("execute create mcfly", () => { - const command = `npm create mcfly@latest` const param = {stdio: 'inherit'} - vi.mock('node:child_process'); testFn({dir: undefined}) - expect(execSync).toHaveBeenCalledWith(command, param) + expect(execSync).toHaveBeenCalledWith(baseCommand, param) }) test("execute create mcfly with no dir", () => { const dir = 'fake-dir' - const command = `npm create mcfly@latest ${dir}` + const command = `${baseCommand} ${dir}` const param = {stdio: 'inherit'} - vi.mock('node:child_process'); testFn({dir: undefined}) @@ -27,9 +29,8 @@ test("execute create mcfly with no dir", () => { test("execute create mcfly with dir", () => { const dir = 'fake-dir' - const command = `npm create mcfly@latest ${dir}` + const command = `${baseCommand} ${dir}` const param = {stdio: 'inherit'} - vi.mock('node:child_process'); testFn({dir}) @@ -38,9 +39,8 @@ test("execute create mcfly with dir", () => { test("execute create mcfly with _dir", () => { const dir = 'fake-dir' - const command = `npm create mcfly@latest ${dir}` + const command = `${baseCommand} ${dir}` const param = {stdio: 'inherit'} - vi.mock('node:child_process'); testFn({_dir: dir}) @@ -49,9 +49,8 @@ test("execute create mcfly with _dir", () => { test("execute create mcfly with dir preferred over _dir", () => { const dir = 'preferred-dir' - const command = `npm create mcfly@latest ${dir}` + const command = `${baseCommand} ${dir}` const param = {stdio: 'inherit'} - vi.mock('node:child_process'); testFn({dir: dir, _dir: 'not-preferred'})