angular/integration/terser/test.js
Paul Gschwendtner a47794272b test: update basic integration tests to work with new package output (#43431)
Basic integration tests are those which do not require significant
changes as others. The larger ones will have individual commits.

For v13, the NPM package output will always be using partial compilation
output. This makes the ngcc integration test fail because the actual
Angular framework packages are no longer processable. We fix this, and
keep the ngcc test coverage by relying on the v12.x framework packages
in the integration test.

The terser integration test needs to point to the new Flat ESM module
file location. We now output FESM2020 instead of FESM2015. This also
requires us to use the latest version of terser.

The `side-effects` test currently is not maintained by us and relies
on View Engine build output. In the partial compilation output the
partial declarations are not marked with `@PURE` and are not removed
therefore. We would need to update the side-effect test to use the
linker Babel plugin instead. This is currently out-of-scope though
so we disable the test for now.

PR Close #43431
2021-10-01 18:28:43 +00:00

37 lines
1.1 KiB
JavaScript

const readFileSync = require('fs').readFileSync;
const writeFileSync = require('fs').writeFileSync;
const resolve = require('path').resolve;
const Terser = require('terser');
async function test() {
const outputPath = resolve(__dirname, './core.min.js');
const pathToCoreFesm2020 = resolve(__dirname, './node_modules/@angular/core/fesm2020/core.mjs');
const coreFesm2020Content = readFileSync(pathToCoreFesm2020, 'utf8');
const GLOBAL_DEFS_FOR_TERSER = (await import('@angular/compiler-cli')).GLOBAL_DEFS_FOR_TERSER;
// Ensure that Terser global_defs exported by compiler-cli work.
const terserOpts = {
compress: {
module: true,
global_defs: GLOBAL_DEFS_FOR_TERSER
}
};
const result = await Terser.minify(coreFesm2020Content, terserOpts);
writeFileSync(outputPath, result.code);
for (const def of Object.keys(GLOBAL_DEFS_FOR_TERSER)) {
if (result.code.includes(def)) {
throw `'${def}' should have been removed from core bundle, but was still there.\n` +
`See output at ${outputPath}.`;
}
}
console.info('Output looks good.')
}
test().catch(e => {
console.error(e);
process.exitCode = 1;
});