Skip to content

build(replay): Streamline tsconfig & jest config #6399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 5, 2022
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
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"search.exclude": {
"**/node_modules/": true,
"**/build/": true,
"**/dist/": true
"**/dist/": true,
"**/coverage/": true,
"**/yarn-error.log": true
},
"typescript.tsdk": "./node_modules/typescript/lib",
"[json]": {
Expand Down
2 changes: 0 additions & 2 deletions packages/replay/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ module.exports = {
files: ['test/**/*.ts'],

rules: {
// TODO: decide if we want to keep our '@test' import paths
'import/no-unresolved': 'off',
// most of these errors come from `new Promise(process.nextTick)`
'@typescript-eslint/unbound-method': 'off',
// TODO: decide if we want to enable this again after the migration
Expand Down
7 changes: 0 additions & 7 deletions packages/replay/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
import type { Config } from '@jest/types';
import { pathsToModuleNameMapper } from 'ts-jest';
import { jsWithTs as jsWithTsPreset } from 'ts-jest/presets';

import { compilerOptions } from './tsconfig.test.json';

export default async (): Promise<Config.InitialOptions> => {
return {
...jsWithTsPreset,
verbose: true,
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.test.json',
},
__DEBUG_BUILD__: true,
},
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
prefix: '<rootDir>/',
}),
setupFilesAfterEnv: ['./jest.setup.ts'],
testEnvironment: 'jsdom',
testMatch: ['<rootDir>/test/**/*(*.)@(spec|test).ts'],
Expand Down
6 changes: 3 additions & 3 deletions packages/replay/test/mocks/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { getCurrentHub } from '@sentry/core';
import { BASE_TIMESTAMP, RecordMock } from '@test';
import { DomHandler, MockTransportSend } from '@test/types';
import { Replay } from 'src';

import { ReplayConfiguration } from '../../src/types';
import { Replay } from './../../src';
import { BASE_TIMESTAMP, RecordMock } from './../index';
import { DomHandler, MockTransportSend } from './../types';

export async function resetSdkMock(options?: ReplayConfiguration): Promise<{
domHandler: DomHandler;
Expand Down
3 changes: 1 addition & 2 deletions packages/replay/test/unit/coreHandlers/handleFetch.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { mockSdk } from '@test';

import { handleFetch } from '../../../src/coreHandlers/handleFetch';
import { mockSdk } from './../../index';

jest.unmock('@sentry/browser');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getCurrentHub } from '@sentry/core';
import { mockSdk } from '@test';

import * as HandleScope from '../../../src/coreHandlers/handleScope';
import { mockSdk } from './../../index';

let mockHandleScope: jest.MockedFunction<typeof HandleScope.handleScope>;

Expand Down
3 changes: 1 addition & 2 deletions packages/replay/test/unit/createPerformanceEntry.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { mockSdk } from '@test';

import { createPerformanceEntries } from '../../src/createPerformanceEntry';
import { mockSdk } from './../index';

jest.unmock('@sentry/browser');

Expand Down
2 changes: 1 addition & 1 deletion packages/replay/test/unit/eventBuffer.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'jsdom-worker';

import { BASE_TIMESTAMP } from '@test';
import pako from 'pako';

import { createEventBuffer, EventBufferCompressionWorker } from './../../src/eventBuffer';
import { BASE_TIMESTAMP } from './../index';

const TEST_EVENT = { data: {}, timestamp: BASE_TIMESTAMP, type: 3 };

Expand Down
2 changes: 1 addition & 1 deletion packages/replay/test/unit/flush.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as SentryUtils from '@sentry/utils';
import { BASE_TIMESTAMP, mockRrweb, mockSdk } from '@test';

import { SESSION_IDLE_DURATION, WINDOW } from '../../src/constants';
import { Replay } from './../../src';
import { createPerformanceEntries } from './../../src/createPerformanceEntry';
import { useFakeTimers } from './../../test/utils/use-fake-timers';
import { BASE_TIMESTAMP, mockRrweb, mockSdk } from './../index';

useFakeTimers();

Expand Down
8 changes: 4 additions & 4 deletions packages/replay/test/unit/index-errorSampleRate.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
jest.unmock('@sentry/browser');

import { captureException } from '@sentry/browser';
import { BASE_TIMESTAMP, RecordMock } from '@test';
import { PerformanceEntryResource } from '@test/fixtures/performanceEntry/resource';
import { resetSdkMock } from '@test/mocks';
import { DomHandler, MockTransportSend } from '@test/types';

import { REPLAY_SESSION_KEY, VISIBILITY_CHANGE_TIMEOUT, WINDOW } from '../../src/constants';
import { Replay } from './../../src';
import { PerformanceEntryResource } from './../fixtures/performanceEntry/resource';
import { BASE_TIMESTAMP, RecordMock } from './../index';
import { resetSdkMock } from './../mocks';
import { DomHandler, MockTransportSend } from './../types';
import { useFakeTimers } from './../utils/use-fake-timers';

useFakeTimers();
Expand Down
6 changes: 3 additions & 3 deletions packages/replay/test/unit/index-handleGlobalEvent.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { getCurrentHub } from '@sentry/core';
import { Error } from '@test/fixtures/error';
import { Transaction } from '@test/fixtures/transaction';
import { resetSdkMock } from '@test/mocks';

import { REPLAY_EVENT_NAME } from '../../src/constants';
import { Replay } from './../../src';
import { Error } from './../fixtures/error';
import { Transaction } from './../fixtures/transaction';
import { resetSdkMock } from './../mocks';
import { useFakeTimers } from './../utils/use-fake-timers';

useFakeTimers();
Expand Down
3 changes: 1 addition & 2 deletions packages/replay/test/unit/index-integrationSettings.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { mockSdk } from '@test';

import { Replay } from '../../src';
import { mockSdk } from './../index';

let replay: Replay;

Expand Down
2 changes: 1 addition & 1 deletion packages/replay/test/unit/index-noSticky.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { getCurrentHub } from '@sentry/core';
import { Transport } from '@sentry/types';
import * as SentryUtils from '@sentry/utils';
import { BASE_TIMESTAMP, mockRrweb, mockSdk } from '@test';

import { SESSION_IDLE_DURATION, VISIBILITY_CHANGE_TIMEOUT } from '../../src/constants';
import { Replay } from './../../src';
import { BASE_TIMESTAMP, mockRrweb, mockSdk } from './../index';
import { useFakeTimers } from './../utils/use-fake-timers';

useFakeTimers();
Expand Down
3 changes: 1 addition & 2 deletions packages/replay/test/unit/index-sampling.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
jest.unmock('@sentry/browser');

// mock functions need to be imported first
import { mockRrweb, mockSdk } from '@test';

import { mockRrweb, mockSdk } from './../index';
import { useFakeTimers } from './../utils/use-fake-timers';

useFakeTimers();
Expand Down
8 changes: 4 additions & 4 deletions packages/replay/test/unit/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
jest.mock('./../../src/util/isInternal', () => ({
isInternal: jest.fn(() => true),
}));
import { BASE_TIMESTAMP, RecordMock } from '@test';
import { PerformanceEntryResource } from '@test/fixtures/performanceEntry/resource';
import { resetSdkMock } from '@test/mocks';
import { DomHandler, MockTransportSend } from '@test/types';
import { EventType } from 'rrweb';

import { Replay } from '../../src';
import { MAX_SESSION_LIFE, REPLAY_SESSION_KEY, VISIBILITY_CHANGE_TIMEOUT, WINDOW } from '../../src/constants';
import { RecordingEvent } from '../../src/types';
import { useFakeTimers } from '../utils/use-fake-timers';
import { PerformanceEntryResource } from './../fixtures/performanceEntry/resource';
import { BASE_TIMESTAMP, RecordMock } from './../index';
import { resetSdkMock } from './../mocks';
import { DomHandler, MockTransportSend } from './../types';

useFakeTimers();

Expand Down
4 changes: 2 additions & 2 deletions packages/replay/test/unit/stop.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as SentryUtils from '@sentry/utils';
// mock functions need to be imported first
import { BASE_TIMESTAMP, mockRrweb, mockSdk } from '@test';

import { SESSION_IDLE_DURATION, WINDOW } from '../../src/constants';
import { Replay } from './../../src';
// mock functions need to be imported first
import { BASE_TIMESTAMP, mockRrweb, mockSdk } from './../index';
import { useFakeTimers } from './../utils/use-fake-timers';

useFakeTimers();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// eslint-disable-next-line import/no-unresolved
import { PerformanceEntryLcp } from '@test/fixtures/performanceEntry/lcp';
import { PerformanceEntryNavigation } from '@test/fixtures/performanceEntry/navigation';
import { PerformanceEntryResource } from '@test/fixtures/performanceEntry/resource';

import { dedupePerformanceEntries } from '../../../src/util/dedupePerformanceEntries';
import { PerformanceEntryLcp } from './../../fixtures/performanceEntry/lcp';
import { PerformanceEntryNavigation } from './../../fixtures/performanceEntry/navigation';
import { PerformanceEntryResource } from './../../fixtures/performanceEntry/resource';

it('does nothing with a single entry', function () {
const entries = [PerformanceEntryNavigation()];
Expand Down
13 changes: 2 additions & 11 deletions packages/replay/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"module": "esnext",
"noImplicitAny": true,
"noEmitOnError": false,
"esModuleInterop": true,
"resolveJsonModule": true,
"allowJs": true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I thought we'd need at least allowJs here because of the worker 🤔 but not complaining if we don't need it either 😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the worker is just loaded as plain text, not as actual js, that's why it works probably!

"declaration": true,
"declarationMap": true,
"strictNullChecks": true
"module": "esnext"
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
"include": ["src/**/*.ts"]
}
15 changes: 5 additions & 10 deletions packages/replay/tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@
"include": ["test/**/*.ts", "jest.config.ts", "jest.setup.ts"],

"compilerOptions": {
"paths": {
"@test": ["./test"],
"@test/*": ["./test/*"]
},
"baseUrl": ".",
"rootDir": ".",
"types": ["node", "jest"],
"noImplicitAny": false,
"esModuleInterop": true,
"allowJs": true,
"noImplicitAny": true,
"noImplicitThis": false,
"strictPropertyInitialization": false,
"resolveJsonModule": true,
"allowJs": true
"strictNullChecks": true,
"strictPropertyInitialization": false
}
}