Skip to content

Commit

Permalink
Test that install skips if node_modules/donejs-cli
Browse files Browse the repository at this point in the history
Install command will skip installing donejs-cli if it already
exists, assuming it was put there by `npm link` or otherwise
for debugging and/or development purposes.
  • Loading branch information
leoj3n committed Apr 3, 2017
1 parent a049c7b commit b113317
Showing 1 changed file with 34 additions and 14 deletions.
48 changes: 34 additions & 14 deletions test/cmd-init-test.js
Expand Up @@ -6,7 +6,7 @@ var assert = require('assert');
var mockery = require('mockery');
var utils = require('../lib/utils');

describe('cli init cmd', function() {
describe('donejs-cli init command', function() {
var cwd;
var init;
var spawnCalls;
Expand Down Expand Up @@ -55,13 +55,11 @@ describe('cli init cmd', function() {
mockery.deregisterAll();
});

it('creates folder if it does not exist', function(done) {
var folder = 'test-project';

it('creates project {folder} if it does not exist', function(done) {
init(folder, {})
.then(function() {
process.chdir(cwd);
assert(fs.existsSync(folder), 'should create folder');
assert(fs.existsSync(folder), 'should create project {folder}');
done();
})
.catch(done);
Expand All @@ -70,7 +68,7 @@ describe('cli init cmd', function() {
// otherwise npm will walk up the tree until it finds a node_modules folder,
// that causes issues if there is indeed an existing node_modules in any of
// the "folder" parent directories.
it('creates {folder}/node_modules for deps to be installed', function(done) {
it('creates {folder}/node_modules to stop npm from crawling parent dirs', function(done) {
init(folder, {})
.then(function() {
process.chdir(cwd);
Expand All @@ -81,7 +79,7 @@ describe('cli init cmd', function() {
.catch(done);
});

it('installs the donejs-cli and then runs done-js init', function(done) {
it('installs donejs-cli and then runs `donejs-cli init`', function(done) {
init(folder, {})
.then(function() {
var installCliCall = spawnCalls[0];
Expand All @@ -92,19 +90,32 @@ describe('cli init cmd', function() {
'install', 'donejs-cli@latest', '--loglevel', 'error'
]);

assert.deepEqual(runBinaryCall.args, ['init']);
assert.deepEqual(
runBinaryCall.options,
{ cwd: folderPath },
'it should set cwd to folderPath so init puts files in {folder}'
);
assertRunBinaryCallInit(folderPath);

done();
})
.catch(done);
});

it('passes options to donejs-init properly', function(done) {
// if folder already exists, we assume it was put there by npm link, or manually, for debugging purposes
it('skips install if {folder}/node_modules/donejs-cli exists, still runs `donejs-cli init`', function(done) {
utils.mkdirp(path.join(folder, 'node_modules', 'donejs-cli')).then(function() {
init(folder, {})
.then(function() {
var installCliCall = spawnCalls[0];
var folderPath = path.join(cwd, folder);

assert.strictEqual(installCliCall, undefined);

assertRunBinaryCallInit(folderPath);

done();
})
.catch(done);
});
});

it('passes options to `donejs-cli init` properly', function(done) {
init(folder, { skipInstall: true, type: 'foobar' })
.then(function() {
assert.deepEqual(runBinaryCall.args, [
Expand All @@ -115,6 +126,15 @@ describe('cli init cmd', function() {
.catch(done);
});

function assertRunBinaryCallInit(folderPath) {
assert.deepEqual(runBinaryCall.args, ['init']);
assert.deepEqual(
runBinaryCall.options,
{ cwd: folderPath },
'it should set cwd so init puts files in {folder}'
);
}

function deleteFolder() {
if (fs.existsSync(folder)) {
rimraf.sync(folder);
Expand Down

0 comments on commit b113317

Please sign in to comment.