105863844SEvan Bacon/* eslint-env jest */ 205863844SEvan Baconimport execa from 'execa'; 305863844SEvan Baconimport fs from 'fs-extra'; 405863844SEvan Baconimport klawSync from 'klaw-sync'; 505863844SEvan Baconimport path from 'path'; 605863844SEvan Bacon 705863844SEvan Baconimport { runExportSideEffects } from './export-side-effects'; 805863844SEvan Baconimport { bin, getRouterE2ERoot } from '../utils'; 905863844SEvan Bacon 1005863844SEvan BaconrunExportSideEffects(); 1105863844SEvan Bacon 1205863844SEvan Bacondescribe('exports static without sourcemaps', () => { 1305863844SEvan Bacon const projectRoot = getRouterE2ERoot(); 1405863844SEvan Bacon const outputName = 'dist-static-rendering-no-map'; 1505863844SEvan Bacon const outputDir = path.join(projectRoot, outputName); 1605863844SEvan Bacon 1705863844SEvan Bacon beforeAll( 1805863844SEvan Bacon async () => { 1905863844SEvan Bacon await execa('node', [bin, 'export', '-p', 'web', '--output-dir', outputName], { 2005863844SEvan Bacon cwd: projectRoot, 2105863844SEvan Bacon env: { 2205863844SEvan Bacon NODE_ENV: 'production', 23*46f023faSEvan Bacon EXPO_USE_STATIC: 'static', 2405863844SEvan Bacon E2E_ROUTER_SRC: 'url-polyfill', 2505863844SEvan Bacon E2E_ROUTER_ASYNC: 'development', 2605863844SEvan Bacon }, 2705863844SEvan Bacon }); 2805863844SEvan Bacon }, 2905863844SEvan Bacon // Could take 45s depending on how fast the bundler resolves 3005863844SEvan Bacon 560 * 1000 3105863844SEvan Bacon ); 3205863844SEvan Bacon 3305863844SEvan Bacon it('has no reference to source maps', async () => { 3405863844SEvan Bacon // List output files with sizes for snapshotting. 3505863844SEvan Bacon // This is to make sure that any changes to the output are intentional. 3605863844SEvan Bacon // Posix path formatting is used to make paths the same across OSes. 3705863844SEvan Bacon const files = klawSync(outputDir) 3805863844SEvan Bacon .map((entry) => { 3905863844SEvan Bacon if (entry.path.includes('node_modules') || !entry.stats.isFile()) { 4005863844SEvan Bacon return null; 4105863844SEvan Bacon } 4205863844SEvan Bacon return path.posix.relative(outputDir, entry.path); 4305863844SEvan Bacon }) 4405863844SEvan Bacon .filter(Boolean); 4505863844SEvan Bacon 4605863844SEvan Bacon // No map files should exist 4705863844SEvan Bacon expect(files.some((file) => file?.endsWith('.map'))).toBe(false); 4805863844SEvan Bacon 4905863844SEvan Bacon const jsFiles = files.filter((file) => file?.endsWith('.js')); 5005863844SEvan Bacon 5105863844SEvan Bacon for (const file of jsFiles) { 5205863844SEvan Bacon // Ensure the bundle does not contain a source map reference 5305863844SEvan Bacon const jsBundle = fs.readFileSync(path.join(outputDir, file!), 'utf8'); 5405863844SEvan Bacon expect(jsBundle).not.toMatch('//# sourceMappingURL'); 5505863844SEvan Bacon expect(jsBundle).not.toMatch('//# sourceURL'); 5605863844SEvan Bacon } 5705863844SEvan Bacon }); 5805863844SEvan Bacon}); 59