Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(maker): DRY up linux config transformations
Add fast tests for linux maker config.
- Loading branch information
1 parent
076c78e
commit a39011b
Showing
9 changed files
with
245 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import merge from 'lodash.merge'; | ||
import path from 'path'; | ||
|
||
import configFn from './config-fn'; | ||
|
||
export function populateConfig({ forgeConfig, configKey, targetArch }) { | ||
const config = configFn(forgeConfig[configKey] || {}, targetArch); | ||
config.options = config.options || {}; | ||
|
||
return config; | ||
} | ||
|
||
export function linuxConfig({ config, pkgArch, dir, outPath }) { | ||
return merge({}, config, { | ||
arch: pkgArch, | ||
dest: path.dirname(outPath), | ||
src: dir, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import chai, { expect } from 'chai'; | ||
import chaiAsPromised from 'chai-as-promised'; | ||
import path from 'path'; | ||
import proxyquire from 'proxyquire'; | ||
import { stub } from 'sinon'; | ||
|
||
chai.use(chaiAsPromised); | ||
|
||
describe('deb maker', () => { | ||
let debModule; | ||
let debMaker; | ||
let eidStub; | ||
let ensureFileStub; | ||
let forgeConfig; | ||
|
||
const dir = '/my/test/dir/out'; | ||
const appName = 'My Test App'; | ||
const targetArch = process.arch; | ||
const packageJSON = { version: '1.2.3' }; | ||
|
||
beforeEach(() => { | ||
ensureFileStub = stub().returns(Promise.resolve()); | ||
eidStub = stub().callsArg(1); | ||
forgeConfig = { electronInstallerDebian: {} }; | ||
|
||
debModule = proxyquire.noPreserveCache().noCallThru().load('../../../src/makers/linux/deb', { | ||
'./config-fn': config => config, | ||
'../../util/ensure-output': { ensureFile: ensureFileStub }, | ||
'electron-installer-debian': eidStub, | ||
}); | ||
debMaker = debModule.default; | ||
}); | ||
|
||
it('should pass through correct defaults', async () => { | ||
await debMaker({ dir, appName, targetArch, forgeConfig, packageJSON }); | ||
const opts = eidStub.firstCall.args[0]; | ||
expect(opts).to.deep.equal({ | ||
arch: debModule.debianArch(process.arch), | ||
options: {}, | ||
src: dir, | ||
dest: path.resolve(dir, '..', 'make'), | ||
}); | ||
}); | ||
|
||
it('should have config cascade correctly', async () => { | ||
forgeConfig.electronInstallerDebian = { | ||
arch: 'overridden', | ||
options: { | ||
productName: 'Debian', | ||
}, | ||
}; | ||
|
||
await debMaker({ dir, appName, targetArch, forgeConfig, packageJSON }); | ||
const opts = eidStub.firstCall.args[0]; | ||
expect(opts).to.deep.equal({ | ||
arch: debModule.debianArch(process.arch), | ||
options: { | ||
productName: 'Debian', | ||
}, | ||
src: dir, | ||
dest: path.resolve(dir, '..', 'make'), | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import chai, { expect } from 'chai'; | ||
import chaiAsPromised from 'chai-as-promised'; | ||
import path from 'path'; | ||
import proxyquire from 'proxyquire'; | ||
import { stub } from 'sinon'; | ||
|
||
chai.use(chaiAsPromised); | ||
|
||
describe('flatpak maker', () => { | ||
let flatpakModule; | ||
let flatpakMaker; | ||
let eidStub; | ||
let ensureFileStub; | ||
let forgeConfig; | ||
|
||
const dir = '/my/test/dir/out'; | ||
const appName = 'My Test App'; | ||
const targetArch = process.arch; | ||
const packageJSON = { version: '1.2.3' }; | ||
|
||
beforeEach(() => { | ||
ensureFileStub = stub().returns(Promise.resolve()); | ||
eidStub = stub().callsArg(1); | ||
forgeConfig = { electronInstallerFlatpak: {} }; | ||
|
||
flatpakModule = proxyquire.noPreserveCache().noCallThru().load('../../../src/makers/linux/flatpak', { | ||
'./config-fn': config => config, | ||
'../../util/ensure-output': { ensureFile: ensureFileStub }, | ||
'electron-installer-flatpak': eidStub, | ||
}); | ||
flatpakMaker = flatpakModule.default; | ||
}); | ||
|
||
it('should pass through correct defaults', async () => { | ||
await flatpakMaker({ dir, appName, targetArch, forgeConfig, packageJSON }); | ||
const opts = eidStub.firstCall.args[0]; | ||
expect(opts).to.deep.equal({ | ||
arch: flatpakModule.flatpakArch(process.arch), | ||
options: {}, | ||
src: dir, | ||
dest: path.resolve(dir, '..', 'make'), | ||
}); | ||
}); | ||
|
||
it('should have config cascade correctly', async () => { | ||
forgeConfig.electronInstallerFlatpak = { | ||
arch: 'overridden', | ||
options: { | ||
productName: 'Flatpak', | ||
}, | ||
}; | ||
|
||
await flatpakMaker({ dir, appName, targetArch, forgeConfig, packageJSON }); | ||
const opts = eidStub.firstCall.args[0]; | ||
expect(opts).to.deep.equal({ | ||
arch: flatpakModule.flatpakArch(process.arch), | ||
options: { | ||
productName: 'Flatpak', | ||
}, | ||
src: dir, | ||
dest: path.resolve(dir, '..', 'make'), | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import chai, { expect } from 'chai'; | ||
import chaiAsPromised from 'chai-as-promised'; | ||
import path from 'path'; | ||
import proxyquire from 'proxyquire'; | ||
import { stub } from 'sinon'; | ||
|
||
chai.use(chaiAsPromised); | ||
|
||
describe('rpm maker', () => { | ||
let rpmModule; | ||
let rpmMaker; | ||
let eidStub; | ||
let ensureFileStub; | ||
let forgeConfig; | ||
|
||
const dir = '/my/test/dir/out'; | ||
const appName = 'My Test App'; | ||
const targetArch = process.arch; | ||
const packageJSON = { version: '1.2.3' }; | ||
|
||
beforeEach(() => { | ||
ensureFileStub = stub().returns(Promise.resolve()); | ||
eidStub = stub().callsArg(1); | ||
forgeConfig = { electronInstallerRedhat: {} }; | ||
|
||
rpmModule = proxyquire.noPreserveCache().noCallThru().load('../../../src/makers/linux/rpm', { | ||
'./config-fn': config => config, | ||
'../../util/ensure-output': { ensureFile: ensureFileStub }, | ||
'electron-installer-redhat': eidStub, | ||
}); | ||
rpmMaker = rpmModule.default; | ||
}); | ||
|
||
it('should pass through correct defaults', async () => { | ||
await rpmMaker({ dir, appName, targetArch, forgeConfig, packageJSON }); | ||
const opts = eidStub.firstCall.args[0]; | ||
expect(opts).to.deep.equal({ | ||
arch: rpmModule.rpmArch(process.arch), | ||
options: {}, | ||
src: dir, | ||
dest: path.resolve(dir, '..', 'make'), | ||
}); | ||
}); | ||
|
||
it('should have config cascade correctly', async () => { | ||
forgeConfig.electronInstallerRedhat = { | ||
arch: 'overridden', | ||
options: { | ||
productName: 'Redhat', | ||
}, | ||
}; | ||
|
||
await rpmMaker({ dir, appName, targetArch, forgeConfig, packageJSON }); | ||
const opts = eidStub.firstCall.args[0]; | ||
expect(opts).to.deep.equal({ | ||
arch: rpmModule.rpmArch(process.arch), | ||
options: { | ||
productName: 'Redhat', | ||
}, | ||
src: dir, | ||
dest: path.resolve(dir, '..', 'make'), | ||
}); | ||
}); | ||
}); |