Repository: ember-cli/ember-cli (js)

Issue:
ember serve watches `tests` directory when `tests: false`
With `tests: false` in `ember-cli-build.js` (e.g. via the recommendation to disable tests in development mode in [this article](https://dev.to/gokatz/how-we-cut-down-our-ember-build-time-ehh)) when changing a file within the `tests` directory the `ember serve` process rebuilds. Previous versions of `ember-cli` did not trigger an `ember serve` rebuild with the same configuration. Using git bisect I was able to identify 1d243e6ef74cd37ab01d2c149c16b68618baa486 as the commit that changed this behavior.

Steps to reproduce:
1. `ember new myapp`
2. `cd myapp`
3. `ember generate route demo`
4. Set `tests: false` in `ember-cli-build.js`
5. `ember serve`
6. (In another terminal session once `ember serve` has completed building) `touch tests/unit/routes/demo-test.js`
7. Note that the `ember serve` process rebuilds

The previous behavior can be observed by installing a version without the above commit (e.g. `npm uninstall ember-cli && npm install ember-cli@3.3.0`) and re-running steps 5-7.

Demo application for reproducing this issue:
https://github.com/f1sherman/demo-ember-serve-watches-tests-when-tests-false

Output from `ember version --verbose && npm --version && yarn --version`:
```
ember-cli: 3.5.0
http_parser: 2.8.0
node: 10.11.0
v8: 6.8.275.32-node.28
uv: 1.23.0
zlib: 1.2.11
ares: 1.14.0
modules: 64
nghttp2: 1.33.0
napi: 3
openssl: 1.1.0i
icu: 62.1
unicode: 11.0
cldr: 33.1
tz: 2018e
os: darwin x64
6.4.1
1.10.1
```


Pull request description:
Do not watch `tests` directory when tests are disabled
Fixes #8173.

This is useful when e.g. disabling tests in development mode (per recommendation in [this article](https://dev.to/gokatz/how-we-cut-down-our-ember-build-time-ehh)) to prevent the `ember serve` process from triggering a rebuild when test files are changed.

This is a minimal approach to resolving this issue. Another potential option would be to not include the `tests` tree at all when tests are disabled, but I was unsure about the downstream implications of making that change.

Patch:
diff --git a/lib/broccoli/ember-app.js b/lib/broccoli/ember-app.js
index 97587feb6..90de86138 100644
--- a/lib/broccoli/ember-app.js
+++ b/lib/broccoli/ember-app.js
@@ -260,7 +260,7 @@ class EmberApp {
     let appTree = buildTreeFor('app', trees.app);
 
     let testsPath = typeof trees.tests === 'string' ? resolvePathFor('tests', trees.tests) : null;
-    let testsTree = buildTreeFor('tests', trees.tests);
+    let testsTree = buildTreeFor('tests', trees.tests, options.tests);
 
     // these are contained within app/ no need to watch again
     // (we should probably have the builder or the watcher dedup though)


Test patch:
diff --git a/tests/unit/broccoli/ember-app-test.js b/tests/unit/broccoli/ember-app-test.js
index 1b6507e6f..4c156210f 100644
--- a/tests/unit/broccoli/ember-app-test.js
+++ b/tests/unit/broccoli/ember-app-test.js
@@ -8,6 +8,7 @@ const Project = require('../../../lib/models/project');
 const expect = require('chai').expect;
 const td = require('testdouble');
 const broccoliTestHelper = require('broccoli-test-helper');
+const { WatchedDir, UnwatchedDir } = require('broccoli-source');
 
 const buildOutput = broccoliTestHelper.buildOutput;
 const createTempDir = broccoliTestHelper.createTempDir;
@@ -1457,6 +1458,31 @@ describe('EmberApp', function() {
     }).to.throw(/You must pass either `vendor` or `test` for options.type in your call to `app.import` for file: foo.js/);
   });
 
+  describe('_initOptions', function() {
+    it('sets the tests directory as watched when tests are enabled', function() {
+      let app = new EmberApp({
+        project,
+      });
+
+      app._initOptions({
+        tests: true,
+      });
+
+      expect(app.options.trees.tests).to.be.an.instanceOf(WatchedDir);
+    });
+    it('sets the tests directory as unwatched when tests are disabled', function() {
+      let app = new EmberApp({
+        project,
+      });
+
+      app._initOptions({
+        tests: false,
+      });
+
+      expect(app.options.trees.tests).to.be.an.instanceOf(UnwatchedDir);
+    });
+  });
+
   describe('_resolveLocal', function() {
     it('resolves a path relative to the project root', function() {
       let app = new EmberApp({