105863844SEvan Bacon/* eslint-env jest */
205863844SEvan Baconimport JsonFile from '@expo/json-file';
305863844SEvan Baconimport execa from 'execa';
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 with url-polyfill', () => {
1305863844SEvan Bacon  const projectRoot = getRouterE2ERoot();
1405863844SEvan Bacon  const outputName = 'dist-url-polyfill';
1505863844SEvan Bacon  const outputDir = path.join(projectRoot, outputName);
1605863844SEvan Bacon
1705863844SEvan Bacon  beforeAll(
1805863844SEvan Bacon    async () => {
1905863844SEvan Bacon      await execa('node', [bin, 'export', '-p', 'ios', '--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 expected files', 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    const metadata = await JsonFile.readAsync(path.resolve(outputDir, 'metadata.json'));
4705863844SEvan Bacon
4805863844SEvan Bacon    expect(metadata).toEqual({
4905863844SEvan Bacon      bundler: 'metro',
5005863844SEvan Bacon      fileMetadata: {
5105863844SEvan Bacon        ios: {
5205863844SEvan Bacon          assets: expect.anything(),
5305863844SEvan Bacon          bundle: expect.stringMatching(/bundles\/ios-.*\.js/),
5405863844SEvan Bacon        },
5505863844SEvan Bacon      },
5605863844SEvan Bacon      version: 0,
5705863844SEvan Bacon    });
5805863844SEvan Bacon
5905863844SEvan Bacon    // The wrapper should not be included as a route.
6005863844SEvan Bacon    expect(files).not.toContain('+html.html');
6105863844SEvan Bacon    expect(files).not.toContain('index.html');
6205863844SEvan Bacon
6305863844SEvan Bacon    const iosBundle = files.find((v) => v?.startsWith('bundles/ios'));
6405863844SEvan Bacon    expect(iosBundle).toBeDefined();
6505863844SEvan Bacon  });
6605863844SEvan Bacon});
67