Repository: ember-cli/ember-cli
Pull request #6452 (2016-11-22 18:56:33)

Lazily install fs monitor
Only install fs monitor if `process.env.BROCCOLI_VIZ`.  There's no reason to
monitor fs operations if we're not going to actually output them.


Patch:
diff --git a/lib/models/builder.js b/lib/models/builder.js
index 038a86172..8b4357b99 100644
--- a/lib/models/builder.js
+++ b/lib/models/builder.js
@@ -12,15 +12,26 @@ var chalk       = require('chalk');
 var attemptNeverIndex = require('../utilities/attempt-never-index');
 var findBuildFile = require('../utilities/find-build-file');
 
-var FSMonitor = require('heimdalljs-fs-monitor');
-var monitor = new FSMonitor();
-monitor.start();
-
 var Sync = require('tree-sync');
 
 var signalsTrapped = false;
 var buildCount = 0;
 
+function _enableFSMonitorIfVizEnabled() {
+  var FSMonitor = require('heimdalljs-fs-monitor');
+  var monitor = new FSMonitor();
+  if (vizEnabled()) {
+    monitor.start();
+  }
+  return monitor;
+}
+
+_enableFSMonitorIfVizEnabled();
+
+function vizEnabled() {
+  return !!process.env.BROCCOLI_VIZ;
+}
+
 function outputViz(count, result) {
   var nodes = result.graph.__heimdall__.toJSONSubgraph();
 
@@ -216,7 +227,7 @@ module.exports = Task.extend({
       })
       .then(function(result) {
 
-        if (process.env.BROCCOLI_VIZ) {
+        if (vizEnabled()) {
           outputViz(buildCount++, result);
         }
         return result;
@@ -307,3 +318,5 @@ module.exports = Task.extend({
     }
   }
 });
+
+module.exports._enableFSMonitorIfVizEnabled = _enableFSMonitorIfVizEnabled;
diff --git a/package.json b/package.json
index 691184914..1186407e3 100644
--- a/package.json
+++ b/package.json
@@ -79,7 +79,7 @@
     "get-caller-file": "^1.0.0",
     "git-repo-info": "^1.0.4",
     "glob": "7.1.1",
-    "heimdalljs-fs-monitor": "^0.1.0",
+    "heimdalljs-fs-monitor": "^0.0.3",
     "heimdalljs-logger": "^0.1.7",
     "http-proxy": "^1.9.0",
     "inflection": "^1.7.0",


Test patch:
diff --git a/tests/acceptance/addon-dummy-generate-test.js b/tests/acceptance/addon-dummy-generate-test.js
index e34d52cee..b90914736 100644
--- a/tests/acceptance/addon-dummy-generate-test.js
+++ b/tests/acceptance/addon-dummy-generate-test.js
@@ -1,6 +1,7 @@
 'use strict';
 
 var Promise              = require('../../lib/ext/promise');
+var conf                 = require('ember-cli-internal-test-helpers/lib/helpers/conf');
 var ember                = require('../helpers/ember');
 var fs                   = require('fs-extra');
 var path                 = require('path');
@@ -20,10 +21,12 @@ describe('Acceptance: ember generate in-addon-dummy', function() {
 
   before(function() {
     BlueprintNpmTask.disableNPM(Blueprint);
+    conf.setup();
   });
 
   after(function() {
     BlueprintNpmTask.restoreNPM(Blueprint);
+    conf.restore();
   });
 
   beforeEach(function() {
diff --git a/tests/acceptance/addon-generate-test.js b/tests/acceptance/addon-generate-test.js
index 0658129d6..05a8d3aed 100644
--- a/tests/acceptance/addon-generate-test.js
+++ b/tests/acceptance/addon-generate-test.js
@@ -1,6 +1,7 @@
 'use strict';
 
 var Promise              = require('../../lib/ext/promise');
+var conf                 = require('ember-cli-internal-test-helpers/lib/helpers/conf');
 var ember                = require('../helpers/ember');
 var fs                   = require('fs-extra');
 var path                 = require('path');
@@ -20,10 +21,12 @@ describe('Acceptance: ember generate in-addon', function() {
 
   before(function() {
     BlueprintNpmTask.disableNPM(Blueprint);
+    conf.setup();
   });
 
   after(function() {
     BlueprintNpmTask.restoreNPM(Blueprint);
+    conf.restore();
   });
 
   beforeEach(function() {
diff --git a/tests/acceptance/destroy-test.js b/tests/acceptance/destroy-test.js
index 8859c80d2..382fc186f 100644
--- a/tests/acceptance/destroy-test.js
+++ b/tests/acceptance/destroy-test.js
@@ -1,6 +1,7 @@
 'use strict';
 
 var Promise    = require('../../lib/ext/promise');
+var conf       = require('ember-cli-internal-test-helpers/lib/helpers/conf');
 var ember      = require('../helpers/ember');
 var fs         = require('fs-extra');
 var outputFile = Promise.denodeify(fs.outputFile);
@@ -23,10 +24,12 @@ describe('Acceptance: ember destroy', function() {
 
   before(function() {
     BlueprintNpmTask.disableNPM(Blueprint);
+    conf.setup();
   });
 
   after(function() {
     BlueprintNpmTask.restoreNPM(Blueprint);
+    conf.restore();
   });
 
   beforeEach(function() {
diff --git a/tests/acceptance/generate-test.js b/tests/acceptance/generate-test.js
index 373b052b9..85d69faa6 100755
--- a/tests/acceptance/generate-test.js
+++ b/tests/acceptance/generate-test.js
@@ -1,6 +1,7 @@
 'use strict';
 
 var Promise          = require('../../lib/ext/promise');
+var conf             = require('ember-cli-internal-test-helpers/lib/helpers/conf');
 var ember            = require('../helpers/ember');
 var fs               = require('fs-extra');
 var outputFile       = Promise.denodeify(fs.outputFile);
@@ -24,10 +25,12 @@ describe('Acceptance: ember generate', function() {
 
   before(function() {
     BlueprintNpmTask.disableNPM(Blueprint);
+    conf.setup();
   });
 
   after(function() {
     BlueprintNpmTask.restoreNPM(Blueprint);
+    conf.restore();
   });
 
   beforeEach(function() {
diff --git a/tests/acceptance/in-repo-addon-generate-test.js b/tests/acceptance/in-repo-addon-generate-test.js
index 3714b261b..01f40a178 100644
--- a/tests/acceptance/in-repo-addon-generate-test.js
+++ b/tests/acceptance/in-repo-addon-generate-test.js
@@ -1,6 +1,7 @@
 'use strict';
 
 var Promise              = require('../../lib/ext/promise');
+var conf                 = require('ember-cli-internal-test-helpers/lib/helpers/conf');
 var ember                = require('../helpers/ember');
 var fs                   = require('fs-extra');
 var path                 = require('path');
@@ -20,10 +21,12 @@ describe('Acceptance: ember generate in-repo-addon', function() {
 
   before(function() {
     BlueprintNpmTask.disableNPM(Blueprint);
+    conf.setup();
   });
 
   after(function() {
     BlueprintNpmTask.restoreNPM(Blueprint);
+    conf.restore();
   });
 
   beforeEach(function() {
diff --git a/tests/acceptance/init-test.js b/tests/acceptance/init-test.js
index 4d5612b9f..1076c43eb 100644
--- a/tests/acceptance/init-test.js
+++ b/tests/acceptance/init-test.js
@@ -8,6 +8,7 @@ var path       = require('path');
 var tmp        = require('ember-cli-internal-test-helpers/lib/helpers/tmp');
 var root       = process.cwd();
 var util       = require('util');
+var conf       = require('ember-cli-internal-test-helpers/lib/helpers/conf');
 var minimatch  = require('minimatch');
 var lodash = require('ember-cli-lodash-subset');
 var intersect  = lodash.intersection;
@@ -27,6 +28,14 @@ var tmpPath = './tmp/init-test';
 describe('Acceptance: ember init', function() {
   this.timeout(20000);
 
+  before(function() {
+    conf.setup();
+  });
+
+  after(function() {
+    conf.restore();
+  });
+
   beforeEach(function() {
     Blueprint.ignoredFiles = defaultIgnoredFiles;
 
diff --git a/tests/acceptance/install-test-slow.js b/tests/acceptance/install-test-slow.js
index 01b400613..3f6b8e4bb 100644
--- a/tests/acceptance/install-test-slow.js
+++ b/tests/acceptance/install-test-slow.js
@@ -1,6 +1,7 @@
 'use strict';
 
 var Promise    = require('../../lib/ext/promise');
+var conf       = require('../helpers/conf');
 var ember      = require('../helpers/ember');
 var path       = require('path');
 var remove     = Promise.denodeify(require('fs-extra').remove);
@@ -15,6 +16,14 @@ var file = chai.file;
 describe('Acceptance: ember install', function() {
   this.timeout(60000);
 
+  before(function() {
+    conf.setup();
+  });
+
+  after(function() {
+    conf.restore();
+  });
+
   beforeEach(function() {
     return mkTmpDirIn(tmproot).then(function(tmpdir) {
       process.chdir(tmpdir);
diff --git a/tests/acceptance/new-test.js b/tests/acceptance/new-test.js
index 32bf25ab1..1c7970970 100644
--- a/tests/acceptance/new-test.js
+++ b/tests/acceptance/new-test.js
@@ -8,6 +8,7 @@ var path       = require('path');
 var tmp        = require('ember-cli-internal-test-helpers/lib/helpers/tmp');
 var root       = process.cwd();
 var util       = require('util');
+var conf       = require('ember-cli-internal-test-helpers/lib/helpers/conf');
 var EOL        = require('os').EOL;
 var chalk      = require('chalk');
 
@@ -22,6 +23,9 @@ var tmpDir = './tmp/new-test';
 describe('Acceptance: ember new', function() {
   this.timeout(10000);
 
+  before(conf.setup);
+  after(conf.restore);
+
   beforeEach(function() {
     return tmp.setup(tmpDir)
       .then(function() {
diff --git a/tests/acceptance/pods-destroy-test.js b/tests/acceptance/pods-destroy-test.js
index 6116defec..16e4450a0 100644
--- a/tests/acceptance/pods-destroy-test.js
+++ b/tests/acceptance/pods-destroy-test.js
@@ -1,6 +1,7 @@
 'use strict';
 
 var Promise     = require('../../lib/ext/promise');
+var conf        = require('ember-cli-internal-test-helpers/lib/helpers/conf');
 var ember       = require('../helpers/ember');
 var fs          = require('fs-extra');
 var replaceFile = require('ember-cli-internal-test-helpers/lib/helpers/file-utils').replaceFile;
@@ -25,10 +26,12 @@ describe('Acceptance: ember destroy pod', function() {
 
   before(function() {
     BlueprintNpmTask.disableNPM(Blueprint);
+    conf.setup();
   });
 
   after(function() {
     BlueprintNpmTask.restoreNPM(Blueprint);
+    conf.restore();
   });
 
   beforeEach(function() {
diff --git a/tests/acceptance/pods-generate-test.js b/tests/acceptance/pods-generate-test.js
index cea1f6893..0cbf71562 100644
--- a/tests/acceptance/pods-generate-test.js
+++ b/tests/acceptance/pods-generate-test.js
@@ -1,6 +1,7 @@
 'use strict';
 
 var Promise          = require('../../lib/ext/promise');
+var conf             = require('ember-cli-internal-test-helpers/lib/helpers/conf');
 var ember            = require('../helpers/ember');
 var replaceFile      = require('ember-cli-internal-test-helpers/lib/helpers/file-utils').replaceFile;
 var fs               = require('fs-extra');
@@ -25,10 +26,12 @@ describe('Acceptance: ember generate pod', function() {
 
   before(function() {
     BlueprintNpmTask.disableNPM(Blueprint);
+    conf.setup();
   });
 
   after(function() {
     BlueprintNpmTask.restoreNPM(Blueprint);
+    conf.restore();
   });
 
   beforeEach(function() {
diff --git a/tests/helpers/acceptance.js b/tests/helpers/acceptance.js
index 0974a99bb..22ab63c86 100644
--- a/tests/helpers/acceptance.js
+++ b/tests/helpers/acceptance.js
@@ -6,6 +6,7 @@ var fs                = require('fs-extra');
 var runCommand        = require('./run-command');
 var Promise           = require('../../lib/ext/promise');
 var tmp               = require('./tmp');
+var conf              = require('./conf');
 var existsSync        = require('exists-sync');
 var copy              = Promise.denodeify(fs.copy);
 var root              = process.cwd();
@@ -68,6 +69,7 @@ function applyCommand(command, name /*, ...flags*/) {
 function createTmp(command) {
   return tmp.setup('./common-tmp').then(function() {
     process.chdir('./common-tmp');
+    conf.setup();
     return command();
   });
 }
@@ -124,10 +126,13 @@ function createTestTargets(projectName, options) {
 
 /**
  * Tears down the targeted project download directory
+ * and restores conf.
  * @return {Promise}
  */
 function teardownTestTargets() {
-  return tmp.teardown('./common-tmp');
+  return tmp.teardown('./common-tmp').then(function() {
+    conf.restore();
+  });
 }
 
 /**
diff --git a/tests/helpers/conf.js b/tests/helpers/conf.js
new file mode 100644
index 000000000..20d03a24f
--- /dev/null
+++ b/tests/helpers/conf.js
@@ -0,0 +1,14 @@
+'use strict';
+
+var Configstore = require('configstore');
+
+var conf = new Configstore('insight-ember-cli');
+var optOut = conf.get('optOut');
+
+module.exports.setup = function() {
+  conf.set('optOut', true);
+};
+
+module.exports.restore = function() {
+  conf.set('optOut', optOut);
+};
diff --git a/tests/unit/models/builder-test.js b/tests/unit/models/builder-test.js
index 6027c5caa..801193d10 100644
--- a/tests/unit/models/builder-test.js
+++ b/tests/unit/models/builder-test.js
@@ -21,6 +21,34 @@ var tmproot         = path.join(root, 'tmp');
 describe('models/builder.js', function() {
   var addon, builder, buildResults, tmpdir;
 
+  describe('._enableFSMonitorIfVizEnabled', function() {
+    var originalBroccoliViz = process.env.BROCCOLI_VIZ;
+
+    afterEach(function() {
+      delete process.env.BROCCOLI_VIZ;
+    });
+
+    it('if VIZ is enabled, monitor', function() {
+      process.env.BROCCOLI_VIZ = '1';
+      var monitor = Builder._enableFSMonitorIfVizEnabled();
+      try {
+        expect(monitor.state).to.eql('active');
+      } finally {
+        monitor.stop();
+      }
+    });
+
+    it('if VIZ is NOT enabled, monitor', function() {
+      var monitor = Builder._enableFSMonitorIfVizEnabled();
+      try {
+        expect(monitor.state).to.eql('idle');
+      } finally {
+        monitor.stop();
+      }
+    });
+
+  });
+
   describe('Windows CTRL + C Capture', function() {
     var originalPlatform, originalStdin;