zip-a-folder
Advanced tools
Comparing version 0.0.10 to 0.0.11
@@ -8,2 +8,7 @@ 'use strict'; | ||
static async zip(srcFolder, zipFilePath) { | ||
const targetBasePath = path.dirname(zipFilePath); | ||
if (targetBasePath === srcFolder) { | ||
throw new Error('Source and target folder must be different.'); | ||
} | ||
return new Promise((resolve, reject) => { | ||
@@ -44,2 +49,2 @@ ZipAFolder.zipFolder(srcFolder, zipFilePath, err => { | ||
module.exports = ZipAFolder; | ||
module.exports = ZipAFolder; |
{ | ||
"name": "zip-a-folder", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"description": "Forked the idea of @sole to zip a complete folder into a zip file but now using promises", | ||
@@ -31,7 +31,7 @@ "main": "lib/zip-a-folder.js", | ||
"devDependencies": { | ||
"coveralls": "^3.0.6", | ||
"eslint-plugin-jest": "^22.15.2", | ||
"coveralls": "^3.0.9", | ||
"eslint-plugin-jest": "^22.21.0", | ||
"jest": "^24.9.0", | ||
"lodash": "^4.17.15", | ||
"prettier": "^1.18.2" | ||
"prettier": "^1.19.1" | ||
}, | ||
@@ -38,0 +38,0 @@ "dependencies": { |
@@ -1,56 +0,63 @@ | ||
"use strict"; | ||
'use strict'; | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const zipafolder = require("../lib/zip-a-folder"); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const zipafolder = require('../lib/zip-a-folder'); | ||
describe("Zip-A-Folder Test", function() { | ||
let testasync = path.resolve(__dirname, "testasync.zip"); | ||
let testcallback = path.resolve(__dirname, "testcallback.zip"); | ||
let testnotexisting = path.resolve(__dirname, "/notexisting/testcallback.zip"); | ||
describe('Zip-A-Folder Test', function() { | ||
let testasync = path.resolve(__dirname, 'testasync.zip'); | ||
let testasyncSameDirectory = path.resolve(__dirname, 'data/testasync.zip'); | ||
let testcallback = path.resolve(__dirname, 'testcallback.zip'); | ||
let testnotexisting = path.resolve(__dirname, '/notexisting/testcallback.zip'); | ||
beforeAll(() => { | ||
if (fs.existsSync(testasync)) { | ||
fs.unlinkSync(testasync); | ||
} | ||
if (fs.existsSync(testcallback)) { | ||
fs.unlinkSync(testcallback); | ||
} | ||
}); | ||
beforeAll(() => { | ||
if (fs.existsSync(testasync)) { | ||
fs.unlinkSync(testasync); | ||
} | ||
if (fs.existsSync(testasyncSameDirectory)) { | ||
fs.unlinkSync(testasyncSameDirectory); | ||
} | ||
if (fs.existsSync(testcallback)) { | ||
fs.unlinkSync(testcallback); | ||
} | ||
}); | ||
it("ASYNC: Zip test folder", async function() { | ||
expect.assertions(1); | ||
await zipafolder.zip(path.resolve(__dirname, "data/"), testasync); | ||
it('ASYNC: Zip test folder and zip target in same directory should throw an error', async () => { | ||
expect.assertions(1); | ||
await expect(zipafolder.zip(path.resolve(__dirname, 'data/'), testasyncSameDirectory)).rejects.toThrow( | ||
/Source and target folder must be different./ | ||
); | ||
}); | ||
expect(fs.existsSync(testasync)).toBe(true); | ||
}); | ||
it('ASYNC: Zip test folder', async () => { | ||
expect.assertions(1); | ||
await zipafolder.zip(path.resolve(__dirname, 'data/'), testasync); | ||
it("ASYNC: Zip test folder failing", async function() { | ||
expect.assertions(1); | ||
try { | ||
await zipafolder.zip(path.resolve(__dirname, "notexisting/"), testasync); | ||
} catch (e) { | ||
expect(e.message).toMatch(/no such file or directory/); | ||
} | ||
}); | ||
expect(fs.existsSync(testasync)).toBe(true); | ||
}); | ||
it("ASYNC: Zip test folder into a zipfile in a notexisting folder", async function() { | ||
expect.assertions(1); | ||
it('ASYNC: Zip test folder failing', async () => { | ||
expect.assertions(1); | ||
try { | ||
await zipafolder.zip(path.resolve(__dirname, 'notexisting/'), testasync); | ||
} catch (e) { | ||
expect(e.message).toMatch(/no such file or directory/); | ||
} | ||
}); | ||
try { | ||
await zipafolder.zip(path.resolve(__dirname, "data/"), testnotexisting); | ||
} catch (e) { | ||
expect(e.message).toMatch(/no such file or directory/); | ||
} | ||
}); | ||
it('ASYNC: Zip test folder into a zipfile in a notexisting folder', async () => { | ||
expect.assertions(1); | ||
it("CALLBACK: Zip test folder", function() { | ||
zipafolder.zipFolder( | ||
path.resolve(__dirname, "data/"), | ||
testcallback, | ||
() => { | ||
expect(fs.existsSync(testcallback)).toBe(true); | ||
} | ||
); | ||
}); | ||
try { | ||
await zipafolder.zip(path.resolve(__dirname, 'data/'), testnotexisting); | ||
} catch (e) { | ||
expect(e.message).toMatch(/no such file or directory/); | ||
} | ||
}); | ||
it('CALLBACK: Zip test folder', () => { | ||
zipafolder.zipFolder(path.resolve(__dirname, 'data/'), testcallback, () => { | ||
expect(fs.existsSync(testcallback)).toBe(true); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
6965
99