Skip to content

Commit

Permalink
Merge pull request #4 from spatie/feature/fixes-v-1-1-0
Browse files Browse the repository at this point in the history
Misc fixes for v1.1.0
  • Loading branch information
sebastiandedeyne authored Oct 1, 2024
2 parents 2260a15 + c8148bc commit 8d72a6b
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 53 deletions.
6 changes: 3 additions & 3 deletions packages/js/src/Flare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { assert, assertKey, assertSolutionProvider, now } from './util';

export class Flare {
config: Config = {
key: KEY,
key: null,
version: CLIENT_VERSION,
sourcemapVersion: SOURCEMAP_VERSION,
stage: '',
Expand All @@ -32,7 +32,7 @@ export class Flare {
context: Context = { context: {} };
solutionProviders: SolutionProvider[] = [];

constructor(public http: Api = new Api()) {}
constructor(public api: Api = new Api()) {}

light(key: string = KEY, debug: boolean = false): Flare {
this.config.key = key;
Expand Down Expand Up @@ -184,7 +184,7 @@ export class Flare {
return;
}

return this.http.report(
return this.api.report(
reportToSubmit,
this.config.reportingUrl,
this.config.key,
Expand Down
4 changes: 2 additions & 2 deletions packages/js/src/api/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { Report } from '../types';
import { flatJsonStringify } from '../util';

export class Api {
report(report: Report, url: string, key: string, reportBrowserExtensionErrors: boolean): Promise<void> {
report(report: Report, url: string, key: string | null, reportBrowserExtensionErrors: boolean): Promise<void> {
return fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Api-Token': key,
'X-Api-Token': key ?? '',
'X-Requested-With': 'XMLHttpRequest',
'X-Report-Browser-Extension-Errors': JSON.stringify(reportBrowserExtensionErrors),
},
Expand Down
2 changes: 1 addition & 1 deletion packages/js/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type Config = {
key: string;
key: string | null;
version: string;
sourcemapVersion: string;
stage: string;
Expand Down
10 changes: 5 additions & 5 deletions packages/js/tests/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { Flare } from '../src';

import { FakeApi } from './helpers';

let fakeHttp: FakeApi;
let fakeApi: FakeApi;
let client: Flare;

beforeEach(() => {
fakeHttp = new FakeApi();
client = new Flare(fakeHttp).configure({
fakeApi = new FakeApi();
client = new Flare(fakeApi).configure({
key: 'key',
debug: true,
});
Expand All @@ -21,8 +21,8 @@ test('can create custom context and context groups', async () => {

await client.report(new Error());

expect(fakeHttp.reports).toHaveLength(1);
expect(fakeHttp.lastReport?.context).toEqual({
expect(fakeApi.reports).toHaveLength(1);
expect(fakeApi.lastReport?.context).toEqual({
context: {
user: 1,
},
Expand Down
6 changes: 3 additions & 3 deletions packages/js/tests/glows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { Flare } from '../src';

import { FakeApi } from './helpers';

let fakeHttp: FakeApi;
let fakeApi: FakeApi;
let client: Flare;

beforeEach(() => {
fakeHttp = new FakeApi();
client = new Flare(fakeHttp).configure({
fakeApi = new FakeApi();
client = new Flare(fakeApi).configure({
key: 'key',
debug: true,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/js/tests/helpers/FakeApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class FakeApi extends Api {
lastKey?: string;
lastReportBrowserExtensionErrors?: boolean;

report(report: Report, url: string, key: string, reportBrowserExtensionErrors: boolean): Promise<void> {
report(report: Report, url: string, key: string | null, reportBrowserExtensionErrors: boolean): Promise<void> {
this.reports.push(report);

this.lastUrl = url;
Expand Down
38 changes: 19 additions & 19 deletions packages/js/tests/hooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { Flare } from '../src';

import { FakeApi } from './helpers';

let fakeHttp: FakeApi;
let fakeApi: FakeApi;
let client: Flare;

beforeEach(() => {
fakeHttp = new FakeApi();
client = new Flare(fakeHttp).configure({
fakeApi = new FakeApi();
client = new Flare(fakeApi).configure({
key: 'key',
debug: true,
});
Expand All @@ -22,7 +22,7 @@ test('can stop a report from being submitted by returning null from beforeEvalua

await client.report(new Error());

expect(fakeHttp.reports).toHaveLength(0);
expect(fakeApi.reports).toHaveLength(0);
});

test('can stop a report from being submitted by returning false from beforeEvaluate', async () => {
Expand All @@ -32,7 +32,7 @@ test('can stop a report from being submitted by returning false from beforeEvalu

await client.report(new Error());

expect(fakeHttp.reports).toHaveLength(0);
expect(fakeApi.reports).toHaveLength(0);
});

test('can stop a report from being submitted by returning null from async beforeEvaluate', async () => {
Expand All @@ -42,7 +42,7 @@ test('can stop a report from being submitted by returning null from async before

await client.report(new Error());

expect(fakeHttp.reports).toHaveLength(0);
expect(fakeApi.reports).toHaveLength(0);
});

test('can stop a report from being submitted by returning false from async beforeEvaluate', async () => {
Expand All @@ -52,7 +52,7 @@ test('can stop a report from being submitted by returning false from async befor

await client.report(new Error());

expect(fakeHttp.reports).toHaveLength(0);
expect(fakeApi.reports).toHaveLength(0);
});

test('can edit a report using beforeEvaluate', async () => {
Expand All @@ -65,8 +65,8 @@ test('can edit a report using beforeEvaluate', async () => {

await client.report(new Error());

expect(fakeHttp.reports).toHaveLength(1);
expect(fakeHttp.lastReport?.message).toBe('All your base are belong to us');
expect(fakeApi.reports).toHaveLength(1);
expect(fakeApi.lastReport?.message).toBe('All your base are belong to us');
});

test('can edit a report using async beforeEvaluate', async () => {
Expand All @@ -79,8 +79,8 @@ test('can edit a report using async beforeEvaluate', async () => {

await client.report(new Error());

expect(fakeHttp.reports).toHaveLength(1);
expect(fakeHttp.lastReport?.message).toBe('All your base are belong to us');
expect(fakeApi.reports).toHaveLength(1);
expect(fakeApi.lastReport?.message).toBe('All your base are belong to us');
});

test('can stop a report from being submitted by returning null from beforeSubmit', async () => {
Expand All @@ -90,7 +90,7 @@ test('can stop a report from being submitted by returning null from beforeSubmit

await client.report(new Error());

expect(fakeHttp.reports).toHaveLength(0);
expect(fakeApi.reports).toHaveLength(0);
});

test('can stop a report from being submitted by returning false from beforeSubmit', async () => {
Expand All @@ -100,7 +100,7 @@ test('can stop a report from being submitted by returning false from beforeSubmi

await client.report(new Error());

expect(fakeHttp.reports).toHaveLength(0);
expect(fakeApi.reports).toHaveLength(0);
});

test('can stop a report from being submitted by returning null from async beforeSubmit', async () => {
Expand All @@ -110,7 +110,7 @@ test('can stop a report from being submitted by returning null from async before

await client.report(new Error());

expect(fakeHttp.reports).toHaveLength(0);
expect(fakeApi.reports).toHaveLength(0);
});

test('can stop a report from being submitted by returning false from async beforeSubmit', async () => {
Expand All @@ -120,7 +120,7 @@ test('can stop a report from being submitted by returning false from async befor

await client.report(new Error());

expect(fakeHttp.reports).toHaveLength(0);
expect(fakeApi.reports).toHaveLength(0);
});

test('can edit a report using beforeSubmit', async () => {
Expand All @@ -133,8 +133,8 @@ test('can edit a report using beforeSubmit', async () => {

await client.report(new Error());

expect(fakeHttp.reports).toHaveLength(1);
expect(fakeHttp.lastReport?.message).toBe('All your base are belong to us');
expect(fakeApi.reports).toHaveLength(1);
expect(fakeApi.lastReport?.message).toBe('All your base are belong to us');
});

test('can edit a report using async beforeSubmit', async () => {
Expand All @@ -147,6 +147,6 @@ test('can edit a report using async beforeSubmit', async () => {

await client.report(new Error());

expect(fakeHttp.reports).toHaveLength(1);
expect(fakeHttp.lastReport?.message).toBe('All your base are belong to us');
expect(fakeApi.reports).toHaveLength(1);
expect(fakeApi.lastReport?.message).toBe('All your base are belong to us');
});
22 changes: 11 additions & 11 deletions packages/js/tests/report.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { Flare } from '../src';

import { FakeApi } from './helpers';

let fakeHttp: FakeApi;
let fakeApi: FakeApi;
let client: Flare;

beforeEach(() => {
fakeHttp = new FakeApi();
client = new Flare(fakeHttp).configure({
fakeApi = new FakeApi();
client = new Flare(fakeApi).configure({
key: 'key',
debug: true,
});
Expand All @@ -20,34 +20,34 @@ test('can send an error report from an error', async () => {

await client.report(error);

expect(fakeHttp.reports).toHaveLength(1);
expect(fakeHttp.lastReport?.message).toBe('Critical malfunction !?!?');
expect(fakeApi.reports).toHaveLength(1);
expect(fakeApi.lastReport?.message).toBe('Critical malfunction !?!?');
});

test('can send a message', async () => {
await client.reportMessage('Hello, Flare!');

expect(fakeHttp.reports).toHaveLength(1);
expect(fakeHttp.lastReport?.message).toBe('Hello, Flare!');
expect(fakeApi.reports).toHaveLength(1);
expect(fakeApi.lastReport?.message).toBe('Hello, Flare!');
});

test('report the test message', async () => {
await client.test();

expect(fakeHttp.reports).toHaveLength(1);
expect(fakeHttp.lastReport?.message).toBe('The Flare client is set up correctly!');
expect(fakeApi.reports).toHaveLength(1);
expect(fakeApi.lastReport?.message).toBe('The Flare client is set up correctly!');
});

test('does not report browser extension errors by default', async () => {
await client.test();

expect(fakeHttp.lastReportBrowserExtensionErrors).toBe(false);
expect(fakeApi.lastReportBrowserExtensionErrors).toBe(false);
});

test('can be configured to report browser extension errors', async () => {
client.configure({ reportBrowserExtensionErrors: true });

await client.test();

expect(fakeHttp.lastReportBrowserExtensionErrors).toBe(true);
expect(fakeApi.lastReportBrowserExtensionErrors).toBe(true);
});
16 changes: 8 additions & 8 deletions packages/js/tests/solutions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { Flare } from '../src';

import { FakeApi } from './helpers';

let fakeHttp: FakeApi;
let fakeApi: FakeApi;
let client: Flare;

beforeEach(() => {
fakeHttp = new FakeApi();
client = new Flare(fakeHttp).configure({
fakeApi = new FakeApi();
client = new Flare(fakeApi).configure({
key: 'key',
debug: true,
});
Expand Down Expand Up @@ -39,8 +39,8 @@ test('can use solution providers', async () => {

await client.report(new Error());

expect(fakeHttp.lastReport?.solutions).toHaveLength(1);
expect(fakeHttp.lastReport?.solutions[0]?.title).toBe('My solution');
expect(fakeApi.lastReport?.solutions).toHaveLength(1);
expect(fakeApi.lastReport?.solutions[0]?.title).toBe('My solution');
});

test('can use async solution providers', async () => {
Expand All @@ -58,8 +58,8 @@ test('can use async solution providers', async () => {

await client.report(new Error());

expect(fakeHttp.lastReport?.solutions).toHaveLength(1);
expect(fakeHttp.lastReport?.solutions[0]?.title).toBe('My solution');
expect(fakeApi.lastReport?.solutions).toHaveLength(1);
expect(fakeApi.lastReport?.solutions[0]?.title).toBe('My solution');
});

test('does not use solution providers that can not solve the error', async () => {
Expand All @@ -77,5 +77,5 @@ test('does not use solution providers that can not solve the error', async () =>

await client.report(new Error());

expect(fakeHttp.lastReport?.solutions).toHaveLength(0);
expect(fakeApi.lastReport?.solutions).toHaveLength(0);
});

0 comments on commit 8d72a6b

Please sign in to comment.