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');
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
fs.symlink(folderToSymlink, symlinkPath);
|
|
|
|
|
2020-04-07 11:53:28 +03:00
|
|
|
compress(symlinkPath, zipDestination)
|
|
|
|
.then((res) => {
|
|
|
|
res.should.be.an.Object().with.properties('path', 'size');
|
|
|
|
res.path.should.eql(zipDestination);
|
|
|
|
res.size.should.eql(321775);
|
|
|
|
|
|
|
|
extract(zipDestination, unzipDestination)
|
|
|
|
.then((res) => {
|
|
|
|
res.should.be.an.Object().with.properties('path');
|
|
|
|
res.path.should.eql(unzipDestination);
|
|
|
|
|
2020-04-07 11:26:01 +03:00
|
|
|
fs.readdir(unzipDestination, function (err, files) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
files.length.should.eql(16);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
2017-12-15 00:07:53 +03:00
|
|
|
return done(err);
|
2020-04-07 11:26:01 +03:00
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
return done(err);
|
2017-12-15 00:07:53 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|