Skip to content
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

Resolve test snapshot issue between node 18 vs 20 & 21 #6794

Merged
merged 4 commits into from
Feb 12, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ exports[`Web3Context getContextObject should return correct context object 1`] =
},
"registeredSubscriptions": {},
"requestManager": Web3RequestManager {
"_emitter": EventEmitter {
"_emitter": {
"_events": {
"BEFORE_PROVIDER_CHANGE": [Function],
"PROVIDER_CHANGED": [Function],
},
"_eventsCount": 2,
"_maxListeners": undefined,
Symbol(kCapture): false,
Symbol(shapeMode): false,
},
"_provider": HttpProvider {
"clientUrl": "http://test/abc",
Expand All @@ -59,14 +60,15 @@ exports[`Web3Context getContextObject should return correct context object 1`] =
"_subscriptions": Map {},
"registeredSubscriptions": {},
"requestManager": Web3RequestManager {
"_emitter": EventEmitter {
"_emitter": {
"_events": {
"BEFORE_PROVIDER_CHANGE": [Function],
"PROVIDER_CHANGED": [Function],
},
"_eventsCount": 2,
"_maxListeners": undefined,
Symbol(kCapture): false,
Symbol(shapeMode): false,
},
"_provider": HttpProvider {
"clientUrl": "http://test/abc",
Expand Down
20 changes: 20 additions & 0 deletions packages/web3-core/test/unit/web3_context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,26 @@ describe('Web3Context', () => {
it('should return correct context object', () => {
const context = new Context1('http://test/abc');

// The following is because a specific property is different in node 18 than it is in node 20 and 21
// So the problematic property is removed from the object and then added to ensure its presence and its location
// And the snapshot is updated to reflect the change.
// Once node 18 is no longer supported, this can be removed. And the snapshot need to be updated then.

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const symbolForShapeMode = Object.getOwnPropertySymbols(
(context.getContextObject().requestManager as any)._emitter,
).find(s => s.description === 'shapeMode');
if (symbolForShapeMode) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
delete (context.getContextObject().requestManager as any)._emitter[symbolForShapeMode];
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(context.getContextObject().requestManager as any)._emitter = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
...(context.getContextObject().requestManager as any)._emitter,
[Symbol.for('shapeMode')]: false,
};

expect(context.getContextObject()).toMatchSnapshot();
});
});
Expand Down
Loading