1 | import path from 'path';
|
2 |
|
3 | import { MakerBase, MakerOptions } from '@electron-forge/maker-base';
|
4 | import { ForgeArch } from '@electron-forge/shared-types';
|
5 | import { expect } from 'chai';
|
6 | import proxyquire from 'proxyquire';
|
7 | import { SinonStub, stub } from 'sinon';
|
8 |
|
9 | import { MakerDebConfig } from '../src/Config';
|
10 | import { debianArch } from '../src/MakerDeb';
|
11 |
|
12 | type MakeFunction = (opts: Partial<MakerOptions>) => Promise<string[]>;
|
13 |
|
14 | class MakerImpl extends MakerBase<MakerDebConfig> {
|
15 | name = 'test';
|
16 |
|
17 | defaultPlatforms = [];
|
18 | }
|
19 |
|
20 | describe('MakerDeb', () => {
|
21 | let MakerDeb: typeof MakerImpl;
|
22 | let eidStub: SinonStub;
|
23 | let ensureDirectoryStub: SinonStub;
|
24 | let config: MakerDebConfig;
|
25 | let maker: MakerImpl;
|
26 | let createMaker: () => void;
|
27 |
|
28 | const dir = '/my/test/dir/out';
|
29 | const makeDir = path.resolve('/foo/bar/make');
|
30 | const appName = 'My Test App';
|
31 | const targetArch = process.arch;
|
32 | const packageJSON = { version: '1.2.3' };
|
33 |
|
34 | beforeEach(() => {
|
35 | ensureDirectoryStub = stub().returns(Promise.resolve());
|
36 | eidStub = stub().returns({ packagePaths: ['/foo/bar.deb'] });
|
37 | config = {};
|
38 |
|
39 | MakerDeb = proxyquire.noPreserveCache().noCallThru().load('../src/MakerDeb', {
|
40 | 'electron-installer-debian': eidStub,
|
41 | }).default;
|
42 | createMaker = () => {
|
43 | maker = new MakerDeb(config, []);
|
44 | maker.ensureDirectory = ensureDirectoryStub;
|
45 | maker.prepareConfig(targetArch as ForgeArch);
|
46 | };
|
47 | createMaker();
|
48 | });
|
49 |
|
50 | it('should pass through correct defaults', async () => {
|
51 | await (maker.make as MakeFunction)({
|
52 | dir,
|
53 | makeDir,
|
54 | appName,
|
55 | targetArch,
|
56 | packageJSON,
|
57 | });
|
58 | const opts = eidStub.firstCall.args[0];
|
59 | expect(opts).to.deep.equal({
|
60 | arch: debianArch(process.arch as ForgeArch),
|
61 | options: {},
|
62 | src: dir,
|
63 | dest: path.join(makeDir, 'deb', process.arch),
|
64 | rename: undefined,
|
65 | });
|
66 | expect(maker.config).to.deep.equal(config);
|
67 | });
|
68 |
|
69 | it('should have config cascade correctly', async () => {
|
70 | config = {
|
71 | arch: 'overridden',
|
72 | options: {
|
73 | productName: 'Debian',
|
74 | },
|
75 | } as Record<string, unknown>;
|
76 |
|
77 | createMaker();
|
78 |
|
79 | await (maker.make as MakeFunction)({
|
80 | dir,
|
81 | makeDir,
|
82 | appName,
|
83 | targetArch,
|
84 | packageJSON,
|
85 | });
|
86 | const opts = eidStub.firstCall.args[0];
|
87 | expect(opts).to.deep.equal({
|
88 | arch: debianArch(process.arch as ForgeArch),
|
89 | options: {
|
90 | productName: 'Debian',
|
91 | },
|
92 | src: dir,
|
93 | dest: path.join(makeDir, 'deb', process.arch),
|
94 | rename: undefined,
|
95 | });
|
96 | });
|
97 |
|
98 | describe('debianArch', () => {
|
99 | it('should convert ia32 to i386', () => {
|
100 | expect(debianArch('ia32')).to.equal('i386');
|
101 | });
|
102 |
|
103 | it('should convert x64 to amd64', () => {
|
104 | expect(debianArch('x64')).to.equal('amd64');
|
105 | });
|
106 |
|
107 | it('should convert arm to armel', () => {
|
108 | expect(debianArch('arm')).to.equal('armel');
|
109 | });
|
110 |
|
111 | it('should convert armv7l to armhf', () => {
|
112 | expect(debianArch('armv7l')).to.equal('armhf');
|
113 | });
|
114 |
|
115 | it('should leave unknown values alone', () => {
|
116 | expect(debianArch('foo' as ForgeArch)).to.equal('foo');
|
117 | });
|
118 | });
|
119 | });
|