feat(testing): add type annotation for Jest configuration export (#30059)

This commit is contained in:
Denis Bendrikov 2025-02-17 14:49:07 +02:00 committed by GitHub
parent d8345147ed
commit af930c396d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 11 additions and 7 deletions

View File

@ -1,5 +1,6 @@
import type { Config } from 'jest';
import { getJestProjectsAsync } from '@nx/jest';
export default async () => ({
export default async (): Promise<Config> => ({
projects: await getJestProjectsAsync(),
});

View File

@ -1,9 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`createJestConfig should generate files 1`] = `
"import { getJestProjectsAsync } from '@nx/jest';
"import type { Config } from 'jest';
import { getJestProjectsAsync } from '@nx/jest';
export default async () => ({
export default async (): Promise<Config> => ({
projects: await getJestProjectsAsync()
});"
`;

View File

@ -153,9 +153,10 @@ export default {
"
`);
expect(tree.read('jest.config.ts', 'utf-8'))
.toEqual(`import { getJestProjectsAsync } from '@nx/jest';
.toEqual(`import type { Config } from 'jest';
import { getJestProjectsAsync } from '@nx/jest';
export default async () => ({
export default async (): Promise<Config> => ({
projects: await getJestProjectsAsync()
});`);
expect(readProjectConfiguration(tree, 'my-project').targets.test)

View File

@ -151,9 +151,10 @@ function generateGlobalConfig(tree: Tree, isJS: boolean) {
module.exports = async () => ({
projects: await getJestProjectsAsync()
});`
: `import { getJestProjectsAsync } from '@nx/jest';
: `import type { Config } from 'jest';
import { getJestProjectsAsync } from '@nx/jest';
export default async () => ({
export default async (): Promise<Config> => ({
projects: await getJestProjectsAsync()
});`;
tree.write(`jest.config.${isJS ? 'js' : 'ts'}`, contents);