|
2 | 2 |
|
3 | 3 | const { tspl } = require('@matteo.collina/tspl') |
4 | 4 | const { test } = require('node:test') |
5 | | -const { markAsUncloneable } = require('node:worker_threads') |
6 | 5 | const { Response, Request, FormData, Headers, ErrorEvent, MessageEvent, CloseEvent, EventSource, WebSocket } = require('..') |
7 | 6 | const { CacheStorage } = require('../lib/web/cache/cachestorage') |
8 | 7 | const { Cache } = require('../lib/web/cache/cache') |
9 | 8 | const { kConstruct } = require('../lib/core/symbols') |
10 | 9 |
|
11 | | -test('unserializable web instances should be uncloneable if node exposes the api', (t) => { |
12 | | - if (markAsUncloneable !== undefined) { |
13 | | - t = tspl(t, { plan: 11 }) |
14 | | - const uncloneables = [ |
15 | | - { Uncloneable: Response, brand: 'Response' }, |
16 | | - { Uncloneable: Request, value: 'http://localhost', brand: 'Request' }, |
17 | | - { Uncloneable: FormData, brand: 'FormData' }, |
18 | | - { Uncloneable: MessageEvent, value: 'dummy event', brand: 'MessageEvent' }, |
19 | | - { Uncloneable: CloseEvent, value: 'dummy event', brand: 'CloseEvent' }, |
20 | | - { Uncloneable: ErrorEvent, value: 'dummy event', brand: 'ErrorEvent' }, |
21 | | - { Uncloneable: EventSource, value: 'http://localhost', brand: 'EventSource', doneCb: (entity) => entity.close() }, |
22 | | - { Uncloneable: Headers, brand: 'Headers' }, |
23 | | - { Uncloneable: WebSocket, value: 'http://localhost', brand: 'WebSocket' }, |
24 | | - { Uncloneable: Cache, value: kConstruct, brand: 'Cache' }, |
25 | | - { Uncloneable: CacheStorage, value: kConstruct, brand: 'CacheStorage' } |
26 | | - ] |
27 | | - uncloneables.forEach((platformEntity) => { |
28 | | - const entity = new platformEntity.Uncloneable(platformEntity.value) |
29 | | - t.throws(() => structuredClone(entity), |
30 | | - DOMException, |
31 | | - `Cloning ${platformEntity.brand} should throw DOMException`) |
| 10 | +test('unserializable web instances should be uncloneable', (t) => { |
| 11 | + t = tspl(t, { plan: 11 }) |
| 12 | + const uncloneables = [ |
| 13 | + { Uncloneable: Response, brand: 'Response' }, |
| 14 | + { Uncloneable: Request, value: 'http://localhost', brand: 'Request' }, |
| 15 | + { Uncloneable: FormData, brand: 'FormData' }, |
| 16 | + { Uncloneable: MessageEvent, value: 'dummy event', brand: 'MessageEvent' }, |
| 17 | + { Uncloneable: CloseEvent, value: 'dummy event', brand: 'CloseEvent' }, |
| 18 | + { Uncloneable: ErrorEvent, value: 'dummy event', brand: 'ErrorEvent' }, |
| 19 | + { Uncloneable: EventSource, value: 'http://localhost', brand: 'EventSource', doneCb: (entity) => entity.close() }, |
| 20 | + { Uncloneable: Headers, brand: 'Headers' }, |
| 21 | + { Uncloneable: WebSocket, value: 'http://localhost', brand: 'WebSocket' }, |
| 22 | + { Uncloneable: Cache, value: kConstruct, brand: 'Cache' }, |
| 23 | + { Uncloneable: CacheStorage, value: kConstruct, brand: 'CacheStorage' } |
| 24 | + ] |
| 25 | + uncloneables.forEach((platformEntity) => { |
| 26 | + const entity = new platformEntity.Uncloneable(platformEntity.value) |
| 27 | + t.throws(() => structuredClone(entity), |
| 28 | + DOMException, |
| 29 | + `Cloning ${platformEntity.brand} should throw DOMException`) |
32 | 30 |
|
33 | | - platformEntity.doneCb?.(entity) |
34 | | - }) |
35 | | - } |
| 31 | + platformEntity.doneCb?.(entity) |
| 32 | + }) |
36 | 33 | }) |
0 commit comments