Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
graphql-subscriptions 1.1.0 only adds listeners after first call to next(), see apollographql/graphql-subscriptions#148
  • Loading branch information
yaacovCR committed Jan 8, 2020
1 parent 7c0d3a1 commit 963955b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 37 deletions.
25 changes: 12 additions & 13 deletions src/test/testMakeRemoteExecutableSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@ describe('remote subscriptions', () => {
`);

let notificationCnt = 0;
subscribe(schema, subscription).then(results =>
subscribe(schema, subscription).then(results => {
forAwaitEach(results as AsyncIterable<ExecutionResult>, (result: ExecutionResult) => {
expect(result).to.have.property('data');
expect(result.data).to.deep.equal(mockNotification);
!notificationCnt++ ? done() : null;
})
);

setTimeout(() => {
});
}).then(() => {
subscriptionPubSub.publish(subscriptionPubSubTrigger, mockNotification);
});
});
Expand All @@ -62,28 +60,29 @@ describe('remote subscriptions', () => {
`);

let notificationCnt = 0;
subscribe(schema, subscription).then(results =>
const sub1 = subscribe(schema, subscription).then(results => {
forAwaitEach(results as AsyncIterable<ExecutionResult>, (result: ExecutionResult) => {
expect(result).to.have.property('data');
expect(result.data).to.deep.equal(mockNotification);
notificationCnt++;
})
);
});
});

subscribe(schema, subscription).then(results =>
const sub2 = subscribe(schema, subscription).then(results => {
forAwaitEach(results as AsyncIterable<ExecutionResult>, (result: ExecutionResult) => {
expect(result).to.have.property('data');
expect(result.data).to.deep.equal(mockNotification);
})
);
});
});

setTimeout(() => {
Promise.all([sub1, sub2]).then(() => {
subscriptionPubSub.publish(subscriptionPubSubTrigger, mockNotification);
subscriptionPubSub.publish(subscriptionPubSubTrigger, mockNotification);

setTimeout(() => {
expect(notificationCnt).to.eq(2);
done();
});
}, 0);
});
});
});
Expand Down
24 changes: 6 additions & 18 deletions src/test/testMergeSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,15 +736,9 @@ bookingById(id: "b1") {
!notificationCnt++ ? done() : null;
},
).catch(done);
})
.catch(done);

setTimeout(() => {
subscriptionPubSub.publish(
subscriptionPubSubTrigger,
mockNotification
);
});
}).then(() => {
subscriptionPubSub.publish(subscriptionPubSubTrigger, mockNotification);
}).catch(done);
});

it('subscription errors are working correctly in merged schema', done => {
Expand Down Expand Up @@ -798,15 +792,9 @@ bookingById(id: "b1") {
!notificationCnt++ ? done() : null;
},
).catch(done);
})
.catch(done);

setTimeout(() => {
subscriptionPubSub.publish(
subscriptionPubSubTrigger,
mockNotification
);
});
}).then(() => {
subscriptionPubSub.publish(subscriptionPubSubTrigger, mockNotification);
}).catch(done);
});

it('links in queries', async () => {
Expand Down
9 changes: 3 additions & 6 deletions src/test/testResolution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,9 @@ describe('Resolve', () => {
done(new Error('Too many subscription fired'));
},
).catch(done);
})
.catch(done);
});

setTimeout(() => {
pubsub.publish('printRootChannel', { printRoot: subscriptionRoot });
}).then(() => {
pubsub.publish('printRootChannel', { printRoot: subscriptionRoot });
}).catch(done);
});

firstSubsTriggered
Expand Down

0 comments on commit 963955b

Please sign in to comment.