From b1133171b11a48e223354cc9a1d43a7ec600da70 Mon Sep 17 00:00:00 2001 From: Joel Kuzmarski Date: Mon, 3 Apr 2017 10:57:45 -0500 Subject: [PATCH] Test that install skips if node_modules/donejs-cli 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. --- test/cmd-init-test.js | 48 ++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/test/cmd-init-test.js b/test/cmd-init-test.js index c5b4f74e9..d56601f12 100644 --- a/test/cmd-init-test.js +++ b/test/cmd-init-test.js @@ -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; @@ -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); @@ -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); @@ -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]; @@ -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, [ @@ -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);