2020-03-20 19:35:13 +03:00
|
|
|
// Switch these lines once there are useful utils
|
|
|
|
// const testUtils = require('./utils');
|
|
|
|
require('./utils');
|
|
|
|
|
|
|
|
const path = require('path');
|
|
|
|
const fs = require('fs-extra');
|
2020-05-08 18:15:02 +03:00
|
|
|
const {hashElement} = require('folder-hash');
|
2020-03-20 19:35:13 +03:00
|
|
|
|
|
|
|
// Mimic how we expect this to be required
|
2020-04-07 11:53:28 +03:00
|
|
|
const {compress, extract} = require('../');
|
2017-12-15 00:07:53 +03:00
|
|
|
|
2020-04-07 11:53:28 +03:00
|
|
|
describe('Compress and Extract should be opposite functions', function () {
|
2020-03-20 19:35:13 +03:00
|
|
|
let symlinkPath, folderToSymlink, zipDestination, unzipDestination;
|
2017-12-15 00:07:53 +03:00
|
|
|
|
2020-03-20 22:59:15 +03:00
|
|
|
const cleanUp = () => {
|
|
|
|
fs.removeSync(symlinkPath);
|
|
|
|
fs.removeSync(zipDestination);
|
|
|
|
fs.removeSync(unzipDestination);
|
|
|
|
};
|
|
|
|
|
2017-12-15 00:07:53 +03:00
|
|
|
before(function () {
|
2020-03-20 19:35:13 +03:00
|
|
|
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');
|
|
|
|
|
2020-03-20 22:59:15 +03:00
|
|
|
cleanUp();
|
2017-12-15 00:07:53 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
2020-03-20 22:59:15 +03:00
|
|
|
cleanUp();
|
2017-12-15 00:07:53 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('ensure symlinks work', function (done) {
|
2020-11-10 13:48:25 +03:00
|
|
|
fs.symlinkSync(folderToSymlink, symlinkPath);
|
2017-12-15 00:07:53 +03:00
|
|
|
|
2020-05-08 18:15:02 +03:00
|
|
|
let originalHash;
|
|
|
|
|
|
|
|
hashElement(symlinkPath)
|
|
|
|
.then((_originalHash) => {
|
|
|
|
originalHash = _originalHash;
|
|
|
|
return compress(symlinkPath, zipDestination);
|
|
|
|
})
|
2020-04-07 11:53:28 +03:00
|
|
|
.then((res) => {
|
|
|
|
res.should.be.an.Object().with.properties('path', 'size');
|
|
|
|
res.path.should.eql(zipDestination);
|
2020-08-04 15:01:52 +03:00
|
|
|
res.size.should.be.below(619618);
|
2020-04-07 11:53:28 +03:00
|
|
|
|
2020-05-08 18:15:02 +03:00
|
|
|
return extract(zipDestination, unzipDestination);
|
|
|
|
})
|
|
|
|
.then((res) => {
|
|
|
|
res.should.be.an.Object().with.properties('path');
|
|
|
|
res.path.should.eql(unzipDestination);
|
2020-04-07 11:53:28 +03:00
|
|
|
|
2020-05-08 18:15:02 +03:00
|
|
|
return hashElement(unzipDestination);
|
|
|
|
})
|
|
|
|
.then((extractedHash) => {
|
|
|
|
originalHash.children.toString().should.eql(extractedHash.children.toString());
|
2020-04-07 11:26:01 +03:00
|
|
|
|
2020-05-08 18:15:02 +03:00
|
|
|
done();
|
2020-04-07 11:26:01 +03:00
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
return done(err);
|
2017-12-15 00:07:53 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|