Debian Codegraph @

testing/web-platform/tests/streams/resources/test-utils.js

raw
1 'use strict';
2
3 self.delay = ms => new Promise(resolve => step_timeout(resolve, ms));
4
5 // For tests which verify that the implementation doesn't do something it shouldn't, it's better not to use a
6 // timeout. Instead, assume that any reasonable implementation is going to finish work after 2 times around the event
7 // loop, and use flushAsyncEvents().then(() => assert_array_equals(...));
8 // Some tests include promise resolutions which may mean the test code takes a couple of event loop visits itself. So go
9 // around an extra 2 times to avoid complicating those tests.
10 self.flushAsyncEvents = () => delay(0).then(() => delay(0)).then(() => delay(0)).then(() => delay(0));
11
12 self.assert_typed_array_equals = (actual, expected, message) => {
13 const prefix = message === undefined ? '' : `${message} `;
14 assert_equals(typeof actual, 'object', `${prefix}type is object`);
15 assert_equals(actual.constructor, expected.constructor, `${prefix}constructor`);
16 assert_equals(actual.byteOffset, expected.byteOffset, `${prefix}byteOffset`);
17 assert_equals(actual.byteLength, expected.byteLength, `${prefix}byteLength`);
18 assert_equals(actual.buffer.byteLength, expected.buffer.byteLength, `${prefix}buffer.byteLength`);
19 assert_array_equals([...actual], [...expected], `${prefix}contents`);
20 assert_array_equals([...new Uint8Array(actual.buffer)], [...new Uint8Array(expected.buffer)], `${prefix}buffer contents`);
21 };
22
23 self.makePromiseAndResolveFunc = () => {
24 let resolve;
25 const promise = new Promise(r => { resolve = r; });
26 return [promise, resolve];
27 };