Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Ib Green committed Sep 27, 2019
1 parent 3b64a97 commit 7c5d107
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion modules/images/test/image-writer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import path from 'path';
// import mkdirp from 'mkdirp';
// const TEST_DIR = path.join(__dirname, '..', 'data');

const TEST_FILE = path.join(__dirname, '../data/test.png');
const TEST_FILE = path.join(__dirname, '../test/data/test.png');

const IMAGE = {
width: 2,
Expand Down
42 changes: 24 additions & 18 deletions modules/polyfills/test/fetch-node/decode-data-uri.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// This code is based on binary-gltf-utils
// Copyright (c) 2016-17 Karl Cheng, MIT license

/* eslint-disable max-len, max-statements */
/* global Buffer */
/* global TextDecoder */
import test from 'tape-promise/tape';
import {isBrowser} from '@loaders.gl/core';
import decodeDataUri from '@loaders.gl/polyfills/fetch-node/utils/decode-data-uri.node';

const toString = arrayBuffer => new TextDecoder().decode(arrayBuffer);

// eslint-disable-next-line max-statements
test('decodeDataUri', t => {
if (isBrowser) {
t.comment('decodeDataUri() currently only works in Node.js');
Expand All @@ -15,32 +17,32 @@ test('decodeDataUri', t => {
}

let obj;
let buf;
let arrayBuffer;

obj = decodeDataUri('data:text/html;base64,PGh0bWw+');
t.equals(obj.mimeType, 'text/html', 'should record down correct MIME type');

obj = decodeDataUri('data:text/plain;base64,SSBsb3ZlIHlvdSE');
buf = obj.buffer;
t.ok(Buffer.isBuffer(buf));
t.equals(buf.toString(), 'I love you!', 'should work with non-padded base64 data URIs');
arrayBuffer = obj.arrayBuffer;
t.ok(arrayBuffer instanceof ArrayBuffer);
t.equals(toString(arrayBuffer), 'I love you!', 'should work with non-padded base64 data URIs');

obj = decodeDataUri('data:text/plain;base64,SSBsb3ZlIHlvdSE=');
buf = obj.buffer;
t.ok(Buffer.isBuffer(buf));
t.equals(buf.toString(), 'I love you!', 'should work with padded base64 data URIs');
arrayBuffer = obj.arrayBuffer;
t.ok(arrayBuffer instanceof ArrayBuffer);
t.equals(toString(arrayBuffer), 'I love you!', 'should work with padded base64 data URIs');

obj = decodeDataUri('data:text/plain,important content!');
buf = obj.buffer;
t.ok(Buffer.isBuffer(buf));
t.equals(buf.toString(), 'important content!', 'should work with plain data URIs');
arrayBuffer = obj.arrayBuffer;
t.ok(arrayBuffer instanceof ArrayBuffer);
t.equals(toString(arrayBuffer), 'important content!', 'should work with plain data URIs');

obj = decodeDataUri('data:,important content!');
t.equals(obj.mimeType, 'text/plain;charset=US-ASCII', 'should set default MIME type');

buf = obj.buffer;
t.ok(Buffer.isBuffer(buf));
t.equals(buf.toString(), 'important content!', 'should work with default MIME type');
arrayBuffer = obj.arrayBuffer;
t.ok(arrayBuffer instanceof ArrayBuffer);
t.equals(toString(arrayBuffer), 'important content!', 'should work with default MIME type');

obj = decodeDataUri('data:;charset=utf-8,important content!');
t.equals(
Expand All @@ -49,9 +51,13 @@ test('decodeDataUri', t => {
'should allow implicit text/plain with charset'
);

buf = obj.buffer;
t.ok(Buffer.isBuffer(buf));
t.equals(buf.toString(), 'important content!', 'should allow implicit text/plain with charset');
arrayBuffer = obj.arrayBuffer;
t.ok(arrayBuffer instanceof ArrayBuffer);
t.equals(
toString(arrayBuffer),
'important content!',
'should allow implicit text/plain with charset'
);

t.end();
});

0 comments on commit 7c5d107

Please sign in to comment.