Implement deno, add other headers
parent
6a8a07deef
commit
091d829ad3
|
@ -4,8 +4,8 @@ const tests = {
|
||||||
try {
|
try {
|
||||||
const ctrl = new AbortController();
|
const ctrl = new AbortController();
|
||||||
setTimeout(() => ctrl.abort(), 5000);
|
setTimeout(() => ctrl.abort(), 5000);
|
||||||
const response = await fetch('https://httpbin.org/get', {
|
const response = await fetch('http://httpbin.org/get', {
|
||||||
headers: {'Cookie': 'overwrote-cookie'},
|
headers: {Cookie: 'overwrote-cookie'},
|
||||||
signal: ctrl.signal,
|
signal: ctrl.signal,
|
||||||
});
|
});
|
||||||
const o = await response.json();
|
const o = await response.json();
|
||||||
|
@ -18,8 +18,8 @@ const tests = {
|
||||||
try {
|
try {
|
||||||
const ctrl = new AbortController();
|
const ctrl = new AbortController();
|
||||||
setTimeout(() => ctrl.abort(), 5000);
|
setTimeout(() => ctrl.abort(), 5000);
|
||||||
const response = await fetch('https://httpbin.org/get', {
|
const response = await fetch('http://httpbin.org/get', {
|
||||||
headers: {'Referer': 'overwrote-referer'},
|
headers: {Referer: 'overwrote-referer'},
|
||||||
signal: ctrl.signal,
|
signal: ctrl.signal,
|
||||||
});
|
});
|
||||||
const o = await response.json();
|
const o = await response.json();
|
||||||
|
@ -32,7 +32,7 @@ const tests = {
|
||||||
try {
|
try {
|
||||||
const ctrl = new AbortController();
|
const ctrl = new AbortController();
|
||||||
setTimeout(() => ctrl.abort(), 5000);
|
setTimeout(() => ctrl.abort(), 5000);
|
||||||
const response = await fetch('https://httpbin.org/get', {
|
const response = await fetch('http://httpbin.org/get', {
|
||||||
headers: {'Keep-Alive': 'timeout=5, max=1000'},
|
headers: {'Keep-Alive': 'timeout=5, max=1000'},
|
||||||
signal: ctrl.signal,
|
signal: ctrl.signal,
|
||||||
});
|
});
|
||||||
|
@ -46,8 +46,8 @@ const tests = {
|
||||||
try {
|
try {
|
||||||
const ctrl = new AbortController();
|
const ctrl = new AbortController();
|
||||||
setTimeout(() => ctrl.abort(), 5000);
|
setTimeout(() => ctrl.abort(), 5000);
|
||||||
const response = await fetch('https://httpbin.org/get', {
|
const response = await fetch('http://httpbin.org/get', {
|
||||||
headers: {'Date': 'overwrote-date'},
|
headers: {Date: 'overwrote-date'},
|
||||||
signal: ctrl.signal,
|
signal: ctrl.signal,
|
||||||
});
|
});
|
||||||
const o = await response.json();
|
const o = await response.json();
|
||||||
|
@ -60,8 +60,8 @@ const tests = {
|
||||||
try {
|
try {
|
||||||
const ctrl = new AbortController();
|
const ctrl = new AbortController();
|
||||||
setTimeout(() => ctrl.abort(), 5000);
|
setTimeout(() => ctrl.abort(), 5000);
|
||||||
const response = await fetch('https://httpbin.org/get', {
|
const response = await fetch('http://httpbin.org/get', {
|
||||||
headers: {'Host': 'overwrote-host.example.com'},
|
headers: {Host: 'overwrote-host.example.com'},
|
||||||
signal: ctrl.signal,
|
signal: ctrl.signal,
|
||||||
});
|
});
|
||||||
const o = await response.json();
|
const o = await response.json();
|
||||||
|
@ -70,11 +70,25 @@ const tests = {
|
||||||
return error.toString();
|
return error.toString();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async acceptContentLength() {
|
async acceptContentLength0() {
|
||||||
try {
|
try {
|
||||||
const ctrl = new AbortController();
|
const ctrl = new AbortController();
|
||||||
setTimeout(() => ctrl.abort(), 5000);
|
setTimeout(() => ctrl.abort(), 5000);
|
||||||
const response = await fetch('https://httpbin.org/get', {
|
const response = await fetch('http://httpbin.org/get', {
|
||||||
|
headers: {'Content-Length': '0'},
|
||||||
|
signal: ctrl.signal,
|
||||||
|
});
|
||||||
|
const o = await response.json();
|
||||||
|
return `Content-Length: ${o.headers['Content-Length']}`;
|
||||||
|
} catch (error) {
|
||||||
|
return error.toString();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async acceptContentLength2() {
|
||||||
|
try {
|
||||||
|
const ctrl = new AbortController();
|
||||||
|
setTimeout(() => ctrl.abort(), 5000);
|
||||||
|
const response = await fetch('http://httpbin.org/get', {
|
||||||
headers: {'Content-Length': '2'},
|
headers: {'Content-Length': '2'},
|
||||||
signal: ctrl.signal,
|
signal: ctrl.signal,
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
import run from './run.js';
|
||||||
|
|
||||||
|
async function main(file) {
|
||||||
|
const tests = await import('./' + file + '.js');
|
||||||
|
const result = await run(tests.default);
|
||||||
|
console.log(JSON.stringify(result));
|
||||||
|
}
|
||||||
|
|
||||||
|
main(Deno.args[0]).catch((error) => {
|
||||||
|
console.error(error);
|
||||||
|
});
|
File diff suppressed because it is too large
Load Diff
|
@ -1,3 +1,4 @@
|
||||||
|
import path from 'path';
|
||||||
import logger from '@wdio/logger';
|
import logger from '@wdio/logger';
|
||||||
import Table from 'cli-table3';
|
import Table from 'cli-table3';
|
||||||
|
|
||||||
|
@ -62,12 +63,15 @@ function* tabularResults(results: Record<string, Result>): Iterable<string[]> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
|
const fixturesPath = path.join(process.cwd(), 'fixtures');
|
||||||
|
|
||||||
// Set up fixtures server
|
// Set up fixtures server
|
||||||
const fixturesServer = new FixturesServer();
|
const fixturesServer = new FixturesServer(fixturesPath);
|
||||||
const addr = await fixturesServer.start();
|
const addr = await fixturesServer.start();
|
||||||
|
|
||||||
// Shared data among platforms
|
// Shared data among platforms
|
||||||
const ctx: Context = {
|
const ctx: Context = {
|
||||||
|
fixturesPath,
|
||||||
fixturesURL: addr.base,
|
fixturesURL: addr.base,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,32 @@
|
||||||
import cp from 'child_process';
|
import {spawn} from 'child_process';
|
||||||
|
import logger from '@wdio/logger';
|
||||||
// @ts-expect-error: Missing types
|
// @ts-expect-error: Missing types
|
||||||
import {binary} from 'deno-prebuilt';
|
import {binary} from 'deno-prebuilt';
|
||||||
|
|
||||||
import {Platform, Result} from './types.js';
|
import {Platform, Result} from './types.js';
|
||||||
|
|
||||||
|
const log = logger('fetch-compare');
|
||||||
|
|
||||||
export default class PlatformDeno implements Platform {
|
export default class PlatformDeno implements Platform {
|
||||||
async run(): Promise<Result> {
|
async run(ctx: Record<string, any>, file: string): Promise<Result> {
|
||||||
throw new Error('not implemented');
|
const child = spawn(
|
||||||
/* eslint-disable no-unreachable */
|
binary,
|
||||||
const child = cp.spawn(binary, []);
|
['run', '--allow-read', '--allow-net=httpbin.org', 'index-deno.js', file],
|
||||||
await new Promise((resolve, reject) => {
|
{cwd: ctx.fixturesPath},
|
||||||
|
);
|
||||||
|
const stdout = await new Promise((resolve, reject) => {
|
||||||
child.once('error', reject);
|
child.once('error', reject);
|
||||||
child.once('exit', reject);
|
child.once('exit', reject);
|
||||||
child.once('spawn', resolve);
|
let stdout = '';
|
||||||
|
child.stdout.on('data', (data) => {
|
||||||
|
stdout += data;
|
||||||
|
});
|
||||||
|
child.once('exit', () => {
|
||||||
|
resolve(stdout);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
child.kill();
|
child.kill();
|
||||||
/* eslint-enable no-unreachable */
|
|
||||||
|
return JSON.parse(stdout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
import process from 'process';
|
import process from 'process';
|
||||||
import cp from 'child_process';
|
import {fork} from 'child_process';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
import {Platform, Result} from './types.js';
|
import {Platform, Result} from './types.js';
|
||||||
|
|
||||||
export default class PlatformNode implements Platform {
|
export default class PlatformNode implements Platform {
|
||||||
async run(ctx: Record<string, any>, file: string): Promise<Result> {
|
async run(ctx: Record<string, any>, file: string): Promise<Result> {
|
||||||
const child = cp.fork(
|
const child = fork(path.join(ctx.fixturesPath, 'index-node.js'), [file], {
|
||||||
path.join(process.cwd(), 'fixtures', 'index-node.js'),
|
cwd: ctx.fixturesPath,
|
||||||
[file],
|
});
|
||||||
);
|
|
||||||
const result: Result = await new Promise((resolve, reject) => {
|
const result: Result = await new Promise((resolve, reject) => {
|
||||||
child.once('error', reject);
|
child.once('error', reject);
|
||||||
child.once('exit', reject);
|
child.once('exit', reject);
|
||||||
|
|
|
@ -12,9 +12,9 @@ export class FixturesServer {
|
||||||
|
|
||||||
private server: net.Server | null = null;
|
private server: net.Server | null = null;
|
||||||
|
|
||||||
constructor() {
|
constructor(path: string) {
|
||||||
this.koa = new Koa();
|
this.koa = new Koa();
|
||||||
this.koa.use(files(path.join(process.cwd(), 'fixtures')));
|
this.koa.use(files(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
async start(): Promise<ServerAddress> {
|
async start(): Promise<ServerAddress> {
|
||||||
|
|
Loading…
Reference in New Issue