Skip to content

Commit

Permalink
moar test
Browse files Browse the repository at this point in the history
  • Loading branch information
samthor committed Aug 30, 2022
1 parent 3d02da9 commit b344268
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export async function tests(isNative, TextEncoder, TextDecoder) {
await test('arraylike', () => {
const arr = [104, 101, 108, 108, 111];

if (isNative) {
if (NativeTextEncoder === TextEncoder) {
// Native can't take Array.
assert.throws(() => dec.decode(arr));
} else {
Expand Down Expand Up @@ -110,7 +110,7 @@ export async function tests(isNative, TextEncoder, TextDecoder) {

// Since this is being run in Node, this should work.
await test('nodejs encodings', () => {
if (typeof window === 'undefined') {
if (typeof window === 'undefined' && isNative) {
new TextDecoder('utf-16le');
} else {
assert.throws(() => {
Expand Down Expand Up @@ -173,11 +173,6 @@ export async function tests(isNative, TextEncoder, TextDecoder) {
}


await tests(true, NativeTextEncoder, NativeTextDecoder);
await tests(false, TextEncoder, TextDecoder);



await test('always lowlevel', () => {
const src = 'hello there ƒåcé zing';

Expand All @@ -187,3 +182,20 @@ await test('always lowlevel', () => {
assert.equal(src, out);
});




await tests(true, NativeTextEncoder, NativeTextDecoder);
await tests(true, TextEncoder, TextDecoder);

const originalBufferFrom = Buffer.from;
let d;
try {
globalThis.scope = {};
Buffer.from = null;
d = await import('./src/polyfill.js');
console.warn('got Buffer.from', Buffer.from);
} finally {
Buffer.from = originalBufferFrom;
}
await tests(false, globalThis.scope.TextEncoder, globalThis.scope.TextDecoder);

0 comments on commit b344268

Please sign in to comment.