Skip to content

Commit

Permalink
Correct some jest types (#48923)
Browse files Browse the repository at this point in the history
# What?

This PR just refines some of the typescript types around `nextJest`, specifically refining the argument `customJestConfig` and the return value.

### Why?

Before this PR, the return type of `nextJest` was inferred by typescript as `any` which is inaccurate and would require type casting for typescript to enable it to be used in a jest configuration written in typescript.


I didn't add an issue for this since it was so trivial, but I can do so if it would be helpful.
  • Loading branch information
cprussin committed Apr 28, 2023
1 parent 44dc4ef commit 20d8e93
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions packages/next/src/build/jest/jest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as Log from '../output/log'
import { findPagesDir } from '../../lib/find-pages-dir'
import { loadBindings, lockfilePatchPromise } from '../swc'
import type { JestTransformerConfig } from '../swc/jest-transformer'
import type { Config } from '@jest/types'

async function getConfig(dir: string) {
const conf = await loadConfig(PHASE_TEST, dir)
Expand Down Expand Up @@ -56,10 +57,14 @@ module.exports = createJestConfig(customJestConfig)
*/
export default function nextJest(options: { dir?: string } = {}) {
// createJestConfig
return (customJestConfig?: any) => {
return (
customJestConfig?:
| Config.InitialProjectOptions
| (() => Promise<Config.InitialProjectOptions>)
) => {
// Function that is provided as the module.exports of jest.config.js
// Will be called and awaited by Jest
return async () => {
return async (): Promise<Config.InitialProjectOptions> => {
let nextConfig
let jsConfig
let resolvedBaseUrl
Expand Down
3 changes: 2 additions & 1 deletion packages/next/src/build/swc/jest-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ import type {
import type { Config } from '@jest/types'
import type { NextConfig, ExperimentalConfig } from '../../server/config-shared'

export interface JestTransformerConfig {
type TransformerConfig = Config.TransformerConfig[1]
export interface JestTransformerConfig extends TransformerConfig {
jsConfig: any
resolvedBaseUrl?: string
pagesDir?: string
Expand Down

0 comments on commit 20d8e93

Please sign in to comment.