1/* eslint-env jest */ 2import { ExecaError } from 'execa'; 3import fs from 'fs/promises'; 4import path from 'path'; 5 6import { execute, projectRoot, getRoot, getLoadedModulesAsync } from './utils'; 7 8const originalForceColor = process.env.FORCE_COLOR; 9beforeAll(async () => { 10 await fs.mkdir(projectRoot, { recursive: true }); 11 process.env.FORCE_COLOR = '0'; 12}); 13afterAll(() => { 14 process.env.FORCE_COLOR = originalForceColor; 15}); 16 17it('loads expected modules by default', async () => { 18 const modules = await getLoadedModulesAsync(`require('../../build/src/config').expoConfig`); 19 expect(modules).toStrictEqual([ 20 '../node_modules/ansi-styles/index.js', 21 '../node_modules/arg/index.js', 22 '../node_modules/chalk/source/index.js', 23 '../node_modules/chalk/source/util.js', 24 '../node_modules/has-flag/index.js', 25 '../node_modules/supports-color/index.js', 26 '@expo/cli/build/src/config/index.js', 27 '@expo/cli/build/src/log.js', 28 '@expo/cli/build/src/utils/args.js', 29 ]); 30}); 31 32it('runs `npx expo config --help`', async () => { 33 const results = await execute('config', '--help'); 34 expect(results.stdout).toMatchInlineSnapshot(` 35 " 36 Info 37 Show the project config 38 39 Usage 40 $ npx expo config <dir> 41 42 Options 43 <dir> Directory of the Expo project. Default: Current working directory 44 --full Include all project config data 45 --json Output in JSON format 46 -t, --type <public|prebuild|introspect> Type of config to show 47 -h, --help Usage info 48 " 49 `); 50}); 51 52it( 53 'runs `npx expo config --json`', 54 async () => { 55 const projectName = 'basic-config'; 56 const projectRoot = getRoot(projectName); 57 // Create the project root aot 58 await fs.mkdir(projectRoot, { recursive: true }); 59 // Create a fake package.json -- this is a terminal file that cannot be overwritten. 60 await fs.writeFile(path.join(projectRoot, 'package.json'), '{ "version": "1.0.0" }'); 61 await fs.writeFile(path.join(projectRoot, 'app.json'), '{ "expo": { "name": "foobar" } }'); 62 63 const results = await execute('config', projectName, '--json'); 64 // @ts-ignore 65 const exp = JSON.parse(results.stdout); 66 67 expect(exp.name).toEqual('foobar'); 68 expect(exp.slug).toEqual('foobar'); 69 expect(exp.platforms).toStrictEqual([]); 70 expect(exp.version).toBe('1.0.0'); 71 expect(exp._internal.dynamicConfigPath).toBe(null); 72 expect(exp._internal.staticConfigPath).toMatch(/\/basic-config\/app\.json$/); 73 }, // Could take 45s depending on how fast npm installs 74 120 * 1000 75); 76 77it('throws on invalid project root', async () => { 78 expect.assertions(1); 79 try { 80 await execute('config', 'very---invalid', '--json'); 81 } catch (e) { 82 const error = e as ExecaError; 83 expect(error.stderr).toMatch(/Invalid project root: \//); 84 } 85}); 86