1/* eslint-env jest */ 2import execa from 'execa'; 3import fs from 'fs-extra'; 4import klawSync from 'klaw-sync'; 5import path from 'path'; 6 7import { execute, projectRoot, getLoadedModulesAsync, setupTestProjectAsync, bin } from './utils'; 8 9const originalForceColor = process.env.FORCE_COLOR; 10const originalCI = process.env.CI; 11 12beforeAll(async () => { 13 await fs.mkdir(projectRoot, { recursive: true }); 14 process.env.FORCE_COLOR = '0'; 15 process.env.CI = '1'; 16 process.env._EXPO_E2E_USE_PATH_ALIASES = '1'; 17}); 18 19afterAll(() => { 20 process.env.FORCE_COLOR = originalForceColor; 21 process.env.CI = originalCI; 22 delete process.env._EXPO_E2E_USE_PATH_ALIASES; 23}); 24 25it('loads expected modules by default', async () => { 26 const modules = await getLoadedModulesAsync( 27 `require('../../build/src/export/embed').expoExportEmbed` 28 ); 29 expect(modules).toStrictEqual([ 30 '../node_modules/ansi-styles/index.js', 31 '../node_modules/arg/index.js', 32 '../node_modules/chalk/source/index.js', 33 '../node_modules/chalk/source/util.js', 34 '../node_modules/has-flag/index.js', 35 '../node_modules/supports-color/index.js', 36 '@expo/cli/build/src/export/embed/index.js', 37 '@expo/cli/build/src/log.js', 38 '@expo/cli/build/src/utils/args.js', 39 ]); 40}); 41 42it('runs `npx expo export:embed --help`', async () => { 43 const results = await execute('export:embed', '--help'); 44 expect(results.stdout).toMatchInlineSnapshot(` 45 " 46 Info 47 (Internal) Export the JavaScript bundle during a native build script for embedding in a native binary 48 49 Usage 50 $ npx expo export:embed <dir> 51 52 Options 53 <dir> Directory of the Expo project. Default: Current working directory 54 --entry-file <path> Path to the root JS file, either absolute or relative to JS root 55 --platform <string> Either "ios" or "android" (default: "ios") 56 --transformer <string> Specify a custom transformer to be used 57 --dev [boolean] If false, warnings are disabled and the bundle is minified (default: true) 58 --minify [boolean] Allows overriding whether bundle is minified. This defaults to false if dev is true, and true if dev is false. Disabling minification can be useful for speeding up production builds for testing purposes. 59 --bundle-output <string> File name where to store the resulting bundle, ex. /tmp/groups.bundle 60 --bundle-encoding <string> Encoding the bundle should be written in (https://nodejs.org/api/buffer.html#buffer_buffer). (default: "utf8") 61 --max-workers <number> Specifies the maximum number of workers the worker-pool will spawn for transforming files. This defaults to the number of the cores available on your machine. 62 --sourcemap-output <string> File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map 63 --sourcemap-sources-root <string> Path to make sourcemap's sources entries relative to, ex. /root/dir 64 --sourcemap-use-absolute-path Report SourceMapURL using its full path 65 --assets-dest <string> Directory name where to store assets referenced in the bundle 66 --asset-catalog-dest <string> Directory to create an iOS Asset Catalog for images 67 --unstable-transform-profile <string> Experimental, transform JS for a specific JS engine. Currently supported: hermes, hermes-canary, default 68 --reset-cache Removes cached files 69 -v, --verbose Enables debug logging 70 --config <string> Path to the CLI configuration file 71 --generate-static-view-configs Generate static view configs for Fabric components. If there are no Fabric components in the bundle or Fabric is disabled, this is just no-op. 72 --read-global-cache Try to fetch transformed JS code from the global cache, if configured. 73 -h, --help Usage info 74 " 75 `); 76}); 77 78it( 79 'runs `npx expo export:embed`', 80 async () => { 81 const projectRoot = await setupTestProjectAsync('ios-export-embed', 'with-assets'); 82 fs.ensureDir(path.join(projectRoot, 'dist')); 83 await execa( 84 'node', 85 [ 86 bin, 87 'export:embed', 88 '--entry-file', 89 './App.js', 90 '--bundle-output', 91 './dist/output.js', 92 '--assets-dest', 93 'dist', 94 '--platform', 95 'ios', 96 ], 97 { 98 cwd: projectRoot, 99 } 100 ); 101 102 const outputDir = path.join(projectRoot, 'dist'); 103 // List output files with sizes for snapshotting. 104 // This is to make sure that any changes to the output are intentional. 105 // Posix path formatting is used to make paths the same across OSes. 106 const files = klawSync(outputDir) 107 .map((entry) => { 108 if (entry.path.includes('node_modules') || !entry.stats.isFile()) { 109 return null; 110 } 111 return path.posix.relative(outputDir, entry.path); 112 }) 113 .filter(Boolean); 114 115 // If this changes then everything else probably changed as well. 116 expect(files).toEqual([ 117 'assets/assets/font.ttf', 118 'assets/assets/icon.png', 119 'assets/assets/icon@2x.png', 120 'output.js', 121 ]); 122 }, 123 // Could take 45s depending on how fast npm installs 124 120 * 1000 125); 126