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

Run code transforms over global{Setup,Teardown} #7562

Merged
merged 6 commits into from
Jan 18, 2019

Conversation

SimenB
Copy link
Member

@SimenB SimenB commented Dec 29, 2018

Summary

Fixes #5164. A caveat is that this can not transpile stuff in node_modules. This is because in order to transpile using e.g. babel-jest, we would need to load babel-jest, which means we cannot transpile it.

We could try to do static analysis on the transformer modules defined in the config and create a dependency tree of the only files we won't transform, but I'm not sure if it's worth it (or possible). Stuff in node_modules should be runnable in node either way.

EDIT: If people want, we can disable node-modules ignoring, and try to catch errors during transform. By default, Jest has transformIgnorePattern on node_modules, so shouldn't make a huge difference

Test plan

I added a flow annotation to an existing test to show the transform happens.

import type {GlobalConfig} from 'types/Config';
import type {Test} from 'types/TestRunner';

import {extname, resolve} from 'path';
import pEachSeries from 'p-each-series';
Copy link
Member Author

Choose a reason for hiding this comment

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

using p-each-series allows us to make sure one require hook does not interfere with another

import type {GlobalConfig} from 'types/Config';
import type {Test} from 'types/TestRunner';

import {extname, resolve} from 'path';
import pEachSeries from 'p-each-series';
import {addHook} from 'pirates';
Copy link
Member Author

Choose a reason for hiding this comment

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

pirates is what babel-register uses

@SimenB SimenB force-pushed the transform-global-setup-teardown branch 3 times, most recently from 65a50f8 to 53e8f54 Compare December 30, 2018 10:43
@codecov-io
Copy link

codecov-io commented Dec 30, 2018

Codecov Report

Merging #7562 into master will decrease coverage by 0.35%.
The diff coverage is 30%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7562      +/-   ##
==========================================
- Coverage   68.28%   67.93%   -0.36%     
==========================================
  Files         250      248       -2     
  Lines        9627     9503     -124     
  Branches        5        5              
==========================================
- Hits         6574     6456     -118     
+ Misses       3051     3045       -6     
  Partials        2        2
Impacted Files Coverage Δ
packages/jest-cli/src/runGlobalHook.js 42.3% <30%> (-19.24%) ⬇️
packages/jest-cli/src/jest.js 0% <0%> (-100%) ⬇️
packages/jest-config/src/getCacheDirectory.js 80% <0%> (-7.5%) ⬇️
packages/jest-jasmine2/src/PCancelable.js 27.58% <0%> (-4.68%) ⬇️
packages/babel-jest/src/index.js 72.22% <0%> (-3.97%) ⬇️
packages/jest-environment-node/src/index.js 59.25% <0%> (-2.81%) ⬇️
packages/jest-environment-jsdom/src/index.js 37.5% <0%> (-1.53%) ⬇️
packages/jest-circus/src/utils.js 19.83% <0%> (-0.66%) ⬇️
packages/jest-snapshot/src/index.js 52% <0%> (-0.64%) ⬇️
packages/jest-runner/src/index.js 75.6% <0%> (-0.59%) ⬇️
... and 85 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 189bedc...8b3b505. Read the comment docs.

packages/jest-cli/src/runGlobalHook.js Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@SimenB SimenB force-pushed the transform-global-setup-teardown branch from da9c958 to 655d16e Compare December 31, 2018 16:04
Copy link
Collaborator

@thymikee thymikee left a comment

Choose a reason for hiding this comment

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

☠️ pirates!

packages/jest-cli/src/runGlobalHook.js Outdated Show resolved Hide resolved
packages/jest-cli/src/runGlobalHook.js Outdated Show resolved Hide resolved
@SimenB SimenB force-pushed the transform-global-setup-teardown branch from 655d16e to 8b3b505 Compare January 18, 2019 12:58
@SimenB SimenB force-pushed the transform-global-setup-teardown branch from 8b3b505 to 650a23e Compare January 18, 2019 13:09
Copy link
Member

@rickhanlonii rickhanlonii left a comment

Choose a reason for hiding this comment

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

Legit

@ezzabuzaid
Copy link

This doesn't work with "testEnvironment"

@SimenB
Copy link
Member Author

SimenB commented Jun 4, 2019

#8479

captain-yossarian pushed a commit to captain-yossarian/jest that referenced this pull request Jul 18, 2019
captain-yossarian pushed a commit to captain-yossarian/jest that referenced this pull request Jul 18, 2019
@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 May 11, 2021
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.

Make "globalSetup" and "globalTeardown" work together with "transform"
8 participants