Skip to content

Commit c54fd24

Browse files
mydeabillyvg
andauthored
chore(deps): Downgrade typescript & jest to versions used in sentry-javascript (getsentry/sentry-replay#310)
For reasons™️ we are stuck with an old version of typescript (3.8) in sentry-javascript. In order to prepare the migration there, this PR downgrades typescript to that version as well. With it, that required some other changes, mainly also downgrading jest, which required adapting some tests... 😢 not ideal, but I tried to make it work with as little changes as possible. The two biggest issues were: * jest 27 does not support `jest.useFakeTimers({ autoAdvance: true })`, so needed to work around that somehow. I tried to replicate this manually * jest 27 does not support `expect.closeTo()`. This was used once, I commented this out for now. Other things: * `@ts-expect-error` is not supported, so instead we use `@ts-ignore` * eslint also needed downgrading * I had issues with `@jest/globals` (which we also don't use in sentry-javascript), so I changed this to use the globals everywhere Co-authored-by: Billy Vong <[email protected]>
1 parent 66571bd commit c54fd24

29 files changed

+1353
-1339
lines changed

.eslintrc.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ module.exports = {
2020
{ vars: 'all', varsIgnorePattern: '^_', argsIgnorePattern: '^_' },
2121
],
2222

23+
'@typescript-eslint/no-explicit-any': 'off',
24+
25+
// Make sure that all ts-ignore comments are given a description.
26+
'@typescript-eslint/ban-ts-comment': [
27+
'warn',
28+
{
29+
'ts-ignore': 'allow-with-description',
30+
},
31+
],
32+
2333
'simple-import-sort/imports': [
2434
'error',
2535
{

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@
2929
"typescript.preferences.quoteStyle": "single",
3030
"javascript.preferences.quoteStyle": "single",
3131
"prettier.jsxSingleQuote": true,
32-
"prettier.singleQuote": true
32+
"prettier.singleQuote": true,
33+
"typescript.tsdk": "node_modules/typescript/lib"
3334
}

config/rollup.config.core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const config = defineConfig({
3131
preventAssignment: false,
3232
values: {
3333
__SENTRY_REPLAY_VERSION__: JSON.stringify(pkg.version),
34-
// @ts-expect-error not gonna deal with types here
34+
// @ts-ignore not gonna deal with types here
3535
__SENTRY_DEBUG__: !IS_PRODUCTION,
3636
},
3737
}),

config/tsconfig.worker.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"declaration": false,
55
"lib": ["webworker", "scripthost"],
66
"baseUrl": "../worker/src",
7+
"rootDir": "../worker/src",
78
"outDir": "../src/worker"
89
},
910
"include": ["../worker/src/worker.ts", "../src/types.ts"]

demo/src/App.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,46 @@ import React from 'react';
22
import './App.css';
33

44
function App() {
5-
const [state, setState] = React.useState(99);
5+
const [state] = React.useState(99);
66
React.useEffect(() => {
77
async function test() {
8-
98
try {
10-
await fetch('/testing');
9+
await fetch('/testing');
1110
} catch {}
1211
}
1312

1413
test();
1514

1615
return () => {};
17-
}, [])
16+
}, []);
1817

1918
return (
20-
<div className='App'>
21-
<header className='App-header'>
22-
<img src={ `/logo${state}.png` } />
19+
<div className="App">
20+
<header className="App-header">
21+
<img src={`/logo${state}.png`} alt="" />
2322
<h1>Our cool React app</h1>
2423
</header>
2524

2625
<form>
2726
<div>
2827
<label>Email:</label>
29-
<input type='email' name='email' placehodler='email' />
28+
<input type="email" name="email" placehodler="email" />
3029
</div>
3130
<div>
3231
<label>Password:</label>
33-
<input type='password' name='password' placehodler='password' />
32+
<input type="password" name="password" placehodler="password" />
3433
</div>
3534
<div>
3635
<label>Secret:</label>
3736
<input
38-
type='email'
39-
name='email'
40-
placehodler='email'
41-
className='sr-ignore'
37+
type="email"
38+
name="email"
39+
placehodler="email"
40+
className="sr-ignore"
4241
/>
4342
</div>
4443

45-
<div className='sr-block'>
44+
<div className="sr-block">
4645
<p>Secret Block</p>
4746
</div>
4847
</form>

jest.setup.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Transport } from '@sentry/types';
44
import { Session } from './src/session/Session';
55
import { Replay } from './src';
66

7-
// @ts-expect-error TS error, this is replaced in prod builds bc of rollup
7+
// @ts-ignore TS error, this is replaced in prod builds bc of rollup
88
global.__SENTRY_REPLAY_VERSION__ = 'version:Test';
99

1010
type MockTransport = jest.MockedFunction<Transport['send']>;
@@ -88,17 +88,17 @@ const toHaveSentReplay = function (
8888
[recordingHeader, recordingPayload] = [],
8989
] = envelopeItems;
9090

91-
// @ts-expect-error recordingPayload is always a string in our tests
91+
// @ts-ignore recordingPayload is always a string in our tests
9292
const [recordingPayloadHeader, events] = recordingPayload?.split('\n') || [];
9393

9494
const actualObj: Required<SentReplayExpected> = {
95-
// @ts-expect-error Custom envelope
95+
// @ts-ignore Custom envelope
9696
envelopeHeader: envelopeHeader,
97-
// @ts-expect-error Custom envelope
97+
// @ts-ignore Custom envelope
9898
replayEventHeader: replayEventHeader,
99-
// @ts-expect-error Custom envelope
99+
// @ts-ignore Custom envelope
100100
replayEventPayload: replayEventPayload,
101-
// @ts-expect-error Custom envelope
101+
// @ts-ignore Custom envelope
102102
recordingHeader: recordingHeader,
103103
recordingPayloadHeader:
104104
recordingPayloadHeader && JSON.parse(recordingPayloadHeader),
@@ -107,7 +107,9 @@ const toHaveSentReplay = function (
107107

108108
const isObjectContaining =
109109
expected && 'sample' in expected && 'inverse' in expected;
110-
const expectedObj = isObjectContaining ? expected.sample : expected;
110+
const expectedObj = isObjectContaining
111+
? (expected as { sample: SentReplayExpected }).sample
112+
: (expected as SentReplayExpected);
111113

112114
if (isObjectContaining) {
113115
console.warn(
@@ -117,7 +119,7 @@ const toHaveSentReplay = function (
117119

118120
const results = expected
119121
? Object.entries(actualObj)
120-
.map(([key, val]: [key: keyof SentReplayExpected, val: any]) => {
122+
.map(([key, val]: [keyof SentReplayExpected, any]) => {
121123
return [
122124
!expectedObj?.[key] || this.equals(expectedObj[key], val),
123125
key,

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,30 @@
4242
"@sentry/browser": "^7.7.0",
4343
"@size-limit/file": "^8.1.0",
4444
"@size-limit/time": "^8.1.0",
45-
"@types/jest": "^29.2.1",
45+
"@types/jest": "27.5.1",
4646
"@types/lodash.debounce": "^4.0.7",
4747
"@types/lodash.throttle": "^4.1.7",
4848
"@types/node": "^18.11.0",
4949
"@types/pako": "^2.0.0",
5050
"@typescript-eslint/eslint-plugin": "^5.31.0",
5151
"@typescript-eslint/parser": "^5.31.0",
52-
"eslint": "^8.10.0",
52+
"eslint": "7.32.0",
5353
"eslint-config-prettier": "^8.5.0",
5454
"eslint-plugin-prettier": "^4.0.0",
5555
"eslint-plugin-simple-import-sort": "^7.0.0",
56-
"jest": "^29.2.1",
57-
"jest-environment-jsdom": "^29.2.1",
56+
"jest": "27.5.1",
57+
"jest-environment-jsdom": "27.5.1",
5858
"jsdom-worker": "^0.2.1",
5959
"pako": "^2.0.4",
6060
"prettier": "^2.5.1",
6161
"rimraf": "^3.0.2",
6262
"rollup": "^2.70.0",
6363
"rollup-plugin-terser": "^7.0.2",
6464
"size-limit": "^8.1.0",
65-
"ts-jest": "^29.0.3",
66-
"ts-node": "^10.9.1",
67-
"tslib": "^2.3.1",
68-
"typescript": "^4.8.4"
65+
"ts-jest": "27.1.4",
66+
"ts-node": "10.9.1",
67+
"tslib": "2.3.1",
68+
"typescript": "3.8.3"
6969
},
7070
"dependencies": {
7171
"@sentry/core": "^7.7.0",

src/coreHandlers/handleFetch.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ it('ignores fetches that have not completed yet', function () {
4646
...DEFAULT_DATA,
4747
};
4848

49-
// @ts-expect-error: The operand of a 'delete' operator must be optional.ts(2790)
49+
// @ts-ignore: The operand of a 'delete' operator must be optional.ts(2790)
5050
delete data.endTimestamp;
51-
// @ts-expect-error: The operand of a 'delete' operator must be optional.ts(2790)
51+
// @ts-ignore: The operand of a 'delete' operator must be optional.ts(2790)
5252
delete data.response;
5353

5454
expect(handleFetch(data)).toEqual(null);

src/coreHandlers/handleScope.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ it('returns a breadcrumb only if last breadcrumb has changed (unit)', function (
1313
} as unknown as Scope;
1414

1515
function addBreadcrumb(breadcrumb: Breadcrumb) {
16-
// @ts-expect-error using private member
16+
// @ts-ignore using private member
1717
scope._breadcrumbs.push(breadcrumb);
1818
}
1919

src/coreHandlers/handleScope.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { createBreadcrumb } from '../util/createBreadcrumb';
55
let _LAST_BREADCRUMB: null | Breadcrumb = null;
66

77
export function handleScope(scope: Scope) {
8-
//@ts-expect-error using private val
8+
//@ts-ignore using private val
99
const newBreadcrumb = scope._breadcrumbs[scope._breadcrumbs.length - 1];
1010

1111
// Listener can be called when breadcrumbs have not changed, so we store the

0 commit comments

Comments
 (0)