|
| 1 | +import path from 'path'; |
| 2 | +import fs from 'fs'; |
| 3 | +import {getTempDirectory} from '../../../../../../jest/helpers'; |
| 4 | +import {BuildSettings} from '../getBuildSettings'; |
| 5 | +import {getBuildPath} from '../getBuildPath'; |
| 6 | + |
| 7 | +const targetBuildDirName = 'foo'; |
| 8 | +const targetBuildDirNameWithMaccatalyst = `${targetBuildDirName}-maccatalyst`; |
| 9 | +const executableFolderPath = path.join('foo.app', 'Contents', 'MacOS', 'foo'); |
| 10 | + |
| 11 | +test('correctly determines macCatalyst build artifact path new style', async () => { |
| 12 | + // setup: |
| 13 | + const tmpBuildPath = getTempDirectory('maccatalyst-test-dir'); |
| 14 | + fs.mkdirSync(path.join(tmpBuildPath, targetBuildDirNameWithMaccatalyst), { |
| 15 | + recursive: true, |
| 16 | + }); |
| 17 | + |
| 18 | + // - create buildSettings object that represents this to CLI |
| 19 | + const buildSettings: BuildSettings = { |
| 20 | + TARGET_BUILD_DIR: path.join( |
| 21 | + tmpBuildPath, |
| 22 | + targetBuildDirNameWithMaccatalyst, |
| 23 | + ), |
| 24 | + EXECUTABLE_FOLDER_PATH: executableFolderPath, |
| 25 | + FULL_PRODUCT_NAME: 'unused-in-this-test', |
| 26 | + INFOPLIST_PATH: 'unused-in-this-test', |
| 27 | + }; |
| 28 | + |
| 29 | + // test: |
| 30 | + // - send our buildSettings in and see what build path comes out |
| 31 | + const buildPath = await getBuildPath(buildSettings, 'ios', true); |
| 32 | + |
| 33 | + // assert: |
| 34 | + expect(buildPath).toBe( |
| 35 | + path.join( |
| 36 | + tmpBuildPath, |
| 37 | + targetBuildDirNameWithMaccatalyst, |
| 38 | + executableFolderPath, |
| 39 | + ), |
| 40 | + ); |
| 41 | +}); |
| 42 | + |
| 43 | +test('correctly determines macCatalyst build artifact path old style', async () => { |
| 44 | + // setup: |
| 45 | + const tmpBuildPath = getTempDirectory('maccatalyst-test-dir'); |
| 46 | + fs.mkdirSync(path.join(tmpBuildPath, targetBuildDirNameWithMaccatalyst), { |
| 47 | + recursive: true, |
| 48 | + }); |
| 49 | + |
| 50 | + // - create buildSettings object that represents this to CLI |
| 51 | + // FIXME get the build settings as side effect from project definition, |
| 52 | + // because it's the translation of project settings to path that fails |
| 53 | + const buildSettings: BuildSettings = { |
| 54 | + TARGET_BUILD_DIR: path.join(tmpBuildPath, targetBuildDirName), |
| 55 | + EXECUTABLE_FOLDER_PATH: executableFolderPath, |
| 56 | + FULL_PRODUCT_NAME: 'unused-in-this-test', |
| 57 | + INFOPLIST_PATH: 'unused-in-this-test', |
| 58 | + }; |
| 59 | + |
| 60 | + // test: |
| 61 | + // - send our buildSettings in and see what build path comes out |
| 62 | + const buildPath = await getBuildPath(buildSettings, 'ios', true); |
| 63 | + |
| 64 | + // assert: |
| 65 | + expect(buildPath).toBe( |
| 66 | + path.join( |
| 67 | + tmpBuildPath, |
| 68 | + targetBuildDirNameWithMaccatalyst, |
| 69 | + executableFolderPath, |
| 70 | + ), |
| 71 | + ); |
| 72 | +}); |
| 73 | + |
| 74 | +test('correctly determines iOS build artifact path', async () => { |
| 75 | + // setup: |
| 76 | + const tmpBuildPath = getTempDirectory('ios-test-dir'); |
| 77 | + fs.mkdirSync(path.join(tmpBuildPath, targetBuildDirName), { |
| 78 | + recursive: true, |
| 79 | + }); |
| 80 | + |
| 81 | + // - create buildSettings object that represents this to CLI |
| 82 | + const buildSettings: BuildSettings = { |
| 83 | + TARGET_BUILD_DIR: path.join(tmpBuildPath, targetBuildDirName), |
| 84 | + EXECUTABLE_FOLDER_PATH: executableFolderPath, |
| 85 | + FULL_PRODUCT_NAME: 'unused-in-this-test', |
| 86 | + INFOPLIST_PATH: 'unused-in-this-test', |
| 87 | + }; |
| 88 | + |
| 89 | + // test: |
| 90 | + // - send our buildSettings in and see what build path comes out |
| 91 | + const buildPath = await getBuildPath(buildSettings); |
| 92 | + |
| 93 | + // assert: |
| 94 | + expect(buildPath).toBe( |
| 95 | + path.join(tmpBuildPath, targetBuildDirName, executableFolderPath), |
| 96 | + ); |
| 97 | +}); |
0 commit comments