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: do not bundle @jest/types #12773

Closed

Conversation

mrazauskas
Copy link
Contributor

@mrazauskas mrazauskas commented Apr 29, 2022

Fixes #12772

Summary

#12772 seems to get fixed, if definitions of @jest/types are not bundled.


tsc generates the following definitions for @jest/reporters:

import type { Config } from '@jest/types';
export declare const utils: {
  formatTestPath: (config: import("@jest/types/build/Config").GlobalConfig | import("@jest/types/build/Config").ProjectConfig, testPath: string) => string;
  printDisplayName: (config: import("@jest/types/build/Config").ProjectConfig) => string;
  // ...
};

The bundler turns them into:

import {GlobalConfig} from '@jest/types/build/Config';
import {ProjectConfig} from '@jest/types/build/Config';
export declare const utils: {
  formatTestPath: (
    config: GlobalConfig | ProjectConfig,
    testPath: string,
  ) => string;
  printDisplayName: (config: ProjectConfig) => string;
}

Test plan

Needs a test.

@mrazauskas
Copy link
Contributor Author

mrazauskas commented Apr 29, 2022

Interesting. If star exports in @jest/types are refactored into namespaces, here is what we get:

tsc generates the following definitions for @jest/reporters (better, it does not reach into build):

export type { Config } from '@jest/types';
export declare const utils: {
  formatTestPath: (config: import("@jest/types").Config.GlobalConfig | import("@jest/types").Config.ProjectConfig, testPath: string) => string;
  // ...
}

Unfortunately, bundling is still messed up:

import {Config} from '@jest/types';
export declare const utils: {
  formatTestPath: (config: Config | Config, testPath: string) => string;
  // Error: Cannot use namespace 'Config' as a type.
}

@mrazauskas
Copy link
Contributor Author

mrazauskas commented Apr 29, 2022

Refactored utils import in @jest/reporters into a star import.

tsc generates:

import * as utils from './utils';
export type { Config } from '@jest/types';
export { utils };

Bundling goes like this:

import {Config} from '@jest/types';

declare const formatTestPath: (
  config: Config.GlobalConfig | Config.ProjectConfig,
  testPath: string,
) => string;

declare const printDisplayName: (config: Config.ProjectConfig) => string;

declare namespace utils {
  export {
    formatTestPath,
    printDisplayName,
    // ...
  };
}

export {utils};

Seems like it got fixed. I must write some tests.

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: @jest/reporters@28.0.3 fails TypeScript type checking
2 participants