Add comprehensive webpack plugin tests and update plugin hooks#20
Open
exo-nikita wants to merge 2 commits into
Open
Add comprehensive webpack plugin tests and update plugin hooks#20exo-nikita wants to merge 2 commits into
exo-nikita wants to merge 2 commits into
Conversation
Migrate StasisWebpack to the .hooks API and fill in the previously
TODO import-recording path: each after-resolve event now calls
state.addImport(issuer, rawRequest, resource) for non-entry resolves,
and state.addFile(url, { isEntry: !issuer }) marks the entry on its
first sighting.
Mirror the esbuild test suite: tests/webpack-run.helper.js drives a
webpack build with the StasisWebpack plugin against a fixture cwd,
then writes state. New fixtures webpack-full and webpack-nm cover
lock=add/frozen/replace/ignore in full and node_modules scope,
package.json metadata mismatch, brand-new entries under lock=frozen,
hash mismatch (src and node_modules), bundle=add/replace including
tamper detection, and env-vs-config scope conflict.
There was a problem hiding this comment.
Pull request overview
Adds a comprehensive node:test suite for the Stasis webpack plugin (lock add/frozen/replace/ignore, bundle add/replace, scope variants, config conflicts, tamper detection) along with two fixture projects, and modernizes src/webpack.js to use the hooks.tap() API with node:assert/strict, recording imports via state.addImport and tagging entries via addFile(..., { isEntry }).
Changes:
- Rewrite
src/webpack.jsto usecompiler.hooks.normalModuleFactory/nmf.hooks.afterResolvetaps, trackisEntry, and callstate.addImport(parentURL, rawRequest, url). - Add
tests/webpack.test.jsandtests/webpack-run.helper.jsrunning webpack in a child process with a freshStateper test. - Add
webpack-fullandwebpack-nmfixtures (with committedstasis.config.jsonandstasis.lock.json).
Reviewed changes
Copilot reviewed 13 out of 17 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/webpack.js | Switch from legacy plugin() callbacks to hooks.tap(), record imports and entry flag |
| tests/webpack.test.js | New 300+ line test suite covering lock modes, bundle, tampering, scopes, conflicts |
| tests/webpack-run.helper.js | Child-process helper that constructs State, runs webpack with the plugin, then writes state |
| tests/fixtures/webpack-full/* | Full-scope fixture: entry, hello, package.json, committed config & lockfile, pnpm-workspace marker |
| tests/fixtures/webpack-nm/* | node_modules-scope fixture: entry/helper, fake-cjs-pkg under node_modules, committed config & lockfile |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Config now reads env vars at construction time and accepts a plain-object options bag with the same shape as the CLI flags. When both env and an option set the same key they must match, otherwise 'Plugin options can not override stasis env' is raised. State forwards options through to Config. Both StasisWebpack and StasisEsbuild now take a constructor options argument and support every CLI mode (lock=add|replace|frozen|ignore|none, bundle=add|replace|load|ignore|none, plus bundleFile/scope/debug). If State.instance already exists (preload path) the plugin asserts its config matches the options; otherwise the plugin constructs State with them. Tests: parallel option-driven coverage for both plugins via a STASIS_TEST_PLUGIN_OPTIONS env var the helpers forward to the plugin constructor. Covers every lock and bundle mode, bundleFile, env-vs-option conflict, unknown option, and invalid value.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds extensive test coverage for the Stasis webpack plugin and modernizes the plugin implementation to use webpack's current hooks API.
Key Changes
Plugin Implementation (
src/webpack.js)plugin()API to modernhooks.tap()API for webpack 5+ compatibilityassertimport to usenode:assert/strictfor stricter equality checksnormalModuleFactoryhook to useafterResolvetap instead of callback-based approachisEntryflagTest Infrastructure
tests/webpack.test.js: 304-line comprehensive test suite covering:tests/webpack-run.helper.js: Test harness that spawns webpack builds with the plugin in isolated processeswebpack-full: Tests full scope with local source file trackingwebpack-nm: Tests node_modules scope with package dependency trackingTest Coverage
The test suite validates:
Notable Implementation Details
spawnSyncto ensure each test gets a fresh State singletonhttps://claude.ai/code/session_01QqHtVH44DmBSMTa4B8ysPv