scratch-parser/test/integration/example.js
chrisgarrity 750e866444 fix(unzip): handle sb2 files zipped with a folder
Uses a pattern to find the sprite or project json in a zipped folder or flat list of files.

Added tests for
* loading a sprite or project with a nested folder
* loading a file without a json

Fixes 
2019-02-07 11:24:33 +01:00

74 lines
2.1 KiB
JavaScript

var test = require('tap').test;
var JSZip = require('jszip');
var data = require('../fixtures/data');
var parser = require('../../index');
test('sb', function (t) {
parser(data.example.sb, false, function (err, res) {
t.type(err, 'string');
t.type(res, 'undefined');
t.end();
});
});
test('sb2', function (t) {
parser(data.example.sb2, false, function (err, result) {
t.equal(err, null);
t.equal(Array.isArray(result), true);
var res = result[0];
var possibleZip = result[1];
t.type(res, 'object');
t.type(res.info, 'object');
t.equal(possibleZip instanceof JSZip, true);
t.end();
});
});
test('json', function (t) {
parser(data.example.json, false, function (err, result) {
t.equal(err, null);
t.equal(Array.isArray(result), true);
var res = result[0];
var possibleZip = result[1];
t.type(res, 'object');
t.type(res.info, 'object');
t.equal(possibleZip, null);
t.end();
});
});
test('json string', function (t) {
parser(data.example.json.toString('utf-8'), false, function (err, result) {
t.equal(err, null);
t.equal(Array.isArray(result), true);
var res = result[0];
var possibleZip = result[1];
t.type(res, 'object');
t.type(res.info, 'object');
t.equal(possibleZip, null);
t.end();
});
});
test('gzipped json', function (t) {
parser(data.example.gzipJson, false, function (err, result) {
t.equal(err, null);
t.equal(Array.isArray(result), true);
var res = result[0];
var possibleZip = result[1];
t.type(res, 'object');
t.type(res.info, 'object');
t.equal(possibleZip, null);
t.end();
});
});
test('invalid empty project archive', function (t) {
var msg = 'Failed to unzip and extract project.json, with error: ';
parser(data.example.invalidEmpty, false, function (err, result) {
t.type(err, 'string');
t.equal(err.startsWith(msg), true);
t.type(result, 'undefined');
t.end();
});
});