Skip to content
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
21 changes: 21 additions & 0 deletions src/__tests__/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,27 @@ describe('Pushy server config', () => {
);
});

test('errors and invalid-update reports go through the client report', async () => {
setupClientMocks();
const { client } = await createClient();
const report = spyOn(client as any, 'report').mockImplementation(
async () => {}
);

(client as any).emitError(new Error('offline'), 'errorChecking');
client.reportInvalidUpdateOnce('noArtifact', 'h2');

expect(report).toHaveBeenCalledWith(
expect.objectContaining({ type: 'errorChecking', message: 'offline' })
);
expect(report).toHaveBeenCalledWith(
expect.objectContaining({
type: 'errorUpdate',
data: { newVersion: 'h2' },
})
);
});

test('calls afterCheckUpdate with skipped when beforeCheckUpdate returns false', async () => {
setupClientMocks();
const beforeCheckUpdate = mock(() => false);
Expand Down
1 change: 1 addition & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export class Pushy {
private readonly reporter = new Reporter({
options: this.options,
getEffectivePackageVersion: () => this.getEffectivePackageVersion(),
report: (event) => this.report(event),
telemetryEndpoint: () =>
this.checker.lastWorkingEndpoint || this.options.server?.main?.[0],
});
Expand Down
9 changes: 7 additions & 2 deletions src/clientReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export type UpdateErrorListener = (
export interface ReporterHost {
readonly options: ClientOptions;
getEffectivePackageVersion(): string;
/**
* The client's report: events raised here go through it, so a caller that
* replaces client.report sees them too.
*/
report(event: ReportEvent): Promise<void>;
/** The endpoint telemetry posts to: the last one that served a check. */
telemetryEndpoint(): string | undefined;
}
Expand Down Expand Up @@ -91,7 +96,7 @@ export class Reporter {
return;
}
this.reportedInvalidUpdates.add(key);
this.report({
this.host.report({
type: 'errorUpdate',
message:
reason === 'missingHash'
Expand Down Expand Up @@ -336,7 +341,7 @@ export class Reporter {
}: { message?: string; data?: Record<string, string | number> } = {}
) => {
this.emittedErrors.add(error);
this.report({
this.host.report({
type,
message,
code: error.code,
Expand Down
Loading