Skip to content

Commit

Permalink
reorganize files
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhiPrasad committed Feb 25, 2025
1 parent cb9da78 commit 4bdb668
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 37 deletions.
7 changes: 0 additions & 7 deletions packages/feedback/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,4 @@

module.exports = {
extends: ['../../.eslintrc.js'],
overrides: [
{
parserOptions: {
project: ['tsconfig.test.json'],
},
},
],
};
1 change: 1 addition & 0 deletions packages/feedback/src/core/TestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class TestClient extends Client<TestClientOptions> {
/**
*
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public eventFromException(exception: any): PromiseLike<Event> {
return resolvedSyncPromise({
exception: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { TRIGGER_LABEL } from '../../constants';
import { getFeedback } from '../getFeedback';
import { buildFeedbackIntegration } from '../integration';
/**
* @vitest-environment jsdom
*/
import { vi, describe, it, expect } from 'vitest';

import { TRIGGER_LABEL } from '../../../src/constants';
import { getFeedback } from '../../../src/core/getFeedback';
import { buildFeedbackIntegration } from '../../../src/core/integration';
import { mockSdk } from '../mockSdk';

describe('Actor', () => {
it('renders the actor button', () => {
const feedbackIntegration = buildFeedbackIntegration({
lazyLoadIntegration: jest.fn(),
lazyLoadIntegration: vi.fn(),
});

const configuredIntegration = feedbackIntegration({});
Expand All @@ -27,7 +32,7 @@ describe('Actor', () => {

it('renders the correct aria label for the button', () => {
const feedbackIntegration = buildFeedbackIntegration({
lazyLoadIntegration: jest.fn(),
lazyLoadIntegration: vi.fn(),
});

const configuredIntegration = feedbackIntegration({});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { vi, describe, it, expect } from 'vitest';

import { getCurrentScope } from '@sentry/core';
import { getFeedback } from './getFeedback';
import { buildFeedbackIntegration } from './integration';
import { getFeedback } from '../../src/core/getFeedback';
import { buildFeedbackIntegration } from '../../src/core/integration';
import { mockSdk } from './mockSdk';

describe('getFeedback', () => {
Expand All @@ -26,7 +28,7 @@ describe('getFeedback', () => {

it('works with a client with Feedback', () => {
const feedbackIntegration = buildFeedbackIntegration({
lazyLoadIntegration: jest.fn(),
lazyLoadIntegration: vi.fn(),
});

const configuredIntegration = feedbackIntegration({});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { vi } from 'vitest';

import type { Envelope, Transport, TransportMakeRequestResponse } from '@sentry/core';

import type { TestClientOptions } from './TestClient';
import { getDefaultClientOptions, init } from './TestClient';
import type { TestClientOptions } from '../../src/core/TestClient';
import { getDefaultClientOptions, init } from '../../src/core/TestClient';

export interface MockSdkParams {
sentryOptions?: Partial<TestClientOptions>;
Expand All @@ -11,7 +13,7 @@ class MockTransport implements Transport {
public send: (request: Envelope) => PromiseLike<TransportMakeRequestResponse>;

public constructor() {
this.send = jest.fn(async () => {
this.send = vi.fn(async () => {
return {
statusCode: 200,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* @vitest-environment jsdom
*/
import { vi, describe, it, expect } from 'vitest';

import {
addBreadcrumb,
getClient,
Expand All @@ -9,7 +14,7 @@ import {
} from '@sentry/core';

import { mockSdk } from './mockSdk';
import { sendFeedback } from './sendFeedback';
import { sendFeedback } from '../../src/core/sendFeedback';

import { TextDecoder, TextEncoder } from 'util';
const patchedEncoder = (!global.window.TextEncoder && (global.window.TextEncoder = TextEncoder)) || true;
Expand All @@ -20,7 +25,7 @@ describe('sendFeedback', () => {
beforeEach(() => {
getIsolationScope().clear();
getCurrentScope().clear();
jest.clearAllMocks();
vi.clearAllMocks();
});

afterAll(() => {
Expand All @@ -32,7 +37,7 @@ describe('sendFeedback', () => {

it('sends feedback with minimal options', async () => {
mockSdk();
const mockTransport = jest.spyOn(getClient()!.getTransport()!, 'send');
const mockTransport = vi.spyOn(getClient()!.getTransport()!, 'send');

const promise = sendFeedback({
message: 'mi',
Expand Down Expand Up @@ -67,7 +72,7 @@ describe('sendFeedback', () => {
feedback: {
message: 'mi',
source: 'api',
url: 'http://localhost/',
url: 'http://localhost:3000/',
},
},
level: 'info',
Expand All @@ -83,7 +88,7 @@ describe('sendFeedback', () => {

it('sends feedback with full options', async () => {
mockSdk();
const mockTransport = jest.spyOn(getClient()!.getTransport()!, 'send');
const mockTransport = vi.spyOn(getClient()!.getTransport()!, 'send');

const promise = sendFeedback({
name: 'doe',
Expand Down Expand Up @@ -142,7 +147,7 @@ describe('sendFeedback', () => {

it('applies active span data to feedback', async () => {
mockSdk({ sentryOptions: { tracesSampleRate: 1 } });
const mockTransport = jest.spyOn(getClient()!.getTransport()!, 'send');
const mockTransport = vi.spyOn(getClient()!.getTransport()!, 'send');

await startSpan({ name: 'test span' }, () => {
return sendFeedback({
Expand Down Expand Up @@ -181,7 +186,7 @@ describe('sendFeedback', () => {
message: 'mi',
name: 'doe',
source: 'api',
url: 'http://localhost/',
url: 'http://localhost:3000/',
},
},
level: 'info',
Expand All @@ -197,7 +202,7 @@ describe('sendFeedback', () => {

it('applies scope data to feedback', async () => {
mockSdk({ sentryOptions: { tracesSampleRate: 1 } });
const mockTransport = jest.spyOn(getClient()!.getTransport()!, 'send');
const mockTransport = vi.spyOn(getClient()!.getTransport()!, 'send');

await withIsolationScope(isolationScope => {
isolationScope.setTag('test-1', 'tag');
Expand Down Expand Up @@ -242,7 +247,7 @@ describe('sendFeedback', () => {
message: 'mi',
name: 'doe',
source: 'api',
url: 'http://localhost/',
url: 'http://localhost:3000/',
},
},
extra: {
Expand All @@ -266,7 +271,7 @@ describe('sendFeedback', () => {

it('handles 400 transport error', async () => {
mockSdk();
jest.spyOn(getClient()!.getTransport()!, 'send').mockImplementation(() => {
vi.spyOn(getClient()!.getTransport()!, 'send').mockImplementation(() => {
return Promise.resolve({ statusCode: 400 });
});

Expand All @@ -283,7 +288,7 @@ describe('sendFeedback', () => {

it('handles 0 transport error', async () => {
mockSdk();
jest.spyOn(getClient()!.getTransport()!, 'send').mockImplementation(() => {
vi.spyOn(getClient()!.getTransport()!, 'send').mockImplementation(() => {
return Promise.resolve({ statusCode: 0 });
});

Expand All @@ -300,7 +305,7 @@ describe('sendFeedback', () => {

it('handles 200 transport response', async () => {
mockSdk();
jest.spyOn(getClient()!.getTransport()!, 'send').mockImplementation(() => {
vi.spyOn(getClient()!.getTransport()!, 'send').mockImplementation(() => {
return Promise.resolve({ statusCode: 200 });
});

Expand All @@ -314,10 +319,10 @@ describe('sendFeedback', () => {
});

it('handles timeout', async () => {
jest.useFakeTimers();
vi.useFakeTimers();

mockSdk();
jest.spyOn(getClient()!.getTransport()!, 'send').mockImplementation(() => {
vi.spyOn(getClient()!.getTransport()!, 'send').mockImplementation(() => {
return new Promise(resolve => setTimeout(resolve, 10_000));
});

Expand All @@ -327,16 +332,16 @@ describe('sendFeedback', () => {
message: 'mi',
});

jest.advanceTimersByTime(5_000);
vi.advanceTimersByTime(5_000);

await expect(promise).rejects.toMatch('Unable to determine if Feedback was correctly sent.');

jest.useRealTimers();
vi.useRealTimers();
});

it('sends attachments', async () => {
mockSdk();
const mockTransport = jest.spyOn(getClient()!.getTransport()!, 'send');
const mockTransport = vi.spyOn(getClient()!.getTransport()!, 'send');

const attachment1 = new Uint8Array([1, 2, 3, 4, 5]);
const attachment2 = new Uint8Array([6, 7, 8, 9]);
Expand Down Expand Up @@ -395,7 +400,7 @@ describe('sendFeedback', () => {
message: 'mi',
name: 'doe',
source: 'api',
url: 'http://localhost/',
url: 'http://localhost:3000/',
},
},
level: 'info',
Expand Down
2 changes: 1 addition & 1 deletion packages/feedback/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"react-dom": ["./node_modules/preact/compat/"]
}
},
"include": ["src/**/*.ts","src/**/*.tsx"]
"include": ["src/**/*.ts", "src/**/*.tsx"]
}

0 comments on commit 4bdb668

Please sign in to comment.