Skip to content

[beta] warns the user if jest config transform matches js files without allowJs in tsconfig#724

Merged
huafu merged 2 commits intokulshekhar:betafrom
huafu:allow-js-detection
Sep 18, 2018
Merged

[beta] warns the user if jest config transform matches js files without allowJs in tsconfig#724
huafu merged 2 commits intokulshekhar:betafrom
huafu:allow-js-detection

Conversation

@huafu
Copy link
Copy Markdown
Collaborator

@huafu huafu commented Sep 17, 2018

Given a jest config with:

{
  // [...]
  transform: {
    '\\.(js|ts)$': 'ts-jest',
  }
}

and a tsconfig.json where allowJs compiler option is missing or set to false, ts-jest will be given .js files even tho it's not supposed to process them. TypeScript would bail in that case.

This PR make it so that input js code from .js files is returned unmodified (in the above described case), and a warning message is shown.

This kinda fixes confusions made such as in #721

@huafu huafu added this to the v23.10.0 milestone Sep 17, 2018
@huafu huafu mentioned this pull request Sep 17, 2018
5 tasks
@coveralls
Copy link
Copy Markdown

coveralls commented Sep 17, 2018

Pull Request Test Coverage Report for Build 1817

  • 18 of 19 (94.74%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 89.901%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/ts-jest-transformer.ts 15 16 93.75%
Totals Coverage Status
Change from base Build 1800: 0.1%
Covered Lines: 950
Relevant Lines: 1005

💛 - Coveralls

Comment thread src/ts-jest-transformer.ts Outdated
if (filePath.endsWith('.d.ts')) {
// do not try to compile declaration files
result = ''
} else if (!configs.typescript.options.allowJs && filePath.endsWith('.js')) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

should this also check for .jsx?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

oh yeah, thanks!

it('should return stringified version of file', () => {
config.shouldStringifyContent.mockImplementation(() => true)
expect(process()).toMatchInlineSnapshot(`"ts:module.exports=\\"export default \\\\\\"foo\\\\\\"\\""`)
expect(process()).toMatchInlineSnapshot(`"module.exports=\\"export default \\\\\\"foo\\\\\\"\\""`)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

this was actually a tiny "bug", files which should be transformed into modules returning their content were then going thru typescript, which was not needed at all, but not failing of course

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants