Unverified Commit 20d8e93d authored by Connor Prussin's avatar Connor Prussin Committed by GitHub

Correct some jest types (#48923)

# 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.
parent 44dc4efa
...@@ -8,6 +8,7 @@ import * as Log from '../output/log' ...@@ -8,6 +8,7 @@ import * as Log from '../output/log'
import { findPagesDir } from '../../lib/find-pages-dir' import { findPagesDir } from '../../lib/find-pages-dir'
import { loadBindings, lockfilePatchPromise } from '../swc' import { loadBindings, lockfilePatchPromise } from '../swc'
import type { JestTransformerConfig } from '../swc/jest-transformer' import type { JestTransformerConfig } from '../swc/jest-transformer'
import type { Config } from '@jest/types'
async function getConfig(dir: string) { async function getConfig(dir: string) {
const conf = await loadConfig(PHASE_TEST, dir) const conf = await loadConfig(PHASE_TEST, dir)
...@@ -56,10 +57,14 @@ module.exports = createJestConfig(customJestConfig) ...@@ -56,10 +57,14 @@ module.exports = createJestConfig(customJestConfig)
*/ */
export default function nextJest(options: { dir?: string } = {}) { export default function nextJest(options: { dir?: string } = {}) {
// createJestConfig // createJestConfig
return (customJestConfig?: any) => { return (
customJestConfig?:
| Config.InitialProjectOptions
| (() => Promise<Config.InitialProjectOptions>)
) => {
// Function that is provided as the module.exports of jest.config.js // Function that is provided as the module.exports of jest.config.js
// Will be called and awaited by Jest // Will be called and awaited by Jest
return async () => { return async (): Promise<Config.InitialProjectOptions> => {
let nextConfig let nextConfig
let jsConfig let jsConfig
let resolvedBaseUrl let resolvedBaseUrl
......
...@@ -37,7 +37,8 @@ import type { ...@@ -37,7 +37,8 @@ import type {
import type { Config } from '@jest/types' import type { Config } from '@jest/types'
import type { NextConfig, ExperimentalConfig } from '../../server/config-shared' import type { NextConfig, ExperimentalConfig } from '../../server/config-shared'
export interface JestTransformerConfig { type TransformerConfig = Config.TransformerConfig[1]
export interface JestTransformerConfig extends TransformerConfig {
jsConfig: any jsConfig: any
resolvedBaseUrl?: string resolvedBaseUrl?: string
pagesDir?: string pagesDir?: string
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment