test(cloudflare): provide TextEncoder and TextDecoder

jsdom/jsdom#2524
This commit is contained in:
Pooya Parsa 2021-09-22 22:31:58 +02:00
parent a0d2caf003
commit 201236195d

View File

@ -1,5 +1,6 @@
import { resolve } from 'path' import { resolve } from 'path'
import { promises as fsp } from 'fs' import { promises as fsp } from 'fs'
import { TextEncoder, TextDecoder } from 'util'
import { JSDOM } from 'jsdom' import { JSDOM } from 'jsdom'
import { setupTest, testNitroBehavior } from './_tests.mjs' import { setupTest, testNitroBehavior } from './_tests.mjs'
@ -42,12 +43,18 @@ describe('nitro:preset:cloudflare', () => {
} }
} }
</script> </script>
<script>${script}</script> <script>window._load = function() { ${script} }</script>
</body> </body>
</html>`, </html>`,
{ runScripts: 'dangerously' } { runScripts: 'dangerously' }
) )
// https://github.com/jsdom/jsdom/issues/2524
// https://github.com/inrupt/solid-client-authn-js/issues/1676#issuecomment-917016646
dom.window.TextEncoder = TextEncoder
dom.window.TextDecoder = TextDecoder
dom.window._load()
return async ({ url, headers, method, body }) => { return async ({ url, headers, method, body }) => {
const data = await dom.window.handleEvent({ const data = await dom.window.handleEvent({
request: { request: {