Skip to content

Commit 61eb5ac

Browse files
committed
cleanup merge conflict overwrites
1 parent 70dd4ab commit 61eb5ac

3 files changed

Lines changed: 127 additions & 113 deletions

File tree

jest.setup.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as fs from 'fs-extra';
22
import * as path from 'path';
3-
import { appsPath, asarsDir, templateApp } from './test/util';
3+
import { appsDir, asarsDir, templateApp } from './test/util';
44

55
export default async () => {
6-
await fs.remove(appsPath);
7-
await fs.mkdirp(appsPath);
6+
await fs.remove(appsDir);
7+
await fs.mkdirp(appsDir);
88
await templateApp('Arm64Asar.app', 'arm64', async (appPath) => {
99
await fs.copy(
1010
path.resolve(asarsDir, 'app.asar'),

test/index.spec.ts

Lines changed: 117 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@ import * as fs from 'fs-extra';
22
import * as path from 'path';
33

44
import { makeUniversalApp } from '../dist/cjs/index';
5-
import {
6-
appsPath,
7-
appsOutPath,
8-
createTestApp,
9-
templateApp,
10-
VERIFY_APP_TIMEOUT,
11-
verifyApp,
12-
} from './util';
5+
import { createTestApp, templateApp, VERIFY_APP_TIMEOUT, verifyApp } from './util';
136
import { createPackage, createPackageWithOptions } from '@electron/asar';
147

8+
const appsPath = path.resolve(__dirname, 'fixtures', 'apps');
9+
const appsOutPath = path.resolve(__dirname, 'fixtures', 'apps', 'out');
10+
1511
// See `jest.setup.ts` for app fixture setup process
1612
describe('makeUniversalApp', () => {
1713
afterEach(async () => {
@@ -160,110 +156,128 @@ describe('makeUniversalApp', () => {
160156
},
161157
VERIFY_APP_TIMEOUT,
162158
);
163-
it('should generate AsarIntegrity for all asars in the application', async () => {
164-
const { testPath } = await createTestApp('app-2');
165-
const testAsarPath = path.resolve(appsOutPath, 'app-2.asar');
166-
await createPackage(testPath, testAsarPath);
167159

168-
const arm64AppPath = await templateApp('Arm64-2.app', 'arm64', async (appPath) => {
169-
await fs.copyFile(testAsarPath, path.resolve(appPath, 'Contents', 'Resources', 'app.asar'));
170-
await fs.copyFile(
171-
testAsarPath,
172-
path.resolve(appPath, 'Contents', 'Resources', 'webapp.asar'),
173-
);
174-
});
175-
const x64AppPath = await templateApp('X64-2.app', 'x64', async (appPath) => {
176-
await fs.copyFile(testAsarPath, path.resolve(appPath, 'Contents', 'Resources', 'app.asar'));
177-
await fs.copyFile(
178-
testAsarPath,
179-
path.resolve(appPath, 'Contents', 'Resources', 'webbapp.asar'),
180-
);
181-
});
182-
const outAppPath = path.resolve(appsOutPath, 'MultipleAsars.app');
160+
// TODO: Investigate if this should even be allowed.
161+
// Current logic detects all unpacked files as APP_CODE, which doesn't seem correct since it could also be a macho file requiring lipo
162+
// https://github.com/electron/universal/blob/d90d573ccf69a5b14b91aa818c8b97e0e6840399/src/file-utils.ts#L48-L49
163+
it.skip(
164+
'should shim asars with different unpacked dirs',
165+
async () => {
166+
const arm64AppPath = await templateApp('UnpackedArm64.app', 'arm64', async (appPath) => {
167+
const { testPath } = await createTestApp('UnpackedAppArm64');
168+
await createPackageWithOptions(
169+
testPath,
170+
path.resolve(appPath, 'Contents', 'Resources', 'app.asar'),
171+
{
172+
unpackDir: 'var',
173+
unpack: '*.txt',
174+
},
175+
);
176+
});
183177

184-
it(
185-
'should shim asars with different unpacked dirs',
186-
async () => {
187-
const arm64AppPath = await templateApp('UnpackedArm64.app', 'arm64', async (appPath) => {
188-
const { testPath } = await createTestApp('UnpackedAppArm64');
189-
await createPackageWithOptions(
190-
testPath,
191-
path.resolve(appPath, 'Contents', 'Resources', 'app.asar'),
192-
{
193-
unpackDir: 'var',
194-
unpack: '*.txt',
195-
},
196-
);
197-
});
178+
const x64AppPath = await templateApp('UnpackedX64.app', 'x64', async (appPath) => {
179+
const { testPath } = await createTestApp('UnpackedAppX64');
180+
await createPackageWithOptions(
181+
testPath,
182+
path.resolve(appPath, 'Contents', 'Resources', 'app.asar'),
183+
{},
184+
);
185+
});
198186

199-
const x64AppPath = await templateApp('UnpackedX64.app', 'x64', async (appPath) => {
200-
const { testPath } = await createTestApp('UnpackedAppX64');
201-
await createPackageWithOptions(
202-
testPath,
203-
path.resolve(appPath, 'Contents', 'Resources', 'app.asar'),
204-
{},
205-
);
206-
});
187+
const outAppPath = path.resolve(appsOutPath, 'UnpackedDir.app');
188+
await makeUniversalApp({
189+
x64AppPath,
190+
arm64AppPath,
191+
outAppPath,
192+
});
193+
await verifyApp(outAppPath);
194+
},
195+
VERIFY_APP_TIMEOUT,
196+
);
207197

208-
const outAppPath = path.resolve(appsOutPath, 'UnpackedDir.app');
209-
await makeUniversalApp({
210-
x64AppPath,
211-
arm64AppPath,
212-
outAppPath,
213-
mergeASARs: true,
214-
});
215-
await verifyApp(outAppPath);
216-
},
217-
VERIFY_APP_TIMEOUT,
218-
);
219-
});
198+
it(
199+
'should generate AsarIntegrity for all asars in the application',
200+
async () => {
201+
const { testPath } = await createTestApp('app-2');
202+
const testAsarPath = path.resolve(appsOutPath, 'app-2.asar');
203+
await createPackage(testPath, testAsarPath);
220204

221-
describe('no asar mode', () => {
222-
it(
223-
'should correctly merge two identical app folders',
224-
async () => {
225-
const out = path.resolve(appsOutPath, 'MergedNoAsar.app');
226-
await makeUniversalApp({
227-
x64AppPath: path.resolve(appsPath, 'X64NoAsar.app'),
228-
arm64AppPath: path.resolve(appsPath, 'Arm64NoAsar.app'),
229-
outAppPath: out,
230-
});
231-
await verifyApp(out);
232-
},
233-
VERIFY_APP_TIMEOUT,
234-
);
205+
const arm64AppPath = await templateApp('Arm64-2.app', 'arm64', async (appPath) => {
206+
await fs.copyFile(
207+
testAsarPath,
208+
path.resolve(appPath, 'Contents', 'Resources', 'app.asar'),
209+
);
210+
await fs.copyFile(
211+
testAsarPath,
212+
path.resolve(appPath, 'Contents', 'Resources', 'webapp.asar'),
213+
);
214+
});
215+
const x64AppPath = await templateApp('X64-2.app', 'x64', async (appPath) => {
216+
await fs.copyFile(
217+
testAsarPath,
218+
path.resolve(appPath, 'Contents', 'Resources', 'app.asar'),
219+
);
220+
await fs.copyFile(
221+
testAsarPath,
222+
path.resolve(appPath, 'Contents', 'Resources', 'webbapp.asar'),
223+
);
224+
});
225+
const outAppPath = path.resolve(appsOutPath, 'MultipleAsars.app');
226+
await makeUniversalApp({
227+
x64AppPath,
228+
arm64AppPath,
229+
outAppPath,
230+
mergeASARs: true,
231+
});
232+
await verifyApp(outAppPath);
233+
},
234+
VERIFY_APP_TIMEOUT,
235+
);
236+
});
235237

236-
it(
237-
'should shim two different app folders',
238-
async () => {
239-
const arm64AppPath = await templateApp('ShimArm64.app', 'arm64', async (appPath) => {
240-
const { testPath } = await createTestApp('shimArm64', {
241-
'i-aint-got-no-rhythm.bin': 'boomshakalaka',
242-
});
243-
await fs.copy(testPath, path.resolve(appPath, 'Contents', 'Resources', 'app'));
244-
});
238+
describe('no asar mode', () => {
239+
it(
240+
'should correctly merge two identical app folders',
241+
async () => {
242+
const out = path.resolve(appsOutPath, 'MergedNoAsar.app');
243+
await makeUniversalApp({
244+
x64AppPath: path.resolve(appsPath, 'X64NoAsar.app'),
245+
arm64AppPath: path.resolve(appsPath, 'Arm64NoAsar.app'),
246+
outAppPath: out,
247+
});
248+
await verifyApp(out);
249+
},
250+
VERIFY_APP_TIMEOUT,
251+
);
245252

246-
const x64AppPath = await templateApp('ShimX64.app', 'x64', async (appPath) => {
247-
const { testPath } = await createTestApp('shimX64', {
248-
'hello-world.bin': 'Hello World',
249-
});
250-
await fs.copy(testPath, path.resolve(appPath, 'Contents', 'Resources', 'app'));
253+
it(
254+
'should shim two different app folders',
255+
async () => {
256+
const arm64AppPath = await templateApp('ShimArm64.app', 'arm64', async (appPath) => {
257+
const { testPath } = await createTestApp('shimArm64', {
258+
'i-aint-got-no-rhythm.bin': 'boomshakalaka',
251259
});
260+
await fs.copy(testPath, path.resolve(appPath, 'Contents', 'Resources', 'app'));
261+
});
252262

253-
const outAppPath = path.resolve(appsOutPath, 'ShimNoAsar.app');
254-
await makeUniversalApp({
255-
x64AppPath,
256-
arm64AppPath,
257-
outAppPath,
258-
});
259-
await verifyApp(outAppPath);
260-
},
261-
VERIFY_APP_TIMEOUT,
262-
);
263-
});
263+
const x64AppPath = await templateApp('ShimX64.app', 'x64', async (appPath) => {
264+
const { testPath } = await createTestApp('shimX64', { 'hello-world.bin': 'Hello World' });
265+
await fs.copy(testPath, path.resolve(appPath, 'Contents', 'Resources', 'app'));
266+
});
264267

265-
// TODO: Add tests for
266-
// * different app dirs with different macho files
267-
// * identical app dirs with universal macho files
268+
const outAppPath = path.resolve(appsOutPath, 'ShimNoAsar.app');
269+
await makeUniversalApp({
270+
x64AppPath,
271+
arm64AppPath,
272+
outAppPath,
273+
});
274+
await verifyApp(outAppPath);
275+
},
276+
VERIFY_APP_TIMEOUT,
277+
);
268278
});
279+
280+
// TODO: Add tests for
281+
// * different app dirs with different macho files
282+
// * identical app dirs with universal macho files
269283
});

test/util.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import { getRawHeader } from '@electron/asar';
21
import { downloadArtifact } from '@electron/get';
32
import { spawn } from '@malept/cross-spawn-promise';
43
import * as zip from 'cross-zip';
54
import * as fs from 'fs-extra';
65
import * as path from 'path';
76
import plist from 'plist';
87
import * as fileUtils from '../dist/cjs/file-utils';
8+
import { getRawHeader } from '@electron/asar';
99

1010
// We do a LOT of verifications in `verifyApp` 😅
1111
// exec universal binary -> verify ALL asars -> verify ALL app dirs -> verify ALL asar integrity entries
1212
// plus some tests create fixtures at runtime
1313
export const VERIFY_APP_TIMEOUT = 80 * 1000;
1414

1515
export const asarsDir = path.resolve(__dirname, 'fixtures', 'asars');
16-
export const appsPath = path.resolve(__dirname, 'fixtures', 'apps');
17-
export const appsOutPath = path.resolve(appsPath, 'out');
16+
export const appsDir = path.resolve(__dirname, 'fixtures', 'apps');
17+
export const appsOutPath = path.resolve(appsDir, 'out');
1818

1919
export const verifyApp = async (appPath: string) => {
2020
await ensureUniversal(appPath);
@@ -130,7 +130,7 @@ export const createTestApp = async (
130130
additionalFiles: Record<string, string> = {},
131131
) => {
132132
const outDir = (testName || 'app') + Math.floor(Math.random() * 100); // tests run in parallel, randomize dir suffix to prevent naming collisions
133-
const testPath = path.join(appsPath, outDir);
133+
const testPath = path.join(appsDir, outDir);
134134
await fs.remove(testPath);
135135

136136
await fs.copy(path.join(asarsDir, 'app'), testPath);
@@ -171,9 +171,9 @@ export const templateApp = async (
171171
platform: 'darwin',
172172
arch,
173173
});
174-
const appPath = path.resolve(appsPath, name);
175-
zip.unzipSync(electronZip, appsPath);
176-
await fs.rename(path.resolve(appsPath, 'Electron.app'), appPath);
174+
const appPath = path.resolve(appsDir, name);
175+
zip.unzipSync(electronZip, appsDir);
176+
await fs.rename(path.resolve(appsDir, 'Electron.app'), appPath);
177177
await fs.remove(path.resolve(appPath, 'Contents', 'Resources', 'default_app.asar'));
178178
await modify(appPath);
179179

0 commit comments

Comments
 (0)