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

New pipeline #236

Merged
merged 9 commits into from
May 30, 2017
Merged

New pipeline #236

merged 9 commits into from
May 30, 2017

Conversation

GeeWee
Copy link
Collaborator

@GeeWee GeeWee commented May 29, 2017

To resolve #235
Added 'json' moduleFileExtension, otherwise some tests fail.

I ported the babel-jest to our pipeline and started on something that might become a hook architecture at some point.

Would love to hear your thoughts.

Copy link
Owner

@kulshekhar kulshekhar left a comment

Choose a reason for hiding this comment

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

This looks promising :)

}

export interface PostProcessHook {
(src: string, filename: string, config: JestConfig, transformOptions: TransformOptions) : string;
Copy link
Owner

Choose a reason for hiding this comment

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

Would a new type to pass into this function be better than multiple params? It'll give a bit of flexibility if we want to change something. For instance, we might want to pass in the original source, the transpiled output and a sourcemap.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not opposed to the idea - this is just a rough draft. Does it make more sense to change the type now, or change it if/when we know what users want? I'm a little vary of overengineering.

Copy link
Owner

Choose a reason for hiding this comment

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

fair enough. We'll leave this as is for now

@@ -0,0 +1,56 @@
/**
* Postprocess step. Stolen from babel-jest: https://github.com/facebook/jest/blob/master/packages/babel-jest/src/index.js
Copy link
Owner

@kulshekhar kulshekhar May 29, 2017

Choose a reason for hiding this comment

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

'Based on' sounds better than 'Stolen' :)
Also, it might be better to use a link of a particular commit. So even if the file changes in the future, we'll have a reference to what this code was based on.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Haha true. Yes that's a good idea.

const outputText =
compilerOptions.allowSyntheticDefaultImports && !tsJestConfig.skipBabel
? babelJest.process(
const outputText = postHook(
tsTranspiled.outputText,
path + '.js', // babel-jest only likes .js files ¯\_(ツ)_/¯
Copy link
Owner

Choose a reason for hiding this comment

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

Should we take the opportunity to change the extension based on the source file? If it's .tsx, set it to .jsx otherwise set it to .js?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Damnit, I realised this I had forgotten this just as I left.
Actually to fix #211 we should just not modify the path - we don't need to fix it to pass babel's typechecks anymore.

Copy link
Owner

Choose a reason for hiding this comment

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

Does that mean we don't need to add .js any more?

Copy link
Collaborator Author

@GeeWee GeeWee May 29, 2017

Choose a reason for hiding this comment

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

Yep!
Edit: Or at least I'm 95% sure.

@@ -30,6 +27,7 @@ export function process(
const isTsFile = path.endsWith('.ts') || path.endsWith('.tsx');
const isJsFile = path.endsWith('.js') || path.endsWith('.jsx');
const isHtmlFile = path.endsWith('.html');
postHook = getPostProcessHook(compilerOptions, config, tsJestConfig);
Copy link
Owner

Choose a reason for hiding this comment

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

minor nit - indentation.

should there be a if postHook !== undefined around this? If not, is there any reason to declare it outside this function?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch!
No, that's an oversight - also a good catch!

@GeeWee
Copy link
Collaborator Author

GeeWee commented May 29, 2017

Will get around to fixes tomorrow I think

@kulshekhar
Copy link
Owner

@GeeWee If you can respond to my subsequent queries - I can push these changes in and you can review it tomorrow or when you have time

@GeeWee
Copy link
Collaborator Author

GeeWee commented May 29, 2017

Definitely - @kulshekhar, that'd be awesome. I think I got around to all of them - let me know if you need anything more

@GeeWee
Copy link
Collaborator Author

GeeWee commented May 30, 2017

Looks good to me atm.
Do we want some more tests to make sure we don't mangle sourcemaps, or do we think we know what we're doing? I don't know a lot about that part, I just noticed we don't actually test the process output anywhere.

@kulshekhar
Copy link
Owner

Well, the tests check it indirectly. For example, https://github.com/kulshekhar/ts-jest/blob/master/tests/__tests__/ts-coverage.spec.ts checks for the coverage which would only work if the process function worked fine and passed the sourcemap back to jest

}

//If we're not skipping babel
if (tsCompilerOptions.allowSyntheticDefaultImports) {
Copy link
Owner

Choose a reason for hiding this comment

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

This indicates that babel won't be used if allowSyntheticDefaultImports is not set to true?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Correct, and I want it to, but this necessitates changing tests, as using babel changes the coverage numbers slightly (the statement count is off by one) and I'd like to merge this in before making new changes that'll also necessitate changing tests.

Copy link
Owner

Choose a reason for hiding this comment

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

So once tests are updated, babel will always be used unless skipBabel is set, right?

If that's the case, open an issue so that we don't forget that, increase the version of ts-jest and merge it in. I'll publish it right away after that

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think #227 covers it?

Copy link
Owner

Choose a reason for hiding this comment

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

sounds good. Ping me when it's ready to publish

@GeeWee
Copy link
Collaborator Author

GeeWee commented May 30, 2017

Yes I see, that makes sense. I'd like some direct tests at one point, but baby steps.

I'm ready to merge this in if you are.

@GeeWee GeeWee merged commit 86a669f into master May 30, 2017
@GeeWee GeeWee deleted the new-pipeline branch May 30, 2017 08:56
@GeeWee GeeWee mentioned this pull request May 30, 2017
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.

Future of ts-jest babel integration
2 participants