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