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

[heft] Add support for Jest to heft. #1966

Merged
merged 8 commits into from
Jul 15, 2020

Conversation

iclanton
Copy link
Member

No description provided.

@iclanton iclanton force-pushed the ianc/heft-api-extractor branch 3 times, most recently from e4e614d to faff2b4 Compare July 7, 2020 23:49

"rootDir": "../../../../",
"testURL": "http://localhost/",
"testMatch": ["<rootDir>/lib/**/*.test.js"]
Copy link
Collaborator

@octogonz octogonz Jul 8, 2020

Choose a reason for hiding this comment

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

  1. For the heft-test-01 project, modify the snapshot test like this:
  it('Correctly handles snapshots', () => {
    expect({ modified: 1, b: 2, c: 3 }).toMatchSnapshot();
  });
  1. Run heft test --clean. It shows:
Tests finished:
  Successes: 1
  Failures: 1
  Total: 2
  1. Now run jest directly. It shows:
Test Suites: 4 failed, 3 passed, 7 total
Tests:       4 failed, 10 passed, 14 total
Snapshots:   4 failed, 1 file obsolete, 3 written, 7 total

The reason is that it is matching paths like .heft/build-cache/lib/test/ExampleTest.test.js.

To the fullest extent possible, we need the vanilla Jest CLI to behave identically as Heft's harness.

Copy link
Collaborator

@octogonz octogonz Jul 8, 2020

Choose a reason for hiding this comment

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

we need the vanilla Jest CLI to behave identically as Heft's harness.

Let me amend this statement based on some more experimentation: The following tools all like to pretend that they are a complete toolchain:

  • Webpack
  • Jest
  • tsc --build

But they cannot realistically reproduce the entire Heft toolchain. They will fall apart when it comes to things like:

Perhaps our long-term philosophy will be like this:

  • When invoked via the CLI, these tools should see config files that process their isolated inputs/outputs only
  • If you run the vanilla CLIs, they should produce the same outputs that Heft would, assuming that Heft has prepared their inputs (e.g. jest will succeed only if Heft has created the .js inputs)
  • Similarly, alternative hosts like the Jest VS Code extension only expected to work after Heft has prepared things; we should aim to polish this experience however possible
  • Heft's features like --watch must be feature complete and expected to completely replace the vanilla CLIs
  • Wherever feasible, the configs should block vanilla CLI features like jest --watch that are not going to be meaningful

Does that make sense? The alternative would be to fully integrate Heft into each of these CLIs (i.e. replacing ts-jest, ts-loader, etc) which seems unrealistically expensive in general.

This also gives us an answer for the longstanding issue of const enum not working with Webpack.

@iclanton iclanton force-pushed the ianc/heft-api-extractor branch from faff2b4 to e9a22a8 Compare July 14, 2020 20:49
@iclanton
Copy link
Member Author

This is in a generally usable state, but there are a few limitations:

  • A race condition can occur between TS and Jest in --watch mode, where Jest detects that the TS file has changed before its compiled output has been written
  • New test files aren't correctly picked up in --watch mode.

@iclanton iclanton merged commit 52fbcbd into microsoft:master Jul 15, 2020
@iclanton iclanton deleted the ianc/heft-api-extractor branch July 15, 2020 03:04
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.

2 participants