1/* eslint-env jest */ 2import execa from 'execa'; 3import fs from 'fs-extra'; 4import klawSync from 'klaw-sync'; 5import path from 'path'; 6 7import { runExportSideEffects } from './export-side-effects'; 8import { bin, getRouterE2ERoot } from '../utils'; 9 10runExportSideEffects(); 11 12describe('exports static without sourcemaps', () => { 13 const projectRoot = getRouterE2ERoot(); 14 const outputName = 'dist-static-rendering-no-map'; 15 const outputDir = path.join(projectRoot, outputName); 16 17 beforeAll( 18 async () => { 19 await execa('node', [bin, 'export', '-p', 'web', '--output-dir', outputName], { 20 cwd: projectRoot, 21 env: { 22 NODE_ENV: 'production', 23 EXPO_USE_STATIC: 'static', 24 E2E_ROUTER_SRC: 'url-polyfill', 25 E2E_ROUTER_ASYNC: 'development', 26 }, 27 }); 28 }, 29 // Could take 45s depending on how fast the bundler resolves 30 560 * 1000 31 ); 32 33 it('has no reference to source maps', async () => { 34 // List output files with sizes for snapshotting. 35 // This is to make sure that any changes to the output are intentional. 36 // Posix path formatting is used to make paths the same across OSes. 37 const files = klawSync(outputDir) 38 .map((entry) => { 39 if (entry.path.includes('node_modules') || !entry.stats.isFile()) { 40 return null; 41 } 42 return path.posix.relative(outputDir, entry.path); 43 }) 44 .filter(Boolean); 45 46 // No map files should exist 47 expect(files.some((file) => file?.endsWith('.map'))).toBe(false); 48 49 const jsFiles = files.filter((file) => file?.endsWith('.js')); 50 51 for (const file of jsFiles) { 52 // Ensure the bundle does not contain a source map reference 53 const jsBundle = fs.readFileSync(path.join(outputDir, file!), 'utf8'); 54 expect(jsBundle).not.toMatch('//# sourceMappingURL'); 55 expect(jsBundle).not.toMatch('//# sourceURL'); 56 } 57 }); 58}); 59