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

Fix esbuild tests #676

Merged
merged 1 commit into from
Oct 19, 2024
Merged

Conversation

into-the-v0id
Copy link
Contributor

@into-the-v0id into-the-v0id commented Oct 19, 2024

Description

The Test Snapshot esbuild plugin with JSX 3 contains:

  • The actual output JS file/page but with a data.url of /_.._/esbuild_jsx/main.js and no src connection
  • A source file /main.jsx without any transformations and with a src connection

This is not the desired output. It should look something like this:

  • Only one /main.js bundle with a src connection

This happens because the esbuild plugin (accidentally ?) modifies their plugin defaults:

const options = merge(defaults, userOptions);
// ...
options.options.absWorkingDir ||= site.src();
const basePath = options.options.absWorkingDir;

This way the absWorkingDir option leaks from the first esbuild test to the other tests. All the esbuild tests use test/assets/esbuild as src -- except the esbuild plugin with JSX test which uses the test/assets/esbuild_jsx dir. However, because of the option leak we configure esbuild with a absWorkingDir of test/assets/esbuild instead of test/assets/esbuild_jsx. Mapping of esbuild output files fails and the output JS is added as a chunk. The /_.._/ part seems to be an "escaped" /../.

You can verify this by running all the esbuild tests (without the PR patch):
deno task test ./tests/esbuild.test.ts - they should all pass
And then run only the esbuild plugin with JSX test (without the PR patch):
deno task test ./tests/esbuild.test.ts --filter '/^esbuild plugin with JSX$/' - this should fail and the diff should display the changes mentioned above (actual / desired output)

This PR changes the way the absWorkingDir option is handled to not modify the plugin defaults. I have also updated the esbuild plugin with JSX 3 snapshot to reflect the desired data.

This should not have any impact on actual users and does not change the output files of actual users. This bug only occurs when using the esbuild plugin multiple times but with a different site.src.

Related Issues

None

Check List

  • Have you read the
    CODE OF CONDUCT
  • Have you read the document
    CONTRIBUTING
    • One pull request per feature. If you want to do more than one thing,
      send multiple pull request.
    • Write tests.
    • Run deno fmt to fix the code format before commit.
    • Document any change in the CHANGELOG.md.

@oscarotero
Copy link
Member

Good catch!
I was expecting the merge() function to return a completely new object, but the property options.options is a reference to the defaults property, so hence the bug.

Changing merge() function to ensure the object is completely cloned (without references) is not easy (and not always possible for some potential values, like functions), so your fix is fine.
Thanks!!

@oscarotero oscarotero merged commit 04b749e into lumeland:main Oct 19, 2024
6 checks passed
@into-the-v0id into-the-v0id deleted the bugfix/esbuild-tests branch October 19, 2024 19:18
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