Skip to content

feat: support tsconfig references #4689

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

sushruth
Copy link

@sushruth sushruth commented Feb 6, 2025

Summary

Fixes #1648 -

  1. By actively checking if at least some files in the parsed tsconfig actually pass isTestFile() check.
  2. If project references are found in the parsed tsconfig, we iterate over each reference until we find a config which has at least one file that passes isTestFile() check.
  3. If we do not find any within references, we default to previous behavior.

Test plan

TODO

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@sushruth sushruth force-pushed the sushruth/feat-support-tsconfig-references branch 2 times, most recently from 3644197 to c2eee48 Compare February 6, 2025 08:27
@ahnpnl ahnpnl marked this pull request as ready for review February 6, 2025 09:15
@ahnpnl ahnpnl requested a review from kulshekhar as a code owner February 6, 2025 09:15
@ahnpnl ahnpnl marked this pull request as draft February 6, 2025 09:15
@ahnpnl
Copy link
Collaborator

ahnpnl commented Feb 6, 2025

Would you pls add some tests for this change?

@sushruth
Copy link
Author

sushruth commented Feb 6, 2025

@ahnpnl Absolutely. That is the reason I have left it in draft stage. Thanks.

@sushruth sushruth force-pushed the sushruth/feat-support-tsconfig-references branch from c2eee48 to daec5b7 Compare February 11, 2025 07:04
@sushruth sushruth marked this pull request as ready for review February 11, 2025 11:05
@sushruth
Copy link
Author

@ahnpnl I added an e2e test case covering the tsconfig project references scenario. Please check it out when you can. Thanks!

@@ -790,7 +790,6 @@ describe('_resolveTsConfig', () => {
expect(conf.options.configFilePath).toBeUndefined()
expect(findConfig).not.toHaveBeenCalled()
expect(readConfig.mock.calls[0][0]).toBe('/foo/tsconfig.bar.json')
expect(parseConfig).not.toHaveBeenCalled()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will now be called to find out if we there are project references in the tsconfig to check.

@@ -918,7 +917,6 @@ describe('_resolveTsConfig', () => {

const conf = cs.parsedTsConfig
expect(conf.options.path).toBe(tscfgPathStub)
expect(findConfig).not.toHaveBeenCalled()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will now be called to find out if we there are project references in the tsconfig to check.

@ahnpnl ahnpnl requested a review from Copilot February 28, 2025 20:03
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR implements support for tsconfig project references by enhancing the tsconfig resolution and parsing logic in the configuration module while adding additional Jest configuration files for ESM and CJS compatibility.

  • Updated configuration resolution in src/legacy/config/config-set.ts to recursively resolve tsconfig references.
  • Added new Jest configuration files for both compiler and transpiler modes with ESM and CJS support in the e2e/tsconfig-projects directory.
  • Updated tests in config-set.spec.ts and provided a minimal test and implementation for foo functionality.

Reviewed Changes

File Description
e2e/tsconfig-projects/src/foo.spec.ts Added basic test spec for foo.
e2e/tsconfig-projects/jest-compiler-esm.config.ts Added Jest ESM configuration for compiler.
e2e/tsconfig-projects/jest-transpiler-esm.config.ts Added Jest ESM configuration for transpiler.
e2e/tsconfig-projects/jest-compiler-cjs.config.ts Added Jest CJS configuration for compiler.
e2e/tsconfig-projects/jest-transpiler-cjs.config.ts Added Jest CJS configuration for transpiler.
src/legacy/config/config-set.ts Refactored tsconfig resolution to support project references.
e2e/tsconfig-projects/src/foo.ts Updated foo to be an exported function.
src/legacy/config/config-set.spec.ts Adjusted tests in accordance with the new tsconfig resolution logic.

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

@coveralls
Copy link

coveralls commented Mar 4, 2025

Pull Request Test Coverage Report for Build 13685876864

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 44 of 53 (83.02%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.1%) to 95.139%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/legacy/config/config-set.ts 44 53 83.02%
Totals Coverage Status
Change from base Build 13608443062: -0.1%
Covered Lines: 4807
Relevant Lines: 4994

💛 - Coveralls

Through this change, we restrict the use of jest globals in the shared source file of the monorepo-app, while allowing them in test files.
@ahnpnl ahnpnl requested a review from Copilot March 5, 2025 12:05
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR adds support for tsconfig references, enabling the tool to resolve project references and verify test files across projects.

  • Implements logic to traverse tsconfig project references and validate files using the isTestFile() check.
  • Introduces several new Jest configuration files to support both ESM and CJS setups.
  • Adds a basic test and corresponding source file for the foo function.

Reviewed Changes

File Description
e2e/tsconfig-projects/src/foo.spec.ts Adds a basic test for the exported foo function.
e2e/tsconfig-projects/jest-compiler-esm.config.ts Adds Jest configuration for ESM via compiler.
e2e/tsconfig-projects/jest-transpiler-esm.config.ts Adds Jest configuration for ESM via transpiler.
e2e/tsconfig-projects/jest-compiler-cjs.config.ts Adds Jest configuration for CJS via compiler.
e2e/tsconfig-projects/jest-transpiler-cjs.config.ts Adds Jest configuration for CJS via transpiler.
e2e/tsconfig-projects/src/foo.ts Exports the foo function.

Copilot reviewed 22 out of 22 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

e2e/tsconfig-projects/src/foo.spec.ts:1

  • The new tsconfig references behavior is not explicitly covered by tests. Consider adding tests that exercise the traversal of project references and validate the isTestFile() check in a dedicated test file.
import { foo } from './foo'

@sushruth
Copy link
Author

sushruth commented Mar 5, 2025

@kulshekhar Please review once. This supports typescript project references for ts-jest.

ahnpnl
ahnpnl previously approved these changes Mar 5, 2025
@ahnpnl
Copy link
Collaborator

ahnpnl commented Mar 7, 2025

Hi @sushruth would you pls sync with main due to a conflict? Thanks 🙏

@sushruth sushruth force-pushed the sushruth/feat-support-tsconfig-references branch from fe0fbb9 to d0d9136 Compare March 12, 2025 22:52
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tests fail when using TypeScript project references
3 participants