/* eslint-env jest */ import execa from 'execa'; import fs from 'fs-extra'; import klawSync from 'klaw-sync'; import path from 'path'; import { runExportSideEffects } from './export-side-effects'; import { bin, getRouterE2ERoot } from '../utils'; runExportSideEffects(); describe('exports static without sourcemaps', () => { const projectRoot = getRouterE2ERoot(); const outputName = 'dist-static-rendering-no-map'; const outputDir = path.join(projectRoot, outputName); beforeAll( async () => { await execa('node', [bin, 'export', '-p', 'web', '--output-dir', outputName], { cwd: projectRoot, env: { NODE_ENV: 'production', EXPO_USE_STATIC: 'static', E2E_ROUTER_SRC: 'url-polyfill', E2E_ROUTER_ASYNC: 'development', }, }); }, // Could take 45s depending on how fast the bundler resolves 560 * 1000 ); it('has no reference to source maps', async () => { // List output files with sizes for snapshotting. // This is to make sure that any changes to the output are intentional. // Posix path formatting is used to make paths the same across OSes. const files = klawSync(outputDir) .map((entry) => { if (entry.path.includes('node_modules') || !entry.stats.isFile()) { return null; } return path.posix.relative(outputDir, entry.path); }) .filter(Boolean); // No map files should exist expect(files.some((file) => file?.endsWith('.map'))).toBe(false); const jsFiles = files.filter((file) => file?.endsWith('.js')); for (const file of jsFiles) { // Ensure the bundle does not contain a source map reference const jsBundle = fs.readFileSync(path.join(outputDir, file!), 'utf8'); expect(jsBundle).not.toMatch('//# sourceMappingURL'); expect(jsBundle).not.toMatch('//# sourceURL'); } }); });