Skip to content

Commit

Permalink
feat(CLI): test regrouping + --no-publish test
Browse files Browse the repository at this point in the history
  • Loading branch information
BibiSebi committed Oct 3, 2024
1 parent 3a6d8b9 commit c731282
Showing 1 changed file with 51 additions and 39 deletions.
90 changes: 51 additions & 39 deletions packages/cli/src/__tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit c731282

Please sign in to comment.