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!
125 lines
3.9 KiB
JavaScript
125 lines
3.9 KiB
JavaScript
const should = require('should');
|
|
const tmp = require('tmp');
|
|
const fs = require('fs-extra');
|
|
const packageJSON = require('../../../../../core/server/lib/fs/package-json');
|
|
|
|
describe('lib/fs/package-json: parse', function () {
|
|
it('should parse valid package.json', function (done) {
|
|
let pkgJson;
|
|
let tmpFile;
|
|
|
|
tmpFile = tmp.fileSync();
|
|
pkgJson = JSON.stringify({
|
|
name: 'test',
|
|
version: '0.0.0'
|
|
});
|
|
|
|
fs.writeSync(tmpFile.fd, pkgJson);
|
|
|
|
packageJSON.parse(tmpFile.name)
|
|
.then(function (pkg) {
|
|
pkg.should.eql({
|
|
name: 'test',
|
|
version: '0.0.0'
|
|
});
|
|
|
|
done();
|
|
})
|
|
.catch(done)
|
|
.finally(tmpFile.removeCallback);
|
|
});
|
|
|
|
it('should fail when name is missing', function (done) {
|
|
let pkgJson;
|
|
let tmpFile;
|
|
|
|
tmpFile = tmp.fileSync();
|
|
pkgJson = JSON.stringify({
|
|
version: '0.0.0'
|
|
});
|
|
|
|
fs.writeSync(tmpFile.fd, pkgJson);
|
|
|
|
packageJSON.parse(tmpFile.name)
|
|
.then(function () {
|
|
done(new Error('packageJSON.parse succeeded, but should\'ve failed'));
|
|
})
|
|
.catch(function (err) {
|
|
err.message.should.equal('"name" or "version" is missing from theme package.json file.');
|
|
err.context.should.equal(tmpFile.name);
|
|
err.help.should.equal('This will be required in future. Please see https://ghost.org/docs/api/handlebars-themes/');
|
|
|
|
done();
|
|
})
|
|
.catch(done)
|
|
.finally(tmpFile.removeCallback);
|
|
});
|
|
|
|
it('should fail when version is missing', function (done) {
|
|
let pkgJson;
|
|
let tmpFile;
|
|
|
|
tmpFile = tmp.fileSync();
|
|
pkgJson = JSON.stringify({
|
|
name: 'test'
|
|
});
|
|
|
|
fs.writeSync(tmpFile.fd, pkgJson);
|
|
|
|
packageJSON.parse(tmpFile.name)
|
|
.then(function () {
|
|
done(new Error('packageJSON.parse succeeded, but should\'ve failed'));
|
|
})
|
|
.catch(function (err) {
|
|
err.message.should.equal('"name" or "version" is missing from theme package.json file.');
|
|
err.context.should.equal(tmpFile.name);
|
|
err.help.should.equal('This will be required in future. Please see https://ghost.org/docs/api/handlebars-themes/');
|
|
|
|
done();
|
|
})
|
|
.catch(done)
|
|
.finally(tmpFile.removeCallback);
|
|
});
|
|
|
|
it('should fail when JSON is invalid', function (done) {
|
|
let pkgJson;
|
|
let tmpFile;
|
|
|
|
tmpFile = tmp.fileSync();
|
|
pkgJson = '{name:"test"}';
|
|
|
|
fs.writeSync(tmpFile.fd, pkgJson);
|
|
|
|
packageJSON.parse(tmpFile.name)
|
|
.then(function () {
|
|
done(new Error('packageJSON.parse succeeded, but should\'ve failed'));
|
|
})
|
|
.catch(function (err) {
|
|
err.message.should.equal('Theme package.json file is malformed');
|
|
err.context.should.equal(tmpFile.name);
|
|
err.help.should.equal('This will be required in future. Please see https://ghost.org/docs/api/handlebars-themes/');
|
|
|
|
done();
|
|
})
|
|
.catch(done)
|
|
.finally(tmpFile.removeCallback);
|
|
});
|
|
|
|
it('should fail when file is missing', function (done) {
|
|
const tmpFile = tmp.fileSync();
|
|
|
|
tmpFile.removeCallback();
|
|
packageJSON.parse(tmpFile.name)
|
|
.then(function () {
|
|
done(new Error('packageJSON.parse succeeded, but should\'ve failed'));
|
|
})
|
|
.catch(function (err) {
|
|
err.message.should.equal('Could not read package.json file');
|
|
err.context.should.equal(tmpFile.name);
|
|
|
|
done();
|
|
})
|
|
.catch(done);
|
|
});
|
|
});
|