Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
miquelbeltran committed Nov 19, 2024
1 parent a7557b5 commit 0502e8d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/sdk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ jobs:
# "dry" causes that if any file is modified, the job fails
dry: True
# "write" performs changes in place
prettier_options: --write .
prettier_options: --write "**/*.js" "**/*.ts" "**/*.tsx"
github_token: ${{ secrets.PERSONAL_GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions sdk/__mocks__/RaygunNativeBridge.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {NativeModules} from 'react-native';
import { NativeModules } from 'react-native';

NativeModules.RaygunNativeBridge = {
DEVICE_ID: '1234567890',
DEVICE_ID: '1234567890'
};
108 changes: 54 additions & 54 deletions sdk/__tests__/RaygunClient.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,58 @@ import { init, sendError } from '../src/RaygunClient';
import { RaygunClientOptions } from '../src/Types';

describe('RaygunClient', () => {
beforeAll(() => {
const options: RaygunClientOptions = {
apiKey: 'ABCD',
version: '1.2.3',
logLevel: 'off',
enableCrashReporting: true,
enableRealUserMonitoring: false,
disableNativeCrashReporting: true,
};
init(options);

global.fetch = jest.fn(() =>
Promise.resolve({
status: 200,
})
);
});

beforeEach(() => {
fetch.mockClear();
});

it('should send error correctly', async () => {
const error = new Error('Test error');
await sendError(error);

// fetch should be called once
expect(fetch).toHaveBeenCalledTimes(1);

// Check url correct
expect(fetch.mock.calls[0][0]).toBe('https://api.raygun.com/entries?apiKey=ABCD');

// Capture body from fetch and check if correct
const body = JSON.parse(fetch.mock.calls[0][1].body);
expect(body.Details.Error.Message).toBe('Test error');

// Check if the version is correct
expect(body.Details.Version).toBe('1.2.3');
});

it('should fail to send error', async () => {
fetch.mockImplementationOnce(() => Promise.reject('API is down'));
const error = new Error('Failed error');
await sendError(error);

expect(fetch).toHaveBeenCalledTimes(1);

// failed to send error should be stored in AsyncStorage
const storedErrors = await AsyncStorage.getItem('raygun4reactnative_local_storage');
expect(storedErrors).not.toBeNull();

const errors = JSON.parse(storedErrors);
expect(errors[0].Details.Error.Message).toBe('Failed error');
});
beforeAll(() => {
const options: RaygunClientOptions = {
apiKey: 'ABCD',
version: '1.2.3',
logLevel: 'off',
enableCrashReporting: true,
enableRealUserMonitoring: false,
disableNativeCrashReporting: true
};
init(options);

global.fetch = jest.fn(() =>
Promise.resolve({
status: 200
})
);
});

beforeEach(() => {
fetch.mockClear();
});

it('should send error correctly', async () => {
const error = new Error('Test error');
await sendError(error);

// fetch should be called once
expect(fetch).toHaveBeenCalledTimes(1);

// Check url correct
expect(fetch.mock.calls[0][0]).toBe('https://api.raygun.com/entries?apiKey=ABCD');

// Capture body from fetch and check if correct
const body = JSON.parse(fetch.mock.calls[0][1].body);
expect(body.Details.Error.Message).toBe('Test error');

// Check if the version is correct
expect(body.Details.Version).toBe('1.2.3');
});

it('should fail to send error', async () => {
fetch.mockImplementationOnce(() => Promise.reject('API is down'));
const error = new Error('Failed error');
await sendError(error);

expect(fetch).toHaveBeenCalledTimes(1);

// failed to send error should be stored in AsyncStorage
const storedErrors = await AsyncStorage.getItem('raygun4reactnative_local_storage');
expect(storedErrors).not.toBeNull();

const errors = JSON.parse(storedErrors);
expect(errors[0].Details.Error.Message).toBe('Failed error');
});
});
2 changes: 1 addition & 1 deletion sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"run_demo_3:windows": "cd ../demo && npx react-native run-android",
"run_demo_3:macos": "cd ../demo && cd ios && pod install && cd ../ && npx react-native run-ios",
"run_demo_3:linux": "cd ../demo && gnome-terminal -x bash -c \"npx react-native start\" && npx react-native run-android",
"prettier": "npx prettier --write src",
"prettier": "npx prettier --write **/*.js **/*.ts **/*.tsx",
"test": "jest"
},
"repository": {
Expand Down

0 comments on commit 0502e8d

Please sign in to comment.