Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): resolve publisher config correctly when given a publisher name #568

Merged
merged 1 commit into from
Sep 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/api/core/src/api/publish.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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