Skip to content

Fix manifest cache for local JavaScript feature tests#10365

Merged
aduth merged 1 commit intomainfrom
aduth-fix-local-js-build-feature
Apr 4, 2024
Merged

Fix manifest cache for local JavaScript feature tests#10365
aduth merged 1 commit intomainfrom
aduth-fix-local-js-build-feature

Conversation

@aduth
Copy link
Copy Markdown
Contributor

@aduth aduth commented Apr 4, 2024

🛠 Summary of changes

Ensures that the JavaScript build which runs when executing a test using the JavaScript driver in tests will invalidate the cached assets manifest.

This resolves an issue where running JavaScript feature specs locally could result in Content-Security-Policy errors in trying to load scripts from http://localhost:3035/ (the Webpack dev server).

This may have been made more prevalent by recent changes in #10301 to eagerly cache the manifest, though likely existed prior.

As outlined in the included inline code comment, the problem is that the application will cache whatever manifest exists at startup, but the JavaScript build happens on-demand. Therefore, the application may try to load incorrect URLs if the on-demand build would produce a different manifest.

📜 Testing Plan

  1. Run make run. This will generate public/packs/manifest.json with http://localhost:3035/ URLs for the Webpack dev server
  2. Run rspec ./spec/features/accessibility/idv_pages_spec.rb:20

Before: You would see CSP errors, because the application starts up and caches the manifest produced by Step 1 .

Example:

       Unexpected browser console logging:
     
       http://127.0.0.1:60993/account - Refused to load the script 'http://localhost:3035/packs/js/navigation.js' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-eval' 'nonce-e586d9c7c882eb04f2ac42658d7c9d43'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

[...]

After: The test will pass, because the cached manifest will be reloaded using the manifest generated by the on-demand JavaScript build.

changelog: Internal, Automated Testing, Fix manifest cache for local JavaScript feature tests
# rubocop:enable Style/GlobalVars
# rubocop:disable Rails/Output
print ' Bundling JavaScript and stylesheets... '
system 'WEBPACK_PORT= yarn concurrently "yarn:build:*" > /dev/null 2>&1'
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removing the environment variable isn't related to the fix, but was part of my troubleshooting. I don't think it's doing anything since the value is "empty" regardless whether it's provided or not.

@aduth aduth merged commit 25e2326 into main Apr 4, 2024
@aduth aduth deleted the aduth-fix-local-js-build-feature branch April 4, 2024 18:30
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