Ghost/ghost/zip/test/zip.test.js
Hannah Wolfe 7964f6ec82 Added dotfile support and set it on by default
refs https://github.com/TryGhost/Ghost/issues/11794

- archiver has an undocumented dot option, that allows you to include dotfiles
- our existing tests had a dotfile, but we didn't check properly that everything exists
- Swapped to using folder-hash to compare if the original, and compressed-then-decompressed folders are identical
- Added an example of a dotfolder with nested dotfile
- Updated compress to use the dot option, make it optional but on by default
2020-05-08 16:21:20 +01:00

67 lines
2.1 KiB
JavaScript

// Switch these lines once there are useful utils
// const testUtils = require('./utils');
require('./utils');
const path = require('path');
const fs = require('fs-extra');
const {hashElement} = require('folder-hash');
// Mimic how we expect this to be required
const {compress, extract} = require('../');
describe('Compress and Extract should be opposite functions', function () {
let symlinkPath, folderToSymlink, zipDestination, unzipDestination;
const cleanUp = () => {
fs.removeSync(symlinkPath);
fs.removeSync(zipDestination);
fs.removeSync(unzipDestination);
};
before(function () {
symlinkPath = path.join(__dirname, 'fixtures', 'theme-symlink');
folderToSymlink = path.join(__dirname, 'fixtures', 'test-theme');
zipDestination = path.join(__dirname, 'fixtures', 'theme-symlink.zip');
unzipDestination = path.join(__dirname, 'fixtures', 'theme-symlink-unzipped');
cleanUp();
});
after(function () {
cleanUp();
});
it('ensure symlinks work', function (done) {
fs.symlink(folderToSymlink, symlinkPath);
let originalHash;
hashElement(symlinkPath)
.then((_originalHash) => {
originalHash = _originalHash;
return compress(symlinkPath, zipDestination);
})
.then((res) => {
res.should.be.an.Object().with.properties('path', 'size');
res.path.should.eql(zipDestination);
res.size.should.eql(323805);
return extract(zipDestination, unzipDestination);
})
.then((res) => {
res.should.be.an.Object().with.properties('path');
res.path.should.eql(unzipDestination);
return hashElement(unzipDestination);
})
.then((extractedHash) => {
originalHash.children.toString().should.eql(extractedHash.children.toString());
done();
})
.catch((err) => {
return done(err);
});
});
});