mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 11:22:19 +03:00
8d9e26cb83
- we don't provide a callback for this so we want it synchronous but `symlink` is async. Switching to `symlinkSync` should now fix the flaky tests
67 lines
2.1 KiB
JavaScript
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.symlinkSync(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.be.below(619618);
|
|
|
|
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);
|
|
});
|
|
});
|
|
});
|