1const expoWebpackConfig = require('@expo/webpack-config'); 2const path = require('path'); 3 4jest.mock('@expo/webpack-config', () => { 5 return jest.fn(() => { 6 return { 7 resolve: {}, 8 }; 9 }); 10}); 11 12const { createWebpackConfigAsync } = require('../webpack'); 13 14const fakeEnv = { 15 projectRoot: path.resolve(__dirname, '../workspace-template'), 16 mode: 'development', 17}; 18 19describe('expo-yarn-workspaces createWebpackConfigAsync()', () => { 20 it('sets up symlink resolution', async () => { 21 const config = await createWebpackConfigAsync( 22 { 23 projectRoot: __dirname, 24 mode: 'development', 25 }, 26 undefined 27 ); 28 29 expect(config.resolve.symlinks).toEqual(true); 30 }); 31 32 it('sets up transpilation for workspace packages', async () => { 33 await createWebpackConfigAsync(fakeEnv, undefined); 34 35 const [lastEnvArgument] = expoWebpackConfig.mock.calls[expoWebpackConfig.mock.calls.length - 1]; 36 37 expect(lastEnvArgument.babel.dangerouslyAddModulePathsToTranspile).toEqual( 38 expect.arrayContaining([ 39 expect.stringContaining('second-package'), 40 expect.stringContaining('first-package'), 41 ]) 42 ); 43 }); 44 45 it('allows custom package transpilation to be configured', async () => { 46 await createWebpackConfigAsync( 47 { 48 ...fakeEnv, 49 babel: { 50 dangerouslyAddModulePathsToTranspile: ['module-to-transpile'], 51 }, 52 }, 53 undefined 54 ); 55 56 const [lastEnvArgument] = expoWebpackConfig.mock.calls[expoWebpackConfig.mock.calls.length - 1]; 57 58 expect(lastEnvArgument.babel.dangerouslyAddModulePathsToTranspile).toEqual( 59 expect.arrayContaining([ 60 expect.stringContaining('module-to-transpile'), 61 expect.stringContaining('first-package'), 62 expect.stringContaining('second-package'), 63 ]) 64 ); 65 }); 66}); 67