Skip to content

Commit

Permalink
Fix on Node 20
Browse files Browse the repository at this point in the history
  • Loading branch information
dguenther committed Nov 17, 2023
1 parent c7df900 commit 3b4d18e
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 278 deletions.
3 changes: 0 additions & 3 deletions config/jest.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@ module.exports = {
coverageProvider: "v8",
coverageReporters: ["text-summary", "json", "clover", "text"],
testPathIgnorePatterns: [".*\\.test\\.slow\\.ts$", ".*\\.test\\.perf\\.ts$"],
// TODO: Reconfiguring legacy defaults, we want to upgrade these eventually
// https://jestjs.io/blog/2021/05/25/jest-27#flipping-defaults
testRunner: "jest-jasmine2", // TODO: Remove `jest-jasmine2` dependency if we remove this
fakeTimers: { legacyFakeTimers: true },
};
3 changes: 1 addition & 2 deletions ironfish-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@
"eslint-config-ironfish": "*",
"eslint-plugin-deprecation": "2.0.0",
"jest": "29.7.0",
"jest-jasmine2": "29.7.0",
"oclif": "2.6.0",
"rimraf": "^3.0.2",
"tsc-watch": "4.2.9",
"typescript": "4.7.4",
"typescript": "5.0.4",
"yarn": "^1.22.10"
},
"scripts": {
Expand Down
3 changes: 1 addition & 2 deletions ironfish-rust-nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@
"@napi-rs/cli": "2.16.1",
"@types/jest": "29.5.8",
"jest": "29.7.0",
"jest-jasmine2": "29.7.0",
"rimraf": "3.0.2",
"ts-jest": "29.1.1",
"typescript": "4.7.4"
"typescript": "5.0.4"
}
}
42 changes: 21 additions & 21 deletions ironfish/jest.setup.env.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@
const consola = require('consola')
const { initializeSapling } = require('@ironfish/rust-nodejs')

jest.mock('node-datachannel', () => {
return {
PeerConnection: class {
onLocalDescription() {}
onLocalCandidate() {}
onDataChannel() {}
createDataChannel() {
return {
onOpen: () => {},
onError: () => {},
onClosed: () => {},
onMessage: () => {},
close: () => {},
isOpen: () => {},
sendMessage: () => {},
sendMessageBinary: (_buffer) => {},
}
}
},
}
})
// jest.mock('node-datachannel', () => {
// return {
// PeerConnection: class {
// onLocalDescription() {}
// onLocalCandidate() {}
// onDataChannel() {}
// createDataChannel() {
// return {
// onOpen: () => {},
// onError: () => {},
// onClosed: () => {},
// onMessage: () => {},
// close: () => {},
// isOpen: () => {},
// sendMessage: () => {},
// sendMessageBinary: (_buffer) => {},
// }
// }
// },
// }
// })

beforeAll(() => {
// This causes Sapling to be initialized, which is 1 time 2 second cost for each test suite
Expand Down
17 changes: 8 additions & 9 deletions ironfish/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@
"lint": "tsc -b && tsc -b tsconfig.test.json && eslint --ext .ts,.tsx,.js,.jsx src/",
"lint:fix": "tsc -b && tsc -b tsconfig.test.json && eslint --ext .ts,.tsx,.js,.jsx src/ --fix",
"start": "tsc -b -w",
"test": "tsc -b && tsc -b tsconfig.test.json && node --experimental-vm-modules ../node_modules/jest/bin/jest.js --testTimeout=${JEST_TIMEOUT:-5000}",
"test:slow": "tsc -b && tsc -b tsconfig.test.json && cross-env TEST_INIT_RUST=true jest --testMatch \"**/*.test.slow.ts\" --testPathIgnorePatterns --testTimeout=${JEST_TIMEOUT:-60000}",
"test:perf": "tsc -b && tsc -b tsconfig.test.json && cross-env TEST_INIT_RUST=true jest --testMatch \"**/*.test.perf.ts\" --testPathIgnorePatterns --testTimeout=${JEST_TIMEOUT:-600000} --runInBand",
"test:perf:report": "tsc -b && tsc -b tsconfig.test.json && cross-env TEST_INIT_RUST=true GENERATE_TEST_REPORT=true jest --config jest.config.js --testMatch \"**/*.test.perf.ts\" --testPathIgnorePatterns --testTimeout=${JEST_TIMEOUT:-600000} --ci",
"test:coverage:html": "tsc -b tsconfig.test.json && jest --testPathIgnorePatterns --coverage --coverage-reporters html",
"test:watch": "tsc -b tsconfig.test.json && jest --watch --coverage false",
"fixtures:regenerate": "find . -name \"__fixtures__\" | xargs rm -rf && JEST_TIMEOUT=1000000000 yarn run test && JEST_TIMEOUT=1000000000 yarn run test:slow && JEST_TIMEOUT=1000000000 yarn run test:perf"
"test": "tsc -b && tsc -b tsconfig.test.json && cross-env NODE_OPTIONS=--experimental-vm-modules jest --testTimeout=${JEST_TIMEOUT:-5000}",
"test:slow": "tsc -b && tsc -b tsconfig.test.json && cross-env NODE_OPTIONS=--experimental-vm-modules TEST_INIT_RUST=true jest --testMatch \"**/*.test.slow.ts\" --testPathIgnorePatterns --testTimeout=${JEST_TIMEOUT:-60000}",
"test:perf": "tsc -b && tsc -b tsconfig.test.json && cross-env NODE_OPTIONS=--experimental-vm-modules TEST_INIT_RUST=true jest --testMatch \"**/*.test.perf.ts\" --testPathIgnorePatterns --testTimeout=${JEST_TIMEOUT:-600000} --runInBand",
"test:perf:report": "tsc -b && tsc -b tsconfig.test.json && cross-env NODE_OPTIONS=--experimental-vm-modules TEST_INIT_RUST=true GENERATE_TEST_REPORT=true jest --config jest.config.js --testMatch \"**/*.test.perf.ts\" --testPathIgnorePatterns --testTimeout=${JEST_TIMEOUT:-600000} --ci",
"test:coverage:html": "tsc -b tsconfig.test.json && cross-env NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns --coverage --coverage-reporters html",
"test:watch": "tsc -b tsconfig.test.json && cross-env NODE_OPTIONS=--experimental-vm-modules jest --watch --coverage false",
"fixtures:regenerate": "find . -name \"__fixtures__\" | xargs rm -rf && NODE_OPTIONS=--experimental-vm-modules JEST_TIMEOUT=1000000000 yarn run test && NODE_OPTIONS=--experimental-vm-modules JEST_TIMEOUT=1000000000 yarn run test:slow && NODE_OPTIONS=--experimental-vm-modules JEST_TIMEOUT=1000000000 yarn run test:perf"
},
"devDependencies": {
"@jest/reporters": "29.3.1",
Expand All @@ -91,12 +91,11 @@
"eslint-plugin-prettier": "3.4.0",
"eslint-plugin-react-hooks": "4.2.0",
"jest": "29.7.0",
"jest-jasmine2": "29.3.1",
"mitm": "1.7.2",
"prettier": "2.3.2",
"ts-jest": "29.1.1",
"ts-node": "10.9.1",
"typescript": "4.7.4"
"typescript": "5.0.4"
},
"bugs": {
"url": "https://github.com/iron-fish/ironfish/issues"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import { Assert } from '../../../assert'
import { createRootLogger } from '../../../logger'
import { IdentifyMessage } from '../../messages/identify'
import { defaultFeatures } from '../peerFeatures'
Expand Down
16 changes: 4 additions & 12 deletions ironfish/src/network/peers/peerManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,19 +625,11 @@ describe('PeerManager', () => {
if (!peer.state.connections.webRtc) {
throw new Error('Peer should have a WebRTC connection')
}
const webRtcConnection = peer.state.connections.webRtc

// TODO: webRtcConnection.datachannel never actually opens during a test
// so when peer.send() gets called as part of the onConnect event, it
// closes the webRTC connection. For now, we'll mock the close function,
// but in the future, we should mock the datachannel class to make tests
// more robust -- deekerno
const closeSpy = jest.spyOn(webRtcConnection, 'close').mockImplementationOnce(() => {})
webRtcConnection.setState({

peer.state.connections.webRtc.setState({
type: 'CONNECTED',
identity: peerIdentity,
})
expect(closeSpy).toHaveBeenCalledTimes(1)

expect(pm.peers.length).toBe(2)
expect(pm.identifiedPeers.size).toBe(2)
Expand Down Expand Up @@ -668,7 +660,7 @@ describe('PeerManager', () => {
identity: peerIdentity,
connections: {
webSocket: unidentifiedConnection,
webRtc: webRtcConnection,
webRtc: peer.state.connections.webRtc,
},
})
expect(unidentifiedPeer.state).toEqual({
Expand Down Expand Up @@ -1166,7 +1158,7 @@ describe('PeerManager', () => {

peer.onMessage.emit(message, connection)
expect(initWebRtcConnectionMock).toHaveBeenCalledTimes(1)
expect(initWebRtcConnectionMock).toHaveBeenCalledWith(peer, true)
expect(initWebRtcConnectionMock).toHaveBeenCalledWith(peer, expect.anything(), true)
expect(pm['getBrokeringPeers'](peer)[0]).toEqual(peer)
})

Expand Down
22 changes: 20 additions & 2 deletions ironfish/src/network/testUtilities/mockLocalPeer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

/* eslint-disable @typescript-eslint/no-empty-function */
import { Blockchain } from '../../blockchain'
import { mockChain } from '../../testUtilities/mocks'
import { PrivateIdentity } from '../identity'
Expand All @@ -11,7 +11,25 @@ import { VERSION_PROTOCOL } from '../version'
import { WebSocketClient } from '../webSocketClient'
import { mockPrivateIdentity } from './mockPrivateIdentity'

const mockNodeDataChannel: NodeDataChannelType = {} as unknown as NodeDataChannelType
const mockNodeDataChannel: NodeDataChannelType = {
PeerConnection: class {
onLocalDescription() {}
onLocalCandidate() {}
onDataChannel() {}
createDataChannel() {
return {
onOpen: () => {},
onError: () => {},
onClosed: () => {},
onMessage: () => {},
close: () => {},
isOpen: () => {},
sendMessage: () => {},
sendMessageBinary: () => {},
}
}
},
} as unknown as NodeDataChannelType

/**
* Utility to create a fake "keypair" for testing the network layer
Expand Down
1 change: 0 additions & 1 deletion ironfish/tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
"tsBuildInfoFile": "./build/tsconfig.tsbuildinfo"
},
"include": ["src", "package.json"],
"references": [],
}
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,11 @@
"eslint-plugin-react-hooks": "4.2.0",
"eslint-plugin-simple-import-sort": "7.0.0",
"jest": "29.7.0",
"jest-jasmine2": "29.7.0",
"lerna": "6.4.1",
"node-gyp": "8.4.1",
"prettier": "2.3.2",
"ts-jest": "29.1.1",
"typescript": "4.7.4"
"typescript": "5.0.4"
},
"resolutions": {
"axios": "0.21.4",
Expand Down
Loading

0 comments on commit 3b4d18e

Please sign in to comment.