Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(jobs tests): Fix types #11349

Merged
merged 2 commits into from
Aug 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading