Browse Source

Adding tests for browser and node

JSZip's browser/ESM support is tenuous, but it appears to support browserify.
develop
Josh Duff 2 years ago
parent
commit
c0533dd3d6
7 changed files with 96 additions and 3 deletions
  1. +1
    -0
      .gitignore
  2. +15
    -3
      package.json
  3. +16
    -0
      rollup.config.test.js
  4. +18
    -0
      test/helper.js
  5. +13
    -0
      test/test.browser.js
  6. +20
    -0
      test/test.everywhere.js
  7. +13
    -0
      test/test.node.js

+ 1
- 0
.gitignore View File

@ -3,3 +3,4 @@
/package-lock.json
/shrinkwrap.yaml
/yarn.lock
test/jszip.js

+ 15
- 3
package.json View File

@ -24,9 +24,21 @@
},
"homepage": "https://cndtr.io/do-not-zip/",
"devDependencies": {
"rollup": "*"
"browserify": "16.2.0",
"jszip": "3.1.5",
"rollup": "*",
"rollup-plugin-commonjs": "9.1.0",
"rollup-plugin-node-resolve": "3.3.0",
"tap-colorize": "1.2.0",
"tape-run": "4.0.0",
"zora": "2.0.1"
},
"scripts": {
"build": "rollup -c"
}
"build": "rollup -c",
"build:jszip": "browserify -s jszip node_modules/jszip/lib/index.js > test/jszip.js",
"test:browser": "npm run build:jszip && rollup -c rollup.config.test.js | tape-run | tap-colorize",
"test:node": "node test/test.node.js | tap-colorize",
"test": "npm run build && npm run test:node && npm run test:browser"
},
"dependencies": {}
}

+ 16
- 0
rollup.config.test.js View File

@ -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(),
],
}

+ 18
- 0
test/helper.js View File

@ -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))
},
}

+ 13
- 0
test/test.browser.js View File

@ -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`)

+ 20
- 0
test/test.everywhere.js View File

@ -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)
})

+ 13
- 0
test/test.node.js View File

@ -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…
Cancel
Save