Files
iptvnator/jest.web-esm.workspace.ts
T
4grayandClaude Fable 5.1 eb662c4855 perf(web): bundle only the app version from package.json
The environment files and the playback diagnostic panel imported the
whole package.json (`import packageJson from '@package'`) to read its
version, and esbuild cannot tree-shake a property read on a JSON default
import, so main.js carried the complete file: scripts, dependency lists
and all. Every edit to a script or dependency moved renderer.initialBytes
even though nothing users download had changed, which is what produced
the apparent 556-byte "platform difference" between a local build made
before the perf scripts were added and the CI build made after.

Import `{ version }` instead, which esbuild tree-shakes down to the one
string. Production main.js shrinks by 11,539 bytes (renderer.initialBytes
2,751,047 -> 2,739,508) and no longer changes with package.json edits.
Jest's ESM loader exposes JSON only as a default export, so the two web
Jest configs map '@package' to a stub that serves the real file's fields
as named exports.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-26 11:12:50 +02:00

52 lines
2.2 KiB
TypeScript

import { nxPreset } from '@nx/jest/preset';
import { createEsmPreset } from 'jest-preset-angular/presets/index.js';
const angularEsmPreset = createEsmPreset({
diagnostics: false,
tsconfig: '<rootDir>/apps/web/tsconfig.spec.json',
});
const coverageReporters = ['json', 'json-summary', 'lcovonly', 'text-summary'];
export default {
...nxPreset,
...angularEsmPreset,
rootDir: '.',
roots: ['<rootDir>/apps/web', '<rootDir>/libs'],
// Jest's 5s default is thin for Angular component specs: TestBed compiles
// and instantiates a real component tree per test, and CI runners are far
// slower per-core than a dev machine. A starved worker then fails a test
// that is merely slow, with no defect behind it. Raised as headroom only —
// a spec that genuinely hangs still fails, just later.
testTimeout: 15_000,
setupFilesAfterEnv: ['<rootDir>/apps/web/src/test-setup.ts'],
resolver: nxPreset.resolver,
moduleFileExtensions: Array.from(
new Set([
...(nxPreset.moduleFileExtensions ?? []),
...(angularEsmPreset.moduleFileExtensions ?? []),
])
),
testMatch: nxPreset.testMatch,
testEnvironmentOptions: {},
snapshotSerializers: angularEsmPreset.snapshotSerializers,
moduleNameMapper: {
...(angularEsmPreset.moduleNameMapper ?? {}),
'^@iptvnator/portal/xtream/feature$':
'<rootDir>/apps/web/src/test-stubs/xtream-feature.stub.ts',
tslib: 'tslib/tslib.es6.js',
'^iptv-playlist-parser$':
'<rootDir>/apps/web/src/test-stubs/iptv-playlist-parser.mjs',
'^@package$': '<rootDir>/apps/web/src/test-stubs/package.mjs',
'^shaka-player$': '<rootDir>/apps/web/src/test-stubs/shaka-player.js',
'^rxjs': '<rootDir>/node_modules/rxjs/dist/bundles/rxjs.umd.js',
'^uuid$': '<rootDir>/node_modules/uuid/wrapper.mjs',
},
transform: angularEsmPreset.transform,
transformIgnorePatterns: [],
extensionsToTreatAsEsm: angularEsmPreset.extensionsToTreatAsEsm,
modulePathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/.nx/'],
watchPathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/.nx/'],
coverageReporters,
};