Skip to content

Commit

Permalink
fix(core): resolve publisher config correctly when given a publisher …
Browse files Browse the repository at this point in the history
…name (#568)

Fixes #541
  • Loading branch information
MarshallOfSound committed Sep 10, 2018
1 parent ee61540 commit f37476b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
8 changes: 7 additions & 1 deletion packages/api/core/src/api/publish.ts
Expand Up @@ -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)[];

Expand Down
31 changes: 28 additions & 3 deletions packages/api/core/test/fast/publish_spec.ts
Expand Up @@ -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();
Expand All @@ -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;
}
};
Expand All @@ -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;
Expand All @@ -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({
Expand Down

0 comments on commit f37476b

Please sign in to comment.