Skip to content
Permalink
Browse files

test(maker): add tests for the DMG maker to ensure the renaming logic…

… is correct
  • Loading branch information
MarshallOfSound committed May 22, 2017
1 parent 14cc927 commit 8f5f9691600f0af0b37a63964a593f6cfc3cc553
Showing with 65 additions and 2 deletions.
  1. +2 −2 package.json
  2. +63 −0 test/fast/makers/dmg_spec.js
@@ -21,8 +21,8 @@
"pretest": "gulp build",
"test": "npm run lint && npm run test-all",
"test-coverage": "npm run lint && npm run test-all-coverage",
"test-all": "mocha test/**/*_spec*.js --compilers js:babel-register --timeout=300000",
"test-fast": "mocha test/**/*_spec.js --compilers js:babel-register --timeout=10000",
"test-all": "mocha test/**/*_spec*.js test/**/**/*_spec*.js --compilers js:babel-register --timeout=300000",
"test-fast": "mocha test/**/*_spec.js test/**/**/*_spec.js --compilers js:babel-register --timeout=10000",
"test-all-coverage": "cross-env NODE_ENV=test nyc npm run test-all",
"test-fast-coverage": "cross-env NODE_ENV=test nyc npm run test-fast",
"release:patch": "changelog -p && node ci/fix-changelog.js && git add CHANGELOG.md && git commit -m \"updated CHANGELOG.md\" && npm version patch && git push origin && git push origin --tags",
@@ -0,0 +1,63 @@
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('dmg maker', () => {
let dmgMaker;
let ensureFileStub;
let eidStub;
let renameStub;
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);
renameStub = stub().returns(Promise.resolve());
forgeConfig = { electronInstallerDMG: {} };

dmgMaker = proxyquire.noPreserveCache().noCallThru().load('../../../src/makers/darwin/dmg', {
'../../util/config-fn': config => config,
'../../util/ensure-output': { ensureFile: ensureFileStub },
'electron-installer-dmg': eidStub,
'fs-promise': {
rename: renameStub,
},
}).default;
});

it('should pass through correct defaults', async () => {
await dmgMaker({ dir, appName, targetArch, forgeConfig, packageJSON });
const opts = eidStub.firstCall.args[0];
expect(opts).to.deep.equal({ overwrite: true,
name: appName,
appPath: path.resolve(`${dir}/My Test App.app`),
out: path.resolve(`${dir.substr(0, dir.length - 4)}/make`),
});
});

it('should attempt to rename the DMG file if no custom name is set', async () => {
await dmgMaker({ dir, appName, targetArch, forgeConfig, packageJSON });
expect(renameStub.callCount).to.equal(1);
expect(renameStub.firstCall.args[1]).to.include('1.2.3');
});

it('should rename the DMG file to include the version if no custom name is set', async () => {
await dmgMaker({ dir, appName, targetArch, forgeConfig, packageJSON });
expect(renameStub.firstCall.args[1]).to.include('1.2.3');
});

it('should not attempt to rename the DMG file if a custom name is set', async () => {
forgeConfig.electronInstallerDMG.name = 'foobar';
await dmgMaker({ dir, appName, targetArch, forgeConfig, packageJSON });
expect(renameStub.callCount).to.equal(0);
});
});

0 comments on commit 8f5f969

Please sign in to comment.
You can’t perform that action at this time.