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

Enable using 'ts-jest' package name as transform (Take 2) + fix #367 #373

Merged

Conversation

martijnthe
Copy link
Contributor

@martijnthe martijnthe commented Nov 12, 2017

@kulshekhar @screendriver @GeeWee I dug into #367
The bug is in babel-core: babel/babel#6524

What changed was that require('ts-jest') would end up requiring babel-core (it's used by the process() function), whereas before my patch it did not do that. To avoid hitting the babel-core bug, I changed the code to lazily require() the preprocessor, so that babel-core does not get dragged in when require('ts-jest').install() runs.

I changed the scripts/tests.js to copy the package sources, replacing the require('../../../../etc') hack. For some reason, I could not get #367 to happen in the integration test that I added with that hack in place.
I think it's better now because 1) the thing under test is not modified, but instead the code as it will be distributed gets tested 2) the Jest "transform" configuration in the package.json does no longer refer to a parent path, but the config that one would normally use in a real project.

In this PR I re-reverted #368 and added the bugfix on top of it.

Martijn The added 3 commits November 12, 2017 19:58
… to avoid hitting "Cannot find module '../../package' from 'node.js'" error

- Change scripts/tests.js to copy the package sources, replacing the require('../../../../etc') hack (which for some reason caused kulshekhar#367 not to trip!?)
@martijnthe martijnthe changed the title Change entry to preprocessor.js (Take 2) Enable using 'ts-jest' package name as transform (Take 2) + fix #367 Nov 12, 2017
@martijnthe
Copy link
Contributor Author

I changed the title because "Change entry to preprocessor.js" is not longer true.

index.js Outdated
},
install: require('./dist/install').install,
};
Copy link
Owner

Choose a reason for hiding this comment

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

You'd want to export the getCacheKey function here as well, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, good catch, thanks!

@@ -1,7 +1,7 @@
{
"jest": {
"transform": {
".(ts|tsx)": "../../preprocessor.js"
".(ts|tsx)": "ts-jest"
Copy link
Owner

Choose a reason for hiding this comment

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

This applies to all test files with similar changes

This doesn't look right. Using ../../preprocessor.js makes sure that the tests run on the current source code. Wouldn't using ts-jest (directly or with <rootDir> cause the tests to use the previously published version of ts-jest?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using ../../preprocessor.js makes sure that the tests run on the current source code. Wouldn't using ts-jest (directly or with cause the tests to use the previously published version of ts-jest?

No, I changed scripts/tests.js to copy the current source code under each test project's node_packages/ts-jest/**:

/~https://github.com/kulshekhar/ts-jest/pull/373/files#diff-0c26479cc3f82df625bd35543ed2aee0R51

"allowJs": true,
"baseUrl": "src"
}
}
Copy link
Owner

Choose a reason for hiding this comment

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

Need a blank line at the end here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. fwiw, this was copy pasted from imports-test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@screendriver
Copy link
Contributor

Cool thanks 👍

-- Add missing getCacheKey() to the ts-jest module interface
-- Fix missing newlines at end of tsconfig.json
- Add integration test case to test the interface of the ts-jest module
- Add missing index.d.ts, this no longer gets generated automatically because there is no longer a index.ts
}

declare const tsJestModule: TsJestModule;
export = tsJestModule;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kulshekhar:
While writing the new ts-jest-module-interface test case, I found out that dist/index.d.ts was missing.
I just added this file to replace it. This reflects the manually written index.js. Its gets copied to dist/ as part of the "build" package script.

@kulshekhar
Copy link
Owner

Something seems to have broken the build

@martijnthe
Copy link
Contributor Author

Something seems to have broken the build

@kulshekhar Fixed it!

@martijnthe
Copy link
Contributor Author

@kulshekhar could you take another look? Thanks!

@kulshekhar
Copy link
Owner

I'm not sure I'm gonna have the time needed to look again closely at this in the next few days.

So I'm gonna go ahead and merge and publish this now and can revisit this in case this breaks things for someone!

@kulshekhar kulshekhar merged commit 958d84d into kulshekhar:master Nov 17, 2017
@kulshekhar
Copy link
Owner

@martijnthe this has been published. Thanks for the PR!

@martijnthe
Copy link
Contributor Author

@kulshekhar thanks!

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.

3 participants