Skip to content

Commit e27cb96

Browse files
committed
test: polyfill Float16Array on older Node.js for WPT
1 parent 60cf136 commit e27cb96

6 files changed

Lines changed: 22 additions & 2 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
"@exodus/prettier": "^1.0.0",
146146
"@exodus/test": "^1.0.0-rc.109",
147147
"@noble/hashes": "^2.0.1",
148+
"@petamoriken/float16": "^3.9.3",
148149
"@scure/base": "^1.2.6",
149150
"@stablelib/base64": "^2.0.1",
150151
"@stablelib/hex": "^2.0.1",

pnpm-lock.yaml

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

tests/vendor/workerd/api/encoding_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ export const encodeWptTest = {
350350
Uint16Array,
351351
Uint32Array,
352352
Uint8ClampedArray,
353-
// Float16Array,
353+
Float16Array,
354354
Float32Array,
355355
Float64Array,
356356
].forEach((view) => {

tests/vendor/workerd/index.test.cjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ const { test, describe } = require('node:test')
33

44
Object.assign(globalThis, { TextDecoder, TextEncoder })
55

6+
// Older but supported Node.js versions don't have Float16Array which is used in some tests
7+
if (!globalThis.Float16Array) {
8+
const { Float16Array } = require('@petamoriken/float16')
9+
Object.assign(globalThis, { Float16Array })
10+
}
11+
612
function run(title, tests) {
713
describe(title, () => {
814
for (const [name, obj] of Object.entries(tests)) {

tests/wpt/fixtures/encoding/encodeInto.any.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@
134134
"Float64Array"].forEach(type => {
135135
["ArrayBuffer", "SharedArrayBuffer"].forEach((arrayBufferOrSharedArrayBuffer) => {
136136
test(() => {
137-
if (!self[type]) return // Added, as old engines don't have e.g. Float16Array
138137
const viewInstance = new self[type](createBuffer(arrayBufferOrSharedArrayBuffer, 0));
139138
assert_throws_js(TypeError, () => new TextEncoder().encodeInto("", viewInstance));
140139
}, "Invalid encodeInto() destination: " + type + ", backed by: " + arrayBufferOrSharedArrayBuffer);

tests/wpt/loader.cjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ if (!globalThis.ReadableStream) {
99
Object.assign(globalThis, { ReadableStream, WritableStream, TransformStream })
1010
}
1111

12+
// Older but supported Node.js versions don't have Float16Array which is used in some tests
13+
if (!globalThis.Float16Array) {
14+
const { Float16Array } = require('@petamoriken/float16')
15+
Object.assign(globalThis, { Float16Array })
16+
}
17+
1218
globalThis.self = globalThis
1319

1420
globalThis.setup = (f) => f()

0 commit comments

Comments
 (0)