Skip to content

Commit

Permalink
(types): improve typings for Jest config
Browse files Browse the repository at this point in the history
  • Loading branch information
agilgur5 committed Mar 9, 2020
1 parent f19fa61 commit 9fef652
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/createJestConfig.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { Config } from '@jest/types';

export type JestConfigOptions = Partial<Config.InitialOptions>;

export function createJestConfig(
_: (relativePath: string) => void,
rootDir: string
) {
const config = {
): JestConfigOptions {
const config: JestConfigOptions = {
transform: {
'.(ts|tsx)$': require.resolve('ts-jest/dist'),
'.(js|jsx)$': require.resolve('babel-jest'), // jest's default
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import semver from 'semver';
import { paths } from './constants';
import * as Messages from './messages';
import { createBuildConfigs } from './createBuildConfigs';
import { createJestConfig } from './createJestConfig';
import { createJestConfig, JestConfigOptions } from './createJestConfig';
import { createEslintConfig } from './createEslintConfig';
import {
resolveApp,
Expand Down Expand Up @@ -499,7 +499,7 @@ prog
});

const argv = process.argv.slice(2);
let jestConfig = {
let jestConfig: JestConfigOptions = {
...createJestConfig(
relativePath => path.resolve(__dirname, '..', relativePath),
opts.config ? path.dirname(opts.config) : paths.appRoot
Expand All @@ -511,7 +511,7 @@ prog
const defaultPathExists = await fs.pathExists(paths.jestConfig);
if (opts.config || defaultPathExists) {
const jestConfigPath = resolveApp(opts.config || paths.jestConfig);
const jestConfigContents = require(jestConfigPath);
const jestConfigContents: JestConfigOptions = require(jestConfigPath);
jestConfig = { ...jestConfig, ...jestConfigContents };
}

Expand Down

0 comments on commit 9fef652

Please sign in to comment.