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}); 17 18afterAll(() => { 19 process.env.FORCE_COLOR = originalForceColor; 20 process.env.CI = originalCI; 21}); 22 23it('loads expected modules by default', async () => { 24 const modules = await getLoadedModulesAsync(`require('../../build/src/customize').expoCustomize`); 25 expect(modules).toStrictEqual([ 26 '../node_modules/ansi-styles/index.js', 27 '../node_modules/arg/index.js', 28 '../node_modules/chalk/source/index.js', 29 '../node_modules/chalk/source/util.js', 30 '../node_modules/has-flag/index.js', 31 '../node_modules/supports-color/index.js', 32 '@expo/cli/build/src/customize/index.js', 33 '@expo/cli/build/src/log.js', 34 '@expo/cli/build/src/utils/args.js', 35 ]); 36}); 37 38it('runs `npx expo customize --help`', async () => { 39 const results = await execute('customize', '--help'); 40 expect(results.stdout).toMatchInlineSnapshot(` 41 " 42 Info 43 Generate static project files 44 45 Usage 46 $ npx expo customize [files...] -- [options] 47 48 Options 49 [files...] List of files to generate 50 [options] Options to pass to the install command 51 -h, --help Usage info 52 " 53 `); 54}); 55 56it( 57 'runs `npx expo customize`', 58 async () => { 59 const projectRoot = await setupTestProjectAsync('basic-customize', 'with-blank'); 60 // `npx expo customize index.html serve.json babel.config.js` 61 await execa('node', [bin, 'customize', 'web/index.html', 'web/serve.json', 'babel.config.js'], { 62 cwd: projectRoot, 63 }); 64 65 const files = klawSync(projectRoot) 66 .map((entry) => { 67 if (entry.path.includes('node_modules') || !entry.stats.isFile()) { 68 return null; 69 } 70 return path.posix.relative(projectRoot, entry.path); 71 }) 72 .filter(Boolean); 73 74 expect(files).toEqual([ 75 'App.js', 76 'app.json', 77 'babel.config.js', 78 'package.json', 79 'web/index.html', 80 'web/serve.json', 81 'yarn.lock', 82 ]); 83 }, 84 // Could take 45s depending on how fast npm installs 85 120 * 1000 86); 87