JSZip's browser/ESM support is tenuous, but it appears to support browserify.develop
parent
c8f566c2fe
commit
c0533dd3d6
@ -0,0 +1,16 @@
|
||||
import commonjs from 'rollup-plugin-commonjs'
|
||||
import nodeResolve from 'rollup-plugin-node-resolve'
|
||||
|
||||
export default {
|
||||
input: `./test/test.browser.js`,
|
||||
output: [
|
||||
{
|
||||
format: `iife`,
|
||||
name: `tests`,
|
||||
},
|
||||
],
|
||||
plugins: [
|
||||
nodeResolve(),
|
||||
commonjs(),
|
||||
],
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
const JSZip = require(`./jszip.js`)
|
||||
|
||||
module.exports = {
|
||||
loadJzip(data) {
|
||||
return new JSZip().loadAsync(data)
|
||||
},
|
||||
jzipToEntries(jzip) {
|
||||
const ary = []
|
||||
jzip.forEach((path, file) => ary.push({ path, file }))
|
||||
return ary
|
||||
},
|
||||
entriesToObject(entries) {
|
||||
return entries.reduce((acc, { path, file }) => {
|
||||
acc[path] = file
|
||||
return acc
|
||||
}, Object.create(null))
|
||||
},
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
const test = require(`zora`)
|
||||
const doNotZip = require(`../`)
|
||||
|
||||
test(`Creates a Blob in the browser`, t => {
|
||||
const outputBlob = doNotZip([
|
||||
{ path: `path/to/file1.txt`, data: `Hello` },
|
||||
{ path: `another/file2.txt`, data: `World` },
|
||||
])
|
||||
|
||||
t.ok(outputBlob instanceof Blob, `output is a Blob`)
|
||||
})
|
||||
|
||||
require(`./test.everywhere.js`)
|
@ -0,0 +1,20 @@
|
||||
const test = require(`zora`)
|
||||
const doNotZip = require(`../`)
|
||||
const { loadJzip, jzipToEntries, entriesToObject } = require(`./helper.js`)
|
||||
|
||||
test(`Creates a zip file that jszip can read`, async t => {
|
||||
const outputBlob = doNotZip([
|
||||
{ path: `path/to/file1.txt`, data: `Hello` },
|
||||
{ path: `another/file2.txt`, data: `World` },
|
||||
])
|
||||
const entries = jzipToEntries(await loadJzip(outputBlob))
|
||||
|
||||
const expectedPaths = [ `path/to/file1.txt`, `another/file2.txt` ]
|
||||
|
||||
t.equal(entries.length, expectedPaths.length)
|
||||
|
||||
const jzipMap = entriesToObject(entries)
|
||||
|
||||
expectedPaths.forEach(expectedPath => expectedPath in jzipMap)
|
||||
})
|
||||
|
@ -0,0 +1,13 @@
|
||||
const test = require(`zora`)
|
||||
const doNotZip = require(`../`)
|
||||
|
||||
test(`Creates a Buffer in node`, t => {
|
||||
const outputBlob = doNotZip([
|
||||
{ path: `path/to/file1.txt`, data: `Hello` },
|
||||
{ path: `another/file2.txt`, data: `World` },
|
||||
])
|
||||
|
||||
t.ok(outputBlob instanceof Buffer, `output is a Buffer`)
|
||||
})
|
||||
|
||||
require(`./test.everywhere.js`)
|
Loading…
Reference in new issue