Skip to content

Commit

Permalink
chore: convert node-specific tests to run in browsers (#2803)
Browse files Browse the repository at this point in the history
Converts tests to use the memory transport to allow running all tests in browsers.

Removes dependencies on WebSockets, TCP, circuit relay etc so changes in these modules don't cause additional releases here.
  • Loading branch information
achingbrain authored Nov 5, 2024
1 parent adc7678 commit 58ca044
Show file tree
Hide file tree
Showing 31 changed files with 981 additions and 3,552 deletions.
57 changes: 1 addition & 56 deletions packages/libp2p/.aegir.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,6 @@
/** @type {import('aegir').PartialOptions} */
export default {
build: {
bundlesizeMax: '147kB'
},
test: {
before: async () => {
// use dynamic import because we only want to reference these files during the test run, e.g. after building
const { webSockets } = await import('@libp2p/websockets')
const { mplex } = await import('@libp2p/mplex')
const { yamux } = await import('@chainsafe/libp2p-yamux')
const { WebSockets } = await import('@multiformats/mafmt')
const { createLibp2p } = await import('./dist/src/index.js')
const { plaintext } = await import('@libp2p/plaintext')
const { circuitRelayServer, circuitRelayTransport } = await import('@libp2p/circuit-relay-v2')
const { identify } = await import('@libp2p/identify')
const { echo } = await import('./dist/test/fixtures/echo-service.js')

const libp2p = await createLibp2p({
connectionManager: {
inboundConnectionThreshold: Infinity
},
addresses: {
listen: [
'/ip4/127.0.0.1/tcp/0/ws'
]
},
transports: [
circuitRelayTransport(),
webSockets()
],
streamMuxers: [
yamux(),
mplex()
],
connectionEncrypters: [
plaintext()
],
services: {
identify: identify(),
relay: circuitRelayServer({
reservations: {
maxReservations: Infinity
}
}),
echo: echo()
}
})

return {
libp2p,
env: {
RELAY_MULTIADDR: libp2p.getMultiaddrs().filter(ma => WebSockets.matches(ma)).pop()
}
}
},
after: async (_, before) => {
await before.libp2p.stop()
}
bundlesizeMax: '95KB'
}
}
21 changes: 8 additions & 13 deletions packages/libp2p/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@
"prepublishOnly": "node scripts/update-version.js && npm run build",
"build": "aegir build",
"test": "aegir test",
"test:node": "aegir test -t node -f \"./dist/test/**/*.{node,spec}.js\" --cov",
"test:chrome": "aegir test -t browser -f \"./dist/test/**/*.spec.js\" --cov",
"test:chrome-webworker": "aegir test -t webworker -f \"./dist/test/**/*.spec.js\"",
"test:firefox": "aegir test -t browser -f \"./dist/test/**/*.spec.js\" -- --browser firefox",
"test:firefox-webworker": "aegir test -t webworker -f \"./dist/test/**/*.spec.js\" -- --browser firefox",
"test:webkit": "aegir test -t browser -f \"./dist/test/**/*.spec.js\" -- --browser webkit"
"test:node": "aegir test -t node --cov",
"test:chrome": "aegir test -t browser --cov",
"test:chrome-webworker": "aegir test -t webworker",
"test:firefox": "aegir test -t browser -- --browser firefox",
"test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
"test:webkit": "aegir test -t browser -- --browser webkit"
},
"dependencies": {
"@libp2p/crypto": "^5.0.6",
Expand Down Expand Up @@ -114,22 +114,17 @@
},
"devDependencies": {
"@chainsafe/libp2p-yamux": "^7.0.0",
"@libp2p/circuit-relay-v2": "^3.1.0",
"@libp2p/identify": "^3.0.10",
"@libp2p/echo": "^2.1.1",
"@libp2p/interface-compliance-tests": "^6.1.8",
"@libp2p/memory": "^0.0.0",
"@libp2p/mplex": "^11.0.10",
"@libp2p/plaintext": "^2.0.10",
"@libp2p/tcp": "^10.0.11",
"@libp2p/websockets": "^9.0.11",
"@multiformats/mafmt": "^12.1.6",
"aegir": "^44.0.1",
"delay": "^6.0.0",
"it-all": "^3.0.6",
"it-drain": "^3.0.7",
"it-map": "^3.1.0",
"it-pair": "^2.0.6",
"it-pipe": "^3.0.1",
"it-pushable": "^3.2.3",
"it-stream-types": "^2.0.1",
"it-take": "^3.0.5",
"p-event": "^6.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/libp2p/src/upgrader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export class DefaultUpgrader implements Upgrader {
accepted = await this.components.connectionManager.acceptIncomingConnection(maConn)

if (!accepted) {
throw new ConnectionDeniedError('connection denied')
throw new ConnectionDeniedError('Connection denied')
}

await this.shouldBlockConnection('denyInboundConnection', maConn)
Expand Down
Loading

0 comments on commit 58ca044

Please sign in to comment.