From c73128249bc7799c4f96a6d9ba7542aa5b39ade9 Mon Sep 17 00:00:00 2001 From: Bibiana Sebestianova Date: Thu, 3 Oct 2024 14:14:16 +0200 Subject: [PATCH] feat(CLI): test regrouping + --no-publish test --- packages/cli/src/__tests__/main.test.ts | 90 ++++++++++++++----------- 1 file changed, 51 insertions(+), 39 deletions(-) diff --git a/packages/cli/src/__tests__/main.test.ts b/packages/cli/src/__tests__/main.test.ts index bd3cc4d9..f60d9209 100644 --- a/packages/cli/src/__tests__/main.test.ts +++ b/packages/cli/src/__tests__/main.test.ts @@ -1,38 +1,53 @@ import { createCLI } from '../main' import { create, add, deploy } from '../commands' -import { vi } from 'vitest' +import { describe, vi } from 'vitest' vi.mock('../commands') const DEFAULT_ARGS = ['node', 'main.ts'] // cli.parse() should receive the executable and its arget as its first two arguments. describe('main', () => { - describe('default arguments', () => { - it('create command', () => { - const cli = createCLI() - cli.parse([...DEFAULT_ARGS, 'create']) - expect(create).toHaveBeenCalledWith({ dir: '.' }) - }) - - it('add command', () => { + describe('add command', () => { + it('default arguments', () => { const cli = createCLI() cli.parse([...DEFAULT_ARGS, 'add']) expect(add).toHaveBeenCalledWith({ dir: '.' }) }) - it('deploy command', () => { + it('full arguments', () => { const cli = createCLI() - cli.parse([...DEFAULT_ARGS, 'deploy']) - expect(deploy).toHaveBeenCalledWith({ - dir: '.', - skipPrompts: false, - publish: true, + cli.parse([ + ...DEFAULT_ARGS, + 'add', + '--template', + 'react', + '--name', + 'my-test-plugin', + '--dir', + 'my-directory', + '--structure', + 'standalone', + '--packageManager', + 'npm', + ]) + expect(add).toHaveBeenCalledWith({ + template: 'react', + name: 'my-test-plugin', + dir: 'my-directory', + structure: 'standalone', + packageManager: 'npm', }) }) }) - describe('full arguments', () => { - it('create command', () => { + describe('create command', () => { + it('default arguments', () => { + const cli = createCLI() + cli.parse([...DEFAULT_ARGS, 'create']) + expect(create).toHaveBeenCalledWith({ dir: '.' }) + }) + + it('full arguments', () => { const cli = createCLI() cli.parse([ ...DEFAULT_ARGS, @@ -53,33 +68,30 @@ describe('main', () => { repoName: 'my-test-repo', }) }) + }) - it('add command', () => { + describe('deploy command', () => { + it('--no-publish', () => { const cli = createCLI() - cli.parse([ - ...DEFAULT_ARGS, - 'add', - '--template', - 'react', - '--name', - 'my-test-plugin', - '--dir', - 'my-directory', - '--structure', - 'standalone', - '--packageManager', - 'npm', - ]) - expect(add).toHaveBeenCalledWith({ - template: 'react', - name: 'my-test-plugin', - dir: 'my-directory', - structure: 'standalone', - packageManager: 'npm', + cli.parse([...DEFAULT_ARGS, 'deploy', '--no-publish']) + expect(deploy).toHaveBeenCalledWith({ + dir: '.', + publish: false, + skipPrompts: false, + }) + }) + + it('default options', () => { + const cli = createCLI() + cli.parse([...DEFAULT_ARGS, 'deploy']) + expect(deploy).toHaveBeenCalledWith({ + dir: '.', + skipPrompts: false, + publish: true, }) }) - it('deploy command', () => { + it('full arguments', () => { const cli = createCLI() cli.parse([ ...DEFAULT_ARGS,