Skip to content

Commit

Permalink
wpt: add gzip-body.any.js (nodejs#1778)
Browse files Browse the repository at this point in the history
* wpt: add gzip-body.any.js

* fix: try fixing windows ci failure
  • Loading branch information
KhafraDev authored and crysmags committed Feb 27, 2024
1 parent 6f701b2 commit 248691d
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 1 deletion.
21 changes: 20 additions & 1 deletion test/wpt/server/server.mjs
Expand Up @@ -3,7 +3,7 @@ import { createServer } from 'node:http'
import { join } from 'node:path'
import process from 'node:process'
import { fileURLToPath } from 'node:url'
import { createReadStream, readFileSync } from 'node:fs'
import { createReadStream, readFileSync, existsSync } from 'node:fs'
import { setTimeout as sleep } from 'node:timers/promises'
import { route as networkPartitionRoute } from './routes/network-partition-key.mjs'
import { route as redirectRoute } from './routes/redirect.mjs'
Expand Down Expand Up @@ -32,6 +32,8 @@ const server = createServer(async (req, res) => {
const fullUrl = new URL(req.url, `http://localhost:${server.address().port}`)

switch (fullUrl.pathname) {
case '/fetch/content-encoding/resources/foo.octetstream.gz':
case '/fetch/content-encoding/resources/foo.text.gz':
case '/fetch/api/resources/cors-top.txt':
case '/fetch/api/resources/top.txt':
case '/mimesniff/mime-types/resources/generated-mime-types.json':
Expand All @@ -47,6 +49,23 @@ const server = createServer(async (req, res) => {
case '/fetch/data-urls/resources/data-urls.json':
case '/fetch/api/resources/empty.txt':
case '/fetch/api/resources/data.json': {
// If this specific resources requires custom headers
const customHeadersPath = join(tests, fullUrl.pathname + '.headers')
if (existsSync(customHeadersPath)) {
const headers = readFileSync(customHeadersPath, 'utf-8')
.trim()
.split(/\r?\n/g)
.map((h) => h.split(': '))

for (const [key, value] of headers) {
if (!key || !value) {
console.warn(`Skipping ${key}:${value} header pair`)
continue
}
res.setHeader(key, value)
}
}

// https://github.com/web-platform-tests/wpt/blob/6ae3f702a332e8399fab778c831db6b7dca3f1c6/fetch/api/resources/data.json
return createReadStream(join(tests, fullUrl.pathname))
.on('end', () => res.end())
Expand Down
16 changes: 16 additions & 0 deletions test/wpt/tests/fetch/content-encoding/gzip-body.any.js
@@ -0,0 +1,16 @@
// META: global=window,worker

const expectedDecompressedSize = 10500;
[
"text",
"octetstream"
].forEach(contentType => {
promise_test(async t => {
let response = await fetch(`resources/foo.${contentType}.gz`);
assert_true(response.ok);
let arrayBuffer = await response.arrayBuffer()
let u8 = new Uint8Array(arrayBuffer);
assert_equals(u8.length, expectedDecompressedSize);
}, `fetched gzip data with content type ${contentType} should be decompressed.`);
});

Binary file not shown.
@@ -0,0 +1,2 @@
Content-type: application/octet-stream
Content-Encoding: gzip
Binary file not shown.
@@ -0,0 +1,2 @@
Content-type: text/plain
Content-Encoding: gzip

0 comments on commit 248691d

Please sign in to comment.