Skip to content

Commit

Permalink
chore(jobs tests): Fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe committed Aug 23, 2024
1 parent 008ec77 commit e566485
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions packages/cli/src/commands/setup/__tests__/jobsHandler.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
let mockExecutedTaskTitles = []
let mockSkippedTaskTitles = []
let mockExecutedTaskTitles: string[] = []
let mockSkippedTaskTitles: string[] = []

vi.mock('fs-extra')

import '../../../lib/mockTelemetry'

import type * as Listr from 'listr2'
import { vol, fs as memfsFs } from 'memfs'
import {
vi,
Expand All @@ -16,6 +17,9 @@ import {
afterAll,
} from 'vitest'

import type * as ProjectConfig from '@redwoodjs/project-config'

// @ts-expect-error - This is a JS file
import * as jobsHandler from '../jobs/jobsHandler.js'

vi.mock('fs', async () => ({ ...memfsFs, default: { ...memfsFs } }))
Expand All @@ -35,9 +39,10 @@ vi.mock('@redwoodjs/cli-helpers', () => ({
task: async () => {},
}),
}))

vi.mock('@redwoodjs/project-config', async (importOriginal) => {
const path = require('path')
const originalProjectConfig = await importOriginal()
const originalProjectConfig = await importOriginal<typeof ProjectConfig>()
return {
...originalProjectConfig,
getPaths: () => {
Expand All @@ -60,7 +65,10 @@ vi.mock('@redwoodjs/project-config', async (importOriginal) => {

vi.mock('listr2', async () => {
const ctx = {}
const listrImpl = (tasks, listrOptions) => {
const listrImpl = (
tasks: any[],
listrOptions?: Listr.ListrOptions | undefined,
) => {
return {
ctx,
run: async () => {
Expand All @@ -80,7 +88,7 @@ vi.mock('listr2', async () => {
const augmentedTask = {
...task,
newListr: listrImpl,
prompt: async (options) => {
prompt: async (options: any) => {
const enquirer = listrOptions?.injectWrapper?.enquirer

if (enquirer) {
Expand All @@ -90,14 +98,15 @@ vi.mock('listr2', async () => {
options[0].name = 'default'
}

const response = await enquirer.prompt(options)
const response: Record<string, any> =
await enquirer.prompt(options)

if (options.length === 1) {
return response.default
}
}
},
skip: (msg) => {
skip: (msg: string) => {
mockSkippedTaskTitles.push(msg || task.title)
},
}
Expand Down Expand Up @@ -135,9 +144,9 @@ beforeEach(() => {
'package.json': '{}',
'api/tsconfig.json': '',
'api/db/schema.prisma': '',
'api/src/lib': {},
'api/src/lib': null,
// api/src/jobs already exists – this should not cause an error
'api/src/jobs': {},
'api/src/jobs': null,
[__dirname + '/../jobs/templates/jobs.ts.template']: '',
},
'/path/to/project',
Expand Down

0 comments on commit e566485

Please sign in to comment.