mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 20:03:12 +03:00
3db4f8d331
- All var declarations are now const or let as per ES6 - All comma-separated lists / chained declarations are now one declaration per line - This is for clarity/readability but also made running the var-to-const/let switch smoother - ESLint rules updated to match How this was done: - npm install -g jscodeshift - git clone https://github.com/cpojer/js-codemod.git - git clone git@github.com:TryGhost/Ghost.git shallow-ghost - cd shallow-ghost - jscodeshift -t ../js-codemod/transforms/unchain-variables.js . -v=2 - jscodeshift -t ../js-codemod/transforms/no-vars.js . -v=2 - yarn - yarn test - yarn lint / fix various lint errors (almost all indent) by opening files and saving in vscode - grunt test-regression - sorted!
264 lines
9.7 KiB
JavaScript
264 lines
9.7 KiB
JavaScript
const should = require('should');
|
|
const tmp = require('tmp');
|
|
const join = require('path').join;
|
|
const fs = require('fs-extra');
|
|
const packageJSON = require('../../../../../core/server/lib/fs/package-json');
|
|
|
|
describe('lib/fs/package-json: read', function () {
|
|
describe('all', function () {
|
|
it('should read directory and ignore unneeded items', function (done) {
|
|
const packagePath = tmp.dirSync({unsafeCleanup: true});
|
|
|
|
// create example theme
|
|
fs.mkdirSync(join(packagePath.name, 'casper'));
|
|
fs.writeFileSync(join(packagePath.name, 'casper', 'index.hbs'));
|
|
|
|
// create some trash
|
|
fs.mkdirSync(join(packagePath.name, 'node_modules'));
|
|
fs.mkdirSync(join(packagePath.name, 'bower_components'));
|
|
fs.mkdirSync(join(packagePath.name, '.git'));
|
|
fs.writeFileSync(join(packagePath.name, '.DS_Store'));
|
|
|
|
packageJSON.read.all(packagePath.name)
|
|
.then(function (pkgs) {
|
|
pkgs.should.eql({
|
|
casper: {
|
|
name: 'casper',
|
|
path: join(packagePath.name, 'casper'),
|
|
'package.json': null
|
|
}
|
|
});
|
|
|
|
done();
|
|
})
|
|
.catch(done)
|
|
.finally(packagePath.removeCallback);
|
|
});
|
|
|
|
it('should read directory and parse package.json files', function (done) {
|
|
let packagePath;
|
|
let pkgJson;
|
|
|
|
packagePath = tmp.dirSync({unsafeCleanup: true});
|
|
pkgJson = JSON.stringify({
|
|
name: 'test',
|
|
version: '0.0.0'
|
|
});
|
|
|
|
// create example theme
|
|
fs.mkdirSync(join(packagePath.name, 'testtheme'));
|
|
fs.writeFileSync(join(packagePath.name, 'testtheme', 'package.json'), pkgJson);
|
|
fs.writeFileSync(join(packagePath.name, 'testtheme', 'index.hbs'));
|
|
|
|
packageJSON.read.all(packagePath.name)
|
|
.then(function (pkgs) {
|
|
pkgs.should.eql({
|
|
testtheme: {
|
|
name: 'testtheme',
|
|
path: join(packagePath.name, 'testtheme'),
|
|
'package.json': {
|
|
name: 'test',
|
|
version: '0.0.0'
|
|
}
|
|
}
|
|
});
|
|
|
|
done();
|
|
})
|
|
.catch(done)
|
|
.finally(packagePath.removeCallback);
|
|
});
|
|
|
|
it('should read directory and ignore invalid package.json files', function (done) {
|
|
let packagePath;
|
|
let pkgJson;
|
|
|
|
packagePath = tmp.dirSync({unsafeCleanup: true});
|
|
pkgJson = JSON.stringify({
|
|
name: 'test'
|
|
});
|
|
|
|
// create example theme
|
|
fs.mkdirSync(join(packagePath.name, 'testtheme'));
|
|
fs.writeFileSync(join(packagePath.name, 'testtheme', 'package.json'), pkgJson);
|
|
fs.writeFileSync(join(packagePath.name, 'testtheme', 'index.hbs'));
|
|
|
|
packageJSON.read.all(packagePath.name)
|
|
.then(function (pkgs) {
|
|
pkgs.should.eql({
|
|
testtheme: {
|
|
name: 'testtheme',
|
|
path: join(packagePath.name, 'testtheme'),
|
|
'package.json': null
|
|
}
|
|
});
|
|
|
|
done();
|
|
})
|
|
.catch(done)
|
|
.finally(packagePath.removeCallback);
|
|
});
|
|
});
|
|
|
|
describe('one', function () {
|
|
it('should read directory and ignore unneeded items', function (done) {
|
|
const packagePath = tmp.dirSync({unsafeCleanup: true});
|
|
|
|
// create example theme
|
|
fs.mkdirSync(join(packagePath.name, 'casper'));
|
|
fs.writeFileSync(join(packagePath.name, 'casper', 'index.hbs'));
|
|
|
|
// create some trash
|
|
fs.mkdirSync(join(packagePath.name, 'node_modules'));
|
|
fs.mkdirSync(join(packagePath.name, 'bower_components'));
|
|
fs.mkdirSync(join(packagePath.name, '.git'));
|
|
fs.writeFileSync(join(packagePath.name, '.DS_Store'));
|
|
|
|
packageJSON.read.one(packagePath.name, 'casper')
|
|
.then(function (pkgs) {
|
|
pkgs.should.eql({
|
|
casper: {
|
|
name: 'casper',
|
|
path: join(packagePath.name, 'casper'),
|
|
'package.json': null
|
|
}
|
|
});
|
|
|
|
done();
|
|
})
|
|
.catch(done)
|
|
.finally(packagePath.removeCallback);
|
|
});
|
|
|
|
it('should read directory and parse package.json files', function (done) {
|
|
let packagePath;
|
|
let pkgJson;
|
|
|
|
packagePath = tmp.dirSync({unsafeCleanup: true});
|
|
pkgJson = JSON.stringify({
|
|
name: 'test',
|
|
version: '0.0.0'
|
|
});
|
|
|
|
// create example theme
|
|
fs.mkdirSync(join(packagePath.name, 'testtheme'));
|
|
fs.writeFileSync(join(packagePath.name, 'testtheme', 'package.json'), pkgJson);
|
|
fs.writeFileSync(join(packagePath.name, 'testtheme', 'index.hbs'));
|
|
|
|
packageJSON.read.one(packagePath.name, 'testtheme')
|
|
.then(function (pkgs) {
|
|
pkgs.should.eql({
|
|
testtheme: {
|
|
name: 'testtheme',
|
|
path: join(packagePath.name, 'testtheme'),
|
|
'package.json': {
|
|
name: 'test',
|
|
version: '0.0.0'
|
|
}
|
|
}
|
|
});
|
|
|
|
done();
|
|
})
|
|
.catch(done)
|
|
.finally(packagePath.removeCallback);
|
|
});
|
|
|
|
it('should read directory and ignore invalid package.json files', function (done) {
|
|
let packagePath;
|
|
let pkgJson;
|
|
|
|
packagePath = tmp.dirSync({unsafeCleanup: true});
|
|
pkgJson = JSON.stringify({
|
|
name: 'test'
|
|
});
|
|
|
|
// create example theme
|
|
fs.mkdirSync(join(packagePath.name, 'testtheme'));
|
|
fs.writeFileSync(join(packagePath.name, 'testtheme', 'package.json'), pkgJson);
|
|
fs.writeFileSync(join(packagePath.name, 'testtheme', 'index.hbs'));
|
|
|
|
packageJSON.read.one(packagePath.name, 'testtheme')
|
|
.then(function (pkgs) {
|
|
pkgs.should.eql({
|
|
testtheme: {
|
|
name: 'testtheme',
|
|
path: join(packagePath.name, 'testtheme'),
|
|
'package.json': null
|
|
}
|
|
});
|
|
|
|
done();
|
|
})
|
|
.catch(done)
|
|
.finally(packagePath.removeCallback);
|
|
});
|
|
|
|
it('should read directory and include only single requested package', function (done) {
|
|
const packagePath = tmp.dirSync({unsafeCleanup: true});
|
|
|
|
// create trash
|
|
fs.writeFileSync(join(packagePath.name, 'casper.zip'));
|
|
fs.writeFileSync(join(packagePath.name, '.DS_Store'));
|
|
|
|
// create actual theme
|
|
fs.mkdirSync(join(packagePath.name, 'casper'));
|
|
fs.mkdirSync(join(packagePath.name, 'casper', 'partials'));
|
|
fs.writeFileSync(join(packagePath.name, 'casper', 'index.hbs'));
|
|
fs.writeFileSync(join(packagePath.name, 'casper', 'partials', 'navigation.hbs'));
|
|
fs.mkdirSync(join(packagePath.name, 'not-casper'));
|
|
fs.writeFileSync(join(packagePath.name, 'not-casper', 'index.hbs'));
|
|
|
|
packageJSON.read.one(packagePath.name, 'casper')
|
|
.then(function (pkgs) {
|
|
pkgs.should.eql({
|
|
casper: {
|
|
name: 'casper',
|
|
path: join(packagePath.name, 'casper'),
|
|
'package.json': null
|
|
}
|
|
});
|
|
|
|
done();
|
|
})
|
|
.catch(done)
|
|
.finally(packagePath.removeCallback);
|
|
});
|
|
|
|
it('should return an error if package cannot be found', function (done) {
|
|
const packagePath = tmp.dirSync({unsafeCleanup: true});
|
|
|
|
// create trash
|
|
fs.writeFileSync(join(packagePath.name, 'casper.zip'));
|
|
fs.writeFileSync(join(packagePath.name, '.DS_Store'));
|
|
|
|
packageJSON.read.one(packagePath.name, 'casper')
|
|
.then(function () {
|
|
done('Should have thrown an error');
|
|
})
|
|
.catch(function (err) {
|
|
err.message.should.eql('Package not found');
|
|
done();
|
|
})
|
|
.finally(packagePath.removeCallback);
|
|
});
|
|
|
|
it('should return empty object if package is not a directory', function (done) {
|
|
const packagePath = tmp.dirSync({unsafeCleanup: true});
|
|
|
|
// create trash
|
|
fs.writeFileSync(join(packagePath.name, 'casper.zip'));
|
|
fs.writeFileSync(join(packagePath.name, '.DS_Store'));
|
|
|
|
packageJSON.read.one(packagePath.name, 'casper.zip')
|
|
.then(function (pkg) {
|
|
pkg.should.eql({});
|
|
|
|
done();
|
|
})
|
|
.catch(done)
|
|
.finally(packagePath.removeCallback);
|
|
});
|
|
});
|
|
});
|