Skip to content

Commit 2235269

Browse files
fix: add node 20 compatibility for tests and build
jest.config.js: Add moduleNameMapper for Node.js built-ins in jsdom - Maps undici, cheerio to mocks - Maps node:stream/util/assert/buffer to polyfills - Maps node:net/tls/http/https/async_hooks/url/querystring/diagnostics_channel to mocks tsconfig.build.json: Add skipLibCheck and noImplicitAny - Resolves type conflicts, supports legacy patterns src/AutoSizer/index.tsx: Fix import - AutoSizerProps to Props as AutoSizerProps src/CodeViewer/utils/lineNumberify.ts: Add newTree type annotation (AST.Element[]) src/ScrollContainer/index.tsx: Add callback types + multi-line JSX format - Fixes tslint compliance Add 9 mock files for undici, cheerio, and Node built-ins: - undici.js, cheerio.js, cheerio_utils.js, node_async_hooks.js - node_net.js, node_tls.js, node_url.js, node_querystring.js, diagnostics_channel.js src/styles/tailwind/_base.scss: Auto-generated by build process Result: All 6 test suites (17 tests) pass, yarn build and yarn test.prod working
1 parent ac0eaf0 commit 2235269

18 files changed

Lines changed: 47784 additions & 20278 deletions

__mocks__/cheerio.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Mock for cheerio
2+
module.exports = {
3+
load: () => (() => {}),
4+
};

__mocks__/cheerio_utils.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Mock for cheerio/lib/utils
2+
module.exports = {
3+
camelCase: (str) => str,
4+
isEmptyObject: () => false,
5+
};

__mocks__/diagnostics_channel.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class TracingChannel {
2+
constructor(name) {
3+
this.name = name;
4+
}
5+
subscribe() {}
6+
unsubscribe() {}
7+
publish() {}
8+
hasSubscribers() {
9+
return false;
10+
}
11+
}
12+
13+
module.exports = {
14+
channel: () => new TracingChannel(),
15+
TracingChannel,
16+
};

__mocks__/node_async_hooks.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Mock for node:async_hooks
2+
module.exports = {
3+
createHook: () => ({
4+
enable: () => {},
5+
disable: () => {},
6+
}),
7+
executionAsyncResource: () => {},
8+
executionAsyncId: () => 0,
9+
triggerAsyncId: () => 0,
10+
AsyncLocalStorage: class {},
11+
AsyncResource: class {},
12+
};

__mocks__/node_net.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {};

__mocks__/node_querystring.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Mock for node:querystring
2+
const querystring = require('querystring');
3+
module.exports = querystring;

__mocks__/node_tls.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {};

__mocks__/node_url.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Mock for node:url
2+
const url = require('url');
3+
module.exports = url;

__mocks__/undici.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Mock for undici to prevent loading Node.js built-in dependencies
2+
module.exports = {
3+
fetch: () => Promise.resolve({ ok: true }),
4+
Client: class {},
5+
Pool: class {},
6+
Agent: class {},
7+
};

jest.config.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,25 @@ module.exports = {
33
testEnvironment: 'jsdom',
44
setupFilesAfterEnv: ['./setupTests.ts'],
55
snapshotSerializers: ['enzyme-to-json/serializer'],
6+
// Map modules to mocks/polyfills for Node 20 compatibility
67
moduleNameMapper: {
78
'\\.(css)$': '<rootDir>/__mocks__/styleMock.js',
9+
'^cheerio$': '<rootDir>/__mocks__/cheerio.js',
10+
'^cheerio/lib/utils$': '<rootDir>/__mocks__/cheerio_utils.js',
11+
'^undici$': '<rootDir>/__mocks__/undici.js',
12+
'^node:stream$': 'stream-browserify',
13+
'^node:util$': 'util',
14+
'^node:assert$': 'assert',
15+
'^node:buffer$': 'buffer',
16+
'^node:url$': '<rootDir>/__mocks__/node_url.js',
17+
'^node:async_hooks$': '<rootDir>/__mocks__/node_async_hooks.js',
18+
'^node:net$': '<rootDir>/__mocks__/node_net.js',
19+
'^node:tls$': '<rootDir>/__mocks__/node_tls.js',
20+
'^node:http$': '<rootDir>/__mocks__/node_net.js',
21+
'^node:https$': '<rootDir>/__mocks__/node_tls.js',
22+
'^node:events$': 'events',
23+
'^node:querystring$': '<rootDir>/__mocks__/node_querystring.js',
24+
'^node:diagnostics_channel$': '<rootDir>/__mocks__/diagnostics_channel.js',
825
},
926
testPathIgnorePatterns: ['/node_modules/'],
1027
};

0 commit comments

Comments
 (0)