Repository: ember-cli/ember-cli
Pull request #6491 (2016-11-30 20:15:47)

Fix Builder._enableFSMonitorIfVizEnabled tests
The monitor will only be active if it is the first instance to be constructed.
This is to avoid double counting.  This could be relaxed to be that only one
monitor can be active, but it still seems good to not even require the module
when viz is disabled.


Patch:
diff --git a/lib/broccoli/ember-app.js b/lib/broccoli/ember-app.js
index 0abc94ce0..55e2af95d 100644
--- a/lib/broccoli/ember-app.js
+++ b/lib/broccoli/ember-app.js
@@ -334,11 +334,9 @@ EmberApp.prototype._initVendorFiles = function() {
     delete this.vendorFiles['ember-resolver.js'];
   }
 
-  // Warn if ember-cli-shims is not included.
-  // `ember-source` bundles them by default, so we must check if that is the
-  // load mechanism of ember before checking `bower`.
-  if (!ember && !bowerDeps['ember-cli-shims']) {
-    this.project.ui.writeWarnLine('You have not included `ember-cli-shims` in your project\'s `bower.json`. This only works if you provide an alternative yourself and unset `app.vendorFiles[\'app-shims.js\']`.');
+  // don't crash if ember-cli-shims is not included
+  if (!bowerDeps['ember-cli-shims']) {
+    delete this.vendorFiles['app-shims.js'];
   }
 
   // this is needed to support versions of Ember older than
@@ -894,11 +892,6 @@ EmberApp.prototype._processedBowerTree = function() {
     return;
   }
 
-    // Don't blow up if there is no bower_components folder.
-  if (!existsSync(this.bowerDirectory)) {
-    return;
-  }
-
   this._cachedBowerTree = new Funnel(this.trees.bower, {
     srcDir: '/',
     destDir: this.bowerDirectory + '/',
diff --git a/lib/broccoli/merge-trees.js b/lib/broccoli/merge-trees.js
index 7e5cc5b6e..559ef6846 100644
--- a/lib/broccoli/merge-trees.js
+++ b/lib/broccoli/merge-trees.js
@@ -24,18 +24,18 @@ module.exports = function mergeTrees(_inputTrees, options) {
   });
 
   switch (inputTrees.length) {
-    case 0:
-      return getEmptyTree();
-    case 1:
-      return inputTrees[0];
-    default:
-      options = options || {};
-      options.description = options.annotation;
-      var tree = upstreamMergeTrees(inputTrees, options);
-
-      tree.description = options && options.description;
-
-      return tree;
+  case 0:
+    return getEmptyTree();
+  case 1:
+    return inputTrees[0];
+  default:
+    options = options || {};
+    options.description = options.annotation;
+    var tree = upstreamMergeTrees(inputTrees, options);
+
+    tree.description = options && options.description;
+
+    return tree;
   }
 };
 
diff --git a/lib/models/builder.js b/lib/models/builder.js
index 8b4357b99..fc06884db 100644
--- a/lib/models/builder.js
+++ b/lib/models/builder.js
@@ -18,9 +18,9 @@ var signalsTrapped = false;
 var buildCount = 0;
 
 function _enableFSMonitorIfVizEnabled() {
-  var FSMonitor = require('heimdalljs-fs-monitor');
-  var monitor = new FSMonitor();
+  var monitor;
   if (vizEnabled()) {
+    monitor = new FSMonitor();
     monitor.start();
   }
   return monitor;
diff --git a/lib/utilities/process-template.js b/lib/utilities/process-template.js
index 015fc8990..05e197fc1 100644
--- a/lib/utilities/process-template.js
+++ b/lib/utilities/process-template.js
@@ -1,5 +1,3 @@
-'use strict';
-
 module.exports = function processTemplate(content, context) {
   var options = {
     evaluate:    /<%([\s\S]+?)%>/g,
@@ -7,4 +5,4 @@ module.exports = function processTemplate(content, context) {
     escape:      /<%-([\s\S]+?)%>/g
   };
   return require('lodash.template')(content, options)(context);
-};
+}


Test patch:
diff --git a/tests/unit/broccoli/ember-app-test.js b/tests/unit/broccoli/ember-app-test.js
index 1d5a870fd..8c6ae2471 100644
--- a/tests/unit/broccoli/ember-app-test.js
+++ b/tests/unit/broccoli/ember-app-test.js
@@ -210,6 +210,14 @@ describe('broccoli/ember-app', function() {
         expect(app.vendorFiles['ember-resolver']).to.equal(undefined);
       });
     });
+
+    describe('ember-cli-shims', function() {
+      it('removes app-shims.js from vendorFiles when ember-cli-shims is not in bower.json', function() {
+        project.bowerDependencies = function() { return { 'ember': {} }; }
+        var app = new EmberApp({ project: project });
+        expect(app.vendorFiles['app-shims.js']).to.equal(undefined);
+      });
+    });
   });
 
   describe('contentFor', function() {
diff --git a/tests/unit/models/builder-test.js b/tests/unit/models/builder-test.js
index 801193d10..8191cb354 100644
--- a/tests/unit/models/builder-test.js
+++ b/tests/unit/models/builder-test.js
@@ -1,13 +1,14 @@
 'use strict';
 
-var fs              = require('fs-extra');
+var fs              = require('fs');
+var fse             = require('fs-extra');
 var path            = require('path');
 var Builder         = require('../../../lib/models/builder');
 var BuildCommand    = require('../../../lib/commands/build');
 var commandOptions  = require('../../factories/command-options');
 var Promise         = require('../../../lib/ext/promise');
 var MockProject     = require('../../helpers/mock-project');
-var remove          = Promise.denodeify(fs.remove);
+var remove          = Promise.denodeify(fse.remove);
 var mkTmpDirIn      = require('../../../lib/utilities/mk-tmp-dir-in');
 var td              = require('testdouble');
 
@@ -23,25 +24,34 @@ describe('models/builder.js', function() {
 
   describe('._enableFSMonitorIfVizEnabled', function() {
     var originalBroccoliViz = process.env.BROCCOLI_VIZ;
+    var originalStatSync = fs.statSync;
+
+    beforeEach(function () {
+      expect(!!process.env.BROCCOLI_VIZ).to.eql(false);
+    });
 
     afterEach(function() {
       delete process.env.BROCCOLI_VIZ;
     });
 
-    it('if VIZ is enabled, monitor', function() {
-      process.env.BROCCOLI_VIZ = '1';
+    it('if VIZ is NOT enabled, do not monitor', function() {
       var monitor = Builder._enableFSMonitorIfVizEnabled();
       try {
-        expect(monitor.state).to.eql('active');
+        expect(fs.statSync).to.equal(originalStatSync);
+        expect(monitor).to.eql(undefined);
       } finally {
-        monitor.stop();
+        if (monitor) {
+          monitor.stop();
+        }
       }
     });
 
-    it('if VIZ is NOT enabled, monitor', function() {
+    it('if VIZ is enabled, monitor', function() {
+      process.env.BROCCOLI_VIZ = '1';
       var monitor = Builder._enableFSMonitorIfVizEnabled();
       try {
-        expect(monitor.state).to.eql('idle');
+        expect(fs.statSync).to.not.equal(originalStatSync);
+        expect(monitor.state).to.eql('active');
       } finally {
         monitor.stop();
       }