Skip to content

Commit 8ca140a

Browse files
authored
fix(deploy): Correct import of deploy helper for Netlify and Vercel (#435)
1 parent 3ea88a7 commit 8ca140a

File tree

4 files changed

+74
-10
lines changed

4 files changed

+74
-10
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import execa from 'execa'
2+
import { vi, it, expect, afterAll } from 'vitest'
3+
4+
// @ts-expect-error JS file import
5+
import * as deployNetlify from '../netlify.js'
6+
7+
vi.mock('path')
8+
vi.mock('execa', () => ({ default: vi.fn() }))
9+
vi.mock('fs-extra')
10+
11+
vi.mock('@cedarjs/project-config', async () => ({
12+
getPaths: () => ({
13+
base: `${__dirname}/fixtures`,
14+
}),
15+
}))
16+
17+
vi.mock('@cedarjs/cli-helpers', async () => ({
18+
recordTelemetryAttributes: vi.fn(),
19+
}))
20+
21+
vi.spyOn(console, 'log').mockImplementation(() => {})
22+
23+
afterAll(() => {
24+
vi.restoreAllMocks()
25+
})
26+
27+
it('should export a command', async () => {
28+
expect(deployNetlify.command).toMatch(/netlify/)
29+
})
30+
31+
it('should export a description', async () => {
32+
expect(deployNetlify.description).toMatch('Build command for Netlify deploy')
33+
})
34+
35+
it('should export a builder function', async () => {
36+
const yargs = {
37+
option: vi.fn().mockImplementation(() => yargs),
38+
epilogue: vi.fn().mockImplementation(() => yargs),
39+
}
40+
41+
deployNetlify.builder(yargs)
42+
43+
expect(yargs.option).toHaveBeenCalledWith('build', {
44+
description: 'Build for production',
45+
type: 'boolean',
46+
default: 'true',
47+
})
48+
expect(yargs.option).toHaveBeenCalledWith('prisma', {
49+
description: 'Apply database migrations',
50+
type: 'boolean',
51+
default: 'true',
52+
})
53+
})
54+
55+
it('should export a handler function', async () => {
56+
await deployNetlify.handler({ build: true, prisma: false, dm: true })
57+
58+
expect(execa).toHaveBeenCalledWith(
59+
'yarn rw build --verbose && yarn rw data-migrate up',
60+
{
61+
shell: true,
62+
stdio: 'inherit',
63+
cwd: expect.stringContaining('fixtures'),
64+
extendEnv: true,
65+
cleanup: true,
66+
},
67+
)
68+
})

packages/cli/src/commands/deploy/helpers/deployHandler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { getPaths } from '@cedarjs/project-config'
44

55
import c from '../../../lib/colors.js'
66

7-
export const deployHandler = async ({ build, prisma, dm: dataMigrate }) => {
7+
export const deployHandler = ({ build, prisma, dm: dataMigrate }) => {
88
const paths = getPaths()
99

1010
let commandSet = []
@@ -20,7 +20,7 @@ export const deployHandler = async ({ build, prisma, dm: dataMigrate }) => {
2020

2121
const joinedCommands = commandSet.join(' && ')
2222

23-
console.log(c.note(`\nRunning:\n`) + `${joinedCommands} \n`)
23+
console.log(c.note('\nRunning:\n') + `${joinedCommands}\n`)
2424

2525
return execa(joinedCommands, {
2626
shell: true,

packages/cli/src/commands/deploy/netlify.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ export async function handler(yargs) {
1515
dataMigrate: yargs.dataMigrate,
1616
})
1717

18-
const { handler: importedHandler } = await import(
19-
'./helpers/deployHandler.js'
20-
)
18+
const { deployHandler } = await import('./helpers/deployHandler.js')
2119

22-
return importedHandler(yargs)
20+
return deployHandler(yargs)
2321
}

packages/cli/src/commands/deploy/vercel.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ export async function handler(yargs) {
1515
dataMigrate: yargs.dataMigrate,
1616
})
1717

18-
const { handler: importedHandler } = await import(
19-
'./helpers/deployHandler.js'
20-
)
18+
const { deployHandler } = await import('./helpers/deployHandler.js')
2119

22-
return importedHandler(yargs)
20+
return deployHandler(yargs)
2321
}

0 commit comments

Comments
 (0)