|
| 1 | +import { getCliOverrides } from '../getCliOverrides.js'; |
| 2 | + |
| 3 | +describe('getCliOverrides', () => { |
| 4 | + describe('bundle command', () => { |
| 5 | + it('should return overrides with entry when entryFile is provided', () => { |
| 6 | + expect( |
| 7 | + getCliOverrides({ |
| 8 | + args: { |
| 9 | + platform: 'ios', |
| 10 | + dev: false, |
| 11 | + minify: true, |
| 12 | + entryFile: 'index.js', |
| 13 | + }, |
| 14 | + command: 'bundle', |
| 15 | + }) |
| 16 | + ).toEqual({ |
| 17 | + mode: 'production', |
| 18 | + optimization: { minimize: true }, |
| 19 | + entry: './index.js', |
| 20 | + }); |
| 21 | + }); |
| 22 | + |
| 23 | + it('should normalize relative entryFile to start with ./', () => { |
| 24 | + expect( |
| 25 | + getCliOverrides({ |
| 26 | + args: { platform: 'ios', dev: true, entryFile: 'src/main.js' }, |
| 27 | + command: 'bundle', |
| 28 | + }) |
| 29 | + ).toEqual({ |
| 30 | + mode: 'development', |
| 31 | + optimization: { minimize: undefined }, |
| 32 | + entry: './src/main.js', |
| 33 | + }); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should preserve absolute entryFile as-is', () => { |
| 37 | + expect( |
| 38 | + getCliOverrides({ |
| 39 | + args: { platform: 'ios', dev: false, entryFile: '/app/src/index.js' }, |
| 40 | + command: 'bundle', |
| 41 | + }) |
| 42 | + ).toEqual({ |
| 43 | + mode: 'production', |
| 44 | + optimization: { minimize: undefined }, |
| 45 | + entry: '/app/src/index.js', |
| 46 | + }); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should preserve entryFile starting with ./ as-is', () => { |
| 50 | + expect( |
| 51 | + getCliOverrides({ |
| 52 | + args: { platform: 'ios', dev: false, entryFile: './src/index.js' }, |
| 53 | + command: 'bundle', |
| 54 | + }) |
| 55 | + ).toEqual({ |
| 56 | + mode: 'production', |
| 57 | + optimization: { minimize: undefined }, |
| 58 | + entry: './src/index.js', |
| 59 | + }); |
| 60 | + }); |
| 61 | + |
| 62 | + it('should not set entry when entryFile is omitted', () => { |
| 63 | + const result = getCliOverrides({ |
| 64 | + args: { platform: 'ios', dev: false }, |
| 65 | + command: 'bundle', |
| 66 | + }); |
| 67 | + |
| 68 | + expect(result).toEqual({ |
| 69 | + mode: 'production', |
| 70 | + optimization: { minimize: undefined }, |
| 71 | + }); |
| 72 | + expect(result).not.toHaveProperty('entry'); |
| 73 | + }); |
| 74 | + }); |
| 75 | + |
| 76 | + describe('start command', () => { |
| 77 | + it('should return devServer overrides', () => { |
| 78 | + expect( |
| 79 | + getCliOverrides({ |
| 80 | + args: { host: 'localhost', port: 8081 }, |
| 81 | + command: 'start', |
| 82 | + }) |
| 83 | + ).toEqual({ |
| 84 | + devServer: { |
| 85 | + port: 8081, |
| 86 | + host: 'localhost', |
| 87 | + server: undefined, |
| 88 | + }, |
| 89 | + }); |
| 90 | + }); |
| 91 | + |
| 92 | + it('should include https server config when https is enabled', () => { |
| 93 | + expect( |
| 94 | + getCliOverrides({ |
| 95 | + args: { |
| 96 | + host: 'localhost', |
| 97 | + port: 8081, |
| 98 | + https: true, |
| 99 | + key: '/path/to/key.pem', |
| 100 | + cert: '/path/to/cert.pem', |
| 101 | + }, |
| 102 | + command: 'start', |
| 103 | + }) |
| 104 | + ).toEqual({ |
| 105 | + devServer: { |
| 106 | + port: 8081, |
| 107 | + host: 'localhost', |
| 108 | + server: { |
| 109 | + type: 'https', |
| 110 | + options: { |
| 111 | + key: '/path/to/key.pem', |
| 112 | + cert: '/path/to/cert.pem', |
| 113 | + }, |
| 114 | + }, |
| 115 | + }, |
| 116 | + }); |
| 117 | + }); |
| 118 | + }); |
| 119 | +}); |
0 commit comments