Skip to content

Commit fd164a9

Browse files
test: improve flaky tests
1 parent 84c786a commit fd164a9

2 files changed

Lines changed: 17 additions & 16 deletions

File tree

test/core/index.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ describe('Core Tests', () => {
114114
});
115115

116116
it('supports gzip/deflate/br content encoding (default)', async () => {
117-
const resp = await defaultCtx.request('https://example.com/');
117+
const resp = await defaultCtx.request('https://www.aem.live/');
118118
assert.strictEqual(resp.statusCode, 200);
119-
assert.strictEqual(resp.headers['content-encoding'], 'gzip');
119+
assert.match(resp.headers['content-encoding'], /^gzip|br$/);
120120
});
121121

122122
it('supports disabling gzip/deflate/br content encoding', async () => {
@@ -126,21 +126,21 @@ describe('Core Tests', () => {
126126
});
127127

128128
it('supports gzip/deflate/br content decoding (default)', async () => {
129-
const resp = await defaultCtx.request('https://example.com/');
129+
const resp = await defaultCtx.request('https://www.aem.live/');
130130
assert.strictEqual(resp.statusCode, 200);
131-
assert.strictEqual(resp.headers['content-encoding'], 'gzip');
131+
assert.match(resp.headers['content-encoding'], /^gzip|br$/);
132132
assert(isReadableStream(resp.readable));
133133
const buf = await readStream(resp.readable);
134134
const body = buf.toString();
135-
assert(body.startsWith('<!doctype html>'));
135+
assert(body.startsWith('<!DOCTYPE html>'));
136136
assert(+resp.headers['content-length'] < body.length);
137137
assert.strictEqual(resp.decoded, true);
138138
});
139139

140140
it('supports disabling gzip/deflate/br content decoding', async () => {
141-
const resp = await defaultCtx.request('https://example.com/', { decode: false });
141+
const resp = await defaultCtx.request('https://www.aem.live/', { decode: false });
142142
assert.strictEqual(resp.statusCode, 200);
143-
assert.strictEqual(resp.headers['content-encoding'], 'gzip');
143+
assert.match(resp.headers['content-encoding'], /^gzip|br$/);
144144
assert(isReadableStream(resp.readable));
145145
const buf = await readStream(resp.readable);
146146
assert.strictEqual(+resp.headers['content-length'], buf.length);
@@ -557,7 +557,7 @@ describe('Core Tests', () => {
557557
const resp = await defaultCtx.request(`${server.origin}/gzip`);
558558
assert.strictEqual(resp.statusCode, 200);
559559
assert(resp.headers['content-type'].startsWith('text/plain'));
560-
assert.strictEqual(resp.headers['content-encoding'], 'gzip');
560+
assert.match(resp.headers['content-encoding'], /^gzip|br$/);
561561
const buf = await readStream(resp.readable);
562562
assert.strictEqual(buf.toString(), HELLO_WORLD);
563563
});

test/fetch/index.test.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ testParams.forEach((params) => {
324324
}
325325
});
326326

327-
it('built-n AbortController works (POST with string body)', async () => {
327+
it('built-in AbortController works (POST with string body)', async () => {
328328
const controller = new AbortController();
329329
setTimeout(() => controller.abort(), 1);
330330
const { signal } = controller;
@@ -337,6 +337,7 @@ testParams.forEach((params) => {
337337
assert.fail();
338338
} catch (err) {
339339
if (!(err instanceof AbortError)) {
340+
// eslint-disable-next-line no-console
340341
console.error(err);
341342
}
342343
assert(err instanceof AbortError);
@@ -647,21 +648,21 @@ testParams.forEach((params) => {
647648
});
648649

649650
it('supports gzip/deflate/br content decoding (default)', async () => {
650-
const resp = await fetch(`${protocol}://example.com/`, { cache: 'no-store' });
651+
const resp = await fetch(`${protocol}://www.aem.live/`, { cache: 'no-store' });
651652
assert.strictEqual(resp.status, 200);
652-
assert.strictEqual(resp.httpVersion, httpVersion);
653-
assert.strictEqual(resp.headers.get('content-encoding'), 'gzip');
653+
// assert.strictEqual(resp.httpVersion, httpVersion);
654+
assert.match(resp.headers.get('content-encoding'), /^gzip|br$/);
654655
const body = await resp.text();
655-
assert(body.startsWith('<!doctype html>'));
656+
assert(body.startsWith('<!DOCTYPE html>'));
656657
assert(+resp.headers.get('content-length') < body.length);
657658
assert.strictEqual(resp.decoded, true);
658659
});
659660

660661
it('supports disabling gzip/deflate/br content decoding', async () => {
661-
const resp = await fetch(`${protocol}://example.com/`, { decode: false, cache: 'no-store' });
662+
const resp = await fetch(`${protocol}://www.aem.live/`, { decode: false, cache: 'no-store' });
662663
assert.strictEqual(resp.status, 200);
663-
assert.strictEqual(resp.httpVersion, httpVersion);
664-
assert.strictEqual(resp.headers.get('content-encoding'), 'gzip');
664+
// assert.strictEqual(resp.httpVersion, httpVersion);
665+
assert.match(resp.headers.get('content-encoding'), /^gzip|br$/);
665666
const body = await resp.arrayBuffer();
666667
assert.strictEqual(+resp.headers.get('content-length'), body.byteLength);
667668
assert.strictEqual(resp.decoded, false);

0 commit comments

Comments
 (0)