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

[DX] Improve tests experience #99

Merged
merged 17 commits into from
Oct 2, 2024
Merged

Conversation

yoannmoinet
Copy link
Member

What and why?

In preparation for the internal injection plugin we need to re-enforce how we use the bundlers in our tests.

We also need to untie the GlobalContext from any plugin.

Finally, extract some helpers that will be needed for the injection plugin.

How?

  • Seed our builds during the tests, whenever we run runBundlers the build will happen in a seeded directory and will return a cleaning function.
  • Add custom jest matchers.
  • Aggregate and extract helpers getAbsolutePath, getResolvedPath, truncateString and doRequest.
  • Create a Bundle Report plugin and remove the GlobalContext initialisation from any internal plugin (it will simplify its usage for the injection plugin).

Comment on lines -78 to -86
// TODO: Add support and add outputFiles to the context.
rspack(compiler) {
globalContext.bundler.rawConfig = compiler.options;
},
farm: {
configResolved(config: any) {
globalContext.bundler.rawConfig = config;
},
},
Copy link
Member Author

Choose a reason for hiding this comment

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

This was dead code.

@yoannmoinet yoannmoinet marked this pull request as ready for review September 27, 2024 15:53
@yoannmoinet yoannmoinet requested a review from a team as a code owner September 27, 2024 15:53
@yoannmoinet yoannmoinet requested review from nchapma2 and removed request for a team September 27, 2024 15:53
@elbywan elbywan self-requested a review September 30, 2024 12:12
try {
return require.resolve(filepath);
} catch (e) {
export const getAbsolutePath = (filepath: string, cwd: string) => {
Copy link
Member

Choose a reason for hiding this comment

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

TBH the order of the arguments confused me a bit since they are reversed when applied to path.resolve (and the leftmost cwd path ends up being the last function argument):
filepath: string, cwd: string -> path.resolve(cwd, filepath)

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, it got me a few times too.
I'll change it, just needed a little nudge to convince me.

@yoannmoinet yoannmoinet removed the request for review from nchapma2 October 1, 2024 13:17
@yoannmoinet yoannmoinet merged commit 6bc57e1 into master Oct 2, 2024
5 checks passed
@yoannmoinet yoannmoinet deleted the yoann/improve-tests-experience branch October 2, 2024 10:05
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