Skip to content

Commit

Permalink
test: behaviour when package.json is missing
Browse files Browse the repository at this point in the history
This was somewhat undocumented, so this is much needed. The primary
feature of this is that it uses the directory name as the package name
when there is no package.json.
  • Loading branch information
rmg committed Jan 30, 2017
1 parent 8746cb9 commit 913c92b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/project.js
Expand Up @@ -52,7 +52,6 @@ function Project(pkgPath, cb) {
try {
this.rawPkgJSON = JSON.parse(fs.readFileSync(this.pkgJSONPath, 'utf8'));
} catch (e) {
console.error('Could not read package:', e);
this.rawPkgJSON = {};
}

Expand Down
11 changes: 11 additions & 0 deletions test/test-project.js
Expand Up @@ -7,7 +7,9 @@

var fs = require('fs');
var helpers = require('./helpers');
var mkdirp = require('mkdirp');
var path = require('path');
var rimraf = require('rimraf');
var test = require('tap').test;
var Project = require('../lib/project');

Expand Down Expand Up @@ -139,3 +141,12 @@ test('bower support', function(t) {
t.strictEqual(bower.version, '2.3.4');
t.end();
});

test('package inference without package.json', function(t) {
var SANDBOX_NOJSON = path.resolve(__dirname, 'SANDBOX-no-json');
rimraf.sync(SANDBOX_NOJSON);
mkdirp.sync(SANDBOX_NOJSON);
var p1 = new Project(SANDBOX_NOJSON);
t.equal(p1.nameVer(), 'SANDBOX-no-json@1.0.0-0');
t.end();
});

0 comments on commit 913c92b

Please sign in to comment.