Skip to content
Permalink
Browse files

fix(core): resolve publisher config correctly when given a publisher …

…name (#568)

Fixes #541
  • Loading branch information
MarshallOfSound committed Sep 10, 2018
1 parent ee61540 commit f37476bfe8906be77144f4f5dbeb5435b7908003
Showing with 35 additions and 4 deletions.
  1. +7 −1 packages/api/core/src/api/publish.ts
  2. +28 −3 packages/api/core/test/fast/publish_spec.ts
@@ -140,7 +140,13 @@ const publish = async ({
// .filter(publisher => (typeof publisher !== 'string' && publisher.platforms) ? publisher.platforms.indexOf(testPlatform) !== -1 : true);
}
publishTargets = publishTargets.map((target) => {
if (typeof target === 'string') return { name: target };
if (typeof target === 'string') {
return (forgeConfig.publishers || []).find((p) => {
if (typeof p === 'string') return false;
if ((p as IForgePublisher).__isElectronForgePublisher) return false;
return (p as IForgeResolvablePublisher).name === target;
}) || { name: target };
}
return target;
}) as (IForgeResolvablePublisher | IForgePublisher)[];

@@ -14,7 +14,8 @@ describe('publish', () => {
let publisherSpy: SinonStub;
let voidStub: SinonStub;
let nowhereStub: SinonStub;
let publishers: string[];
let publishers: any[];
let fooPublisher: { name: string, providedConfig: any };

beforeEach(() => {
resolveStub = sinon.stub();
@@ -23,9 +24,11 @@ describe('publish', () => {
voidStub = sinon.stub();
nowhereStub = sinon.stub();
publishers = ['@electron-forge/publisher-test'];
const fakePublisher = (stub: SinonStub) => class {
const fakePublisher = (stub: SinonStub, name: string = 'default') => class X {
private publish: SinonStub;
constructor() {
public name = name;
constructor(public providedConfig: any) {
fooPublisher = this;
this.publish = stub;
}
};
@@ -52,6 +55,9 @@ describe('publish', () => {
if (name === '@electron-forge/publisher-test') {
return fakePublisher(publisherSpy);
}
if (name === '@electron-forge/publisher-foo') {
return fakePublisher(publisherSpy, name);
}
return null;
},
}).default;
@@ -69,6 +75,25 @@ describe('publish', () => {
expect(makeStub.callCount).to.equal(1);
});

it('should resolve publishers from the forge config if provided', async () => {
publishers = [{
name: 'bad',
config: 'foo',
}, {
name: '@electron-forge/publisher-foo',
config: 'resolved',
}];
await publish({
dir: __dirname,
interactive: false,
publishTargets: ['@electron-forge/publisher-foo'],
});
expect(publisherSpy.callCount).to.equal(1);

expect(fooPublisher.name).to.equal('@electron-forge/publisher-foo');
expect(fooPublisher.providedConfig).to.equal('resolved');
});

it('should call the resolved publisher with the appropriate args', async () => {
makeStub.returns([{ artifacts: ['artifact1', 'artifact2'] }]);
await publish({

0 comments on commit f37476b

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