How to validate backup and restore processes for core-js polyfills?
0 reputation · 05 Sept 2022, 12:14 UTC
0 reputation · 05 Sept 2022, 12:14 UTC
Validating a backup of the core-js library involves ensuring that the archived files are complete, that restoration reproduces the exact module structure, and that every polyfill behaves identically to the original version. Yet it remains unclear how to automate integrity checks across the large set of individual polyfills, what level of test coverage is necessary to catch subtle behavioural differences, and how to isolate the restored library from the project’s existing dependencies during verification.
What automated test suite can confirm that each exported polyfill function matches the specification after a restore? How can checksums or metadata be used to detect corruption or truncation in the backup archive? In what ways can a temporary sandbox or module‑alias mechanism isolate the restored core-js to verify compatibility with the application code?
To confirm that a restored core-js polyfill set behaves exactly as before, perform a two‑phase validation:
node_modules/core-js directory (or the bundled file if you use a custom build) and compare it to a stored hash. If you archived package.json and package-lock.json, also hash those files to guard against accidental version drift.package.json and the lockfile; mismatched versions change polyfill semantics.core-js-pure) is used, the build configuration and output bundle must be archived and verified.const core = require('core-js');
const fs = require('fs');
const manifest = Object.keys(core).sort();
fs.writeFileSync('corejs-manifest.json', JSON.stringify(manifest, null, 2));
npm run hash:corejs # custom script that zips node_modules/core-js and outputs SHA‑256
node_modules/core-js directory, package.json, package-lock.json, and the manifest.node_modules and running npm ci (or npm install if lockfile is absent).node_modules/core-js into it, and run the feature‑detection script there. This guarantees no interference from other dependencies.module-alias to point core-js to the restored path:
require('module-alias/register');
require('module-alias').addAlias('core-js', '/path/to/restored/node_modules/core-js');
const core = require('core-js');
process.env.CORE_JS_PATH and adjust the resolver to use that path during tests.For the most thorough check, combine a lightweight feature‑detection script (as shown above) with your existing unit test runner (Jest, Mocha, etc.). If you need stricter conformance, consider running the official core-js test harness (npm i -g core-js@next and core-js test) against the restored copy. This harness exercises each polyfill against its spec.
Do you use core-js-pure or a custom build configuration? Knowing that will determine whether you need to archive the build script and output bundle, in addition to the source.
Use comments to ask for clarification. Post a solution as an answer.
35,275 reputation · 05 Sept 2022, 20:50 UTC
core‑js relies on the exact version of the package and its transitive dependencies. If the backup omits package-lock.json (or yarn.lock), a later install may pull a newer major release that changes polyfill behavior.
# before backup
npm run hash:corejs
# after restore
npm ci
npm run hash:corejs
# compare the two hashes
Running npm ci with --frozen-lockfile guarantees that the restored node_modules exactly matches the locked state, and the hash comparison confirms byte‑for‑byte integrity.