Skip to content

Commit ad26c27

Browse files
author
Alan Shaw
authored
fix: tests in CI (#1034)
Node.js v16.14.0 included [a fix](nodejs/node#40706) that meant that `@web-std/blob` started using the Node.js native version. Bad news, Node.js currently copies the buffer on every iteration when obtaining a stream from `File.stream()`. It also has a fixed and small chunk size of `65536` bytes. This makes reading the stream VERY slow and this test fails because it times out. I opened an issue about this here: nodejs/node#42108 Once the test was fixed, the cloudflare build for the website started failing so I had to update next.js to v12. WTF!?! After that, the client build started failing with: ``` Error: Build failed with 2 errors: ../../node_modules/parse-link-header/index.js:3:17: error: Could not resolve "querystring" (use "platform: 'node'" when building for node) ../../node_modules/parse-link-header/index.js:4:18: error: Could not resolve "url" (use "platform: 'node'" when building for node) at failureErrorWithLog (/Users/alan/Code/web3-storage/web3.storage/node_modules/esbuild/lib/main.js:1493:15) at /Users/alan/Code/web3-storage/web3.storage/node_modules/esbuild/lib/main.js:1151:28 at runOnEndCallbacks (/Users/alan/Code/web3-storage/web3.storage/node_modules/esbuild/lib/main.js:941:63) at buildResponseToResult (/Users/alan/Code/web3-storage/web3.storage/node_modules/esbuild/lib/main.js:1149:7) at /Users/alan/Code/web3-storage/web3.storage/node_modules/esbuild/lib/main.js:1258:14 at /Users/alan/Code/web3-storage/web3.storage/node_modules/esbuild/lib/main.js:629:9 at handleIncomingPacket (/Users/alan/Code/web3-storage/web3.storage/node_modules/esbuild/lib/main.js:726:9) at Socket.readFromStdout (/Users/alan/Code/web3-storage/web3.storage/node_modules/esbuild/lib/main.js:596:7) at Socket.emit (node:events:520:28) at addChunk (node:internal/streams/readable:315:12) { errors: [ { detail: undefined, location: [Object], notes: [], pluginName: '', text: `Could not resolve "querystring" (use "platform: 'node'" when building for node)` }, { detail: undefined, location: [Object], notes: [], pluginName: '', text: `Could not resolve "url" (use "platform: 'node'" when building for node)` } ], warnings: [] } ``` So I had to roll the update to `parse-link-header` from #1032 into here as well.
1 parent 0e5d0f8 commit ad26c27

File tree

7 files changed

+13473
-8042
lines changed

7 files changed

+13473
-8042
lines changed

package-lock.json

Lines changed: 13423 additions & 8024 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/client/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@
3131
},
3232
"dependencies": {
3333
"@ipld/car": "^3.1.4",
34-
"@web-std/blob": "^3.0.1",
35-
"@web-std/fetch": "^3.0.0",
36-
"@web-std/file": "^3.0.0",
34+
"@web-std/blob": "^3.0.3",
35+
"@web-std/fetch": "^3.0.3",
36+
"@web-std/file": "^3.0.2",
37+
"@web3-storage/parse-link-header": "^3.1.0",
3738
"browser-readablestream-to-it": "^1.0.3",
3839
"carbites": "^1.0.6",
3940
"cborg": "^1.6.0",
4041
"files-from-path": "^0.2.3",
41-
"ipfs-car": "^0.6.1",
42+
"ipfs-car": "^0.6.2",
4243
"ipns": "^0.16.0",
4344
"libp2p-crypto": "^0.21.0",
4445
"p-retry": "^4.5.0",
45-
"parse-link-header": "^2.0.0",
4646
"streaming-iterables": "^6.0.0",
4747
"uint8arrays": "^3.0.0"
4848
},
@@ -52,7 +52,6 @@
5252
"@rollup/plugin-json": "^4.1.0",
5353
"@rollup/plugin-node-resolve": "^13.1.3",
5454
"@types/mocha": "9.0.0",
55-
"@types/parse-link-header": "^1.0.1",
5655
"bundlesize": "^0.18.1",
5756
"cors": "^2.8.5",
5857
"del-cli": "^4.0.0",
@@ -62,6 +61,7 @@
6261
"npm-run-all": "^4.1.5",
6362
"nyc": "15.1.0",
6463
"playwright-test": "^7.2.2",
64+
"randombytes": "^2.1.0",
6565
"rollup": "2.63.0",
6666
"rollup-plugin-multi-input": "1.3.1",
6767
"rollup-plugin-terser": "^7.0.2",

packages/client/src/lib.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import { transform } from 'streaming-iterables'
1717
import pRetry from 'p-retry'
1818
import { pack } from 'ipfs-car/pack'
19-
import parseLink from 'parse-link-header'
19+
import { parseLinkHeader } from '@web3-storage/parse-link-header'
2020
import { unpackStream } from 'ipfs-car/unpack'
2121
import { TreewalkCarSplitter } from 'carbites/treewalk'
2222
import { CarReader } from '@ipld/car'
@@ -469,13 +469,13 @@ function toWeb3Response (res) {
469469
async function * paginator (fn, service, opts) {
470470
let res = await fn(service, opts)
471471
yield res
472-
let link = parseLink(res.headers.get('Link') || '')
472+
let link = parseLinkHeader(res.headers.get('Link') || '')
473473
// @ts-ignore
474474
while (link && link.next) {
475475
// @ts-ignore
476476
res = await fn(service, link.next)
477477
yield res
478-
link = parseLink(res.headers.get('Link') || '')
478+
link = parseLinkHeader(res.headers.get('Link') || '')
479479
}
480480
}
481481

packages/client/test/put.spec.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { CID } from 'multiformats/cid'
99
import { encode } from 'multiformats/block'
1010
import * as json from '@ipld/dag-json'
1111
import { sha256 } from 'multiformats/hashes/sha2'
12+
import { ReadableStream } from '@web-std/blob'
1213

1314
describe('put', () => {
1415
const { AUTH_TOKEN, API_PORT } = process.env
@@ -85,12 +86,31 @@ describe('put', () => {
8586
})
8687

8788
it('adds big files', async function () {
88-
this.timeout(30e3)
89+
this.timeout(60e3)
8990
const client = new Web3Storage({ token, endpoint })
9091
let uploadedChunks = 0
9192

9293
const files = [
93-
new File([randomBytes(1024e6)], '102mb.txt')
94+
// Previously: new File([randomBytes(1024e6)], '102mb.txt')
95+
//
96+
// Node.js currently copies the buffer on every iteration when obtaining a
97+
// stream from File.stream(). It also has a fixed and small chunk size of
98+
// 65536 bytes. This makes reading the stream VERY slow and this test
99+
// fails because it times out.
100+
//
101+
// TODO: revert to using File if this issue gets resolved:
102+
// https://github.com/nodejs/node/issues/42108
103+
{
104+
name: '102mb.txt',
105+
stream () {
106+
return new ReadableStream({
107+
pull (controller) {
108+
controller.enqueue(randomBytes(1024e6))
109+
controller.close()
110+
}
111+
})
112+
}
113+
}
94114
]
95115

96116
await client.put(files, {

packages/website/next-env.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/// <reference types="next" />
2-
/// <reference types="next/types/global" />
32
/// <reference types="next/image-types/global" />
43

54
// NOTE: This file should not be edited

packages/website/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"filesize": "^6.1.0",
1717
"gray-matter": "^4.0.3",
1818
"magic-sdk": "^4.2.1",
19-
"next": "^11.0.1",
19+
"next": "^12.1.0",
2020
"p-map": "^5.1.0",
2121
"pretty-bytes": "^5.6.0",
2222
"rc-tooltip": "^5.1.1",

packages/website/tsconfig.json

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
"allowJs": true,
55
"checkJs": true,
66
"target": "esnext",
7-
"lib": ["ESNext", "DOM"],
7+
"lib": [
8+
"ESNext",
9+
"DOM"
10+
],
811
"strict": true,
912
"moduleResolution": "node",
1013
"sourceMap": true,
@@ -17,11 +20,21 @@
1720
"resolveJsonModule": true,
1821
"isolatedModules": true,
1922
"paths": {
20-
"web3.storage": ["../client"]
21-
}
23+
"web3.storage": [
24+
"../client"
25+
]
26+
},
27+
"incremental": true
2228
},
23-
"include": ["lib", "pages", "components"],
24-
"exclude": ["node_modules/", ".next/"],
29+
"include": [
30+
"lib",
31+
"pages",
32+
"components"
33+
],
34+
"exclude": [
35+
"node_modules/",
36+
".next/"
37+
],
2538
"references": [
2639
{
2740
"path": "../client"

0 commit comments

Comments
 (0)