Repository: ember-cli/ember-try
Pull request #108 (2016-10-30 19:41:26)

Allow removing packages from bower config
Counterpart to #106 for bower.

As discussed, changed from 'undefined' to 'null' to signify a package should be removed in a scenario. 


Patch:
diff --git a/.travis.yml b/.travis.yml
index d3ed308..4493489 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -5,15 +5,7 @@ node_js:
   - "4.2"
 #  - "6" - The test that includes coverage runs with 6
 
-dist: trusty
-sudo: required
-
-addons:
-  apt:
-    sources:
-    - google-chrome
-    packages:
-    - google-chrome-stable
+sudo: false
 
 cache:
   directories:
@@ -35,14 +27,13 @@ matrix:
     env: NPM_SCRIPT=node-test-with-coverage
 
 before_install:
-  - "export DISPLAY=:99.0"
-  - "sh -e /etc/init.d/xvfb start"
-  - "npm config set spin false"
-  - "npm install -g npm@^2"
+  - npm config set spin false
+  - npm install -g bower
+  - bower --version
+  - npm install phantomjs-prebuilt
+  - node_modules/phantomjs-prebuilt/bin/phantomjs --version
 
 install:
-  - node --version
-  - npm install -g bower
   - npm install
   - bower install
 
diff --git a/README.md b/README.md
index 2d9d363..f04bf0a 100644
--- a/README.md
+++ b/README.md
@@ -159,8 +159,8 @@ module.exports = function() {
         devDependencies: {
           'ember-data': '2.3.0',
 
-          // you can remove any package by marking `undefined`
-          'some-optional-package': undefined
+          // you can remove any package by marking `null`
+          'some-optional-package': null
         }
       },
       bower: {
diff --git a/lib/dependency-manager-adapters/bower.js b/lib/dependency-manager-adapters/bower.js
index 5ad0583..eacf5f5 100644
--- a/lib/dependency-manager-adapters/bower.js
+++ b/lib/dependency-manager-adapters/bower.js
@@ -75,7 +75,7 @@ module.exports = CoreObject.extend({
     if (fs.existsSync(filename)) {
       return JSON.parse(fs.readFileSync(filename)).version;
     } else {
-      throw 'File ' + filename + ' does not exist';
+      return null;
     }
   },
   _install: function() {
@@ -110,12 +110,19 @@ module.exports = CoreObject.extend({
       if (!bowerJSON[kindOfDependency]) {
         bowerJSON[kindOfDependency] = {};
       }
-      bowerJSON[kindOfDependency][pkg] = depSet[kindOfDependency][pkg];
 
-      if (depSet.resolutions && depSet.resolutions[pkg]) {
-        bowerJSON.resolutions[pkg] = depSet.resolutions[pkg];
+      var version = depSet[kindOfDependency][pkg];
+      if (version === null) {
+        delete bowerJSON[kindOfDependency][pkg];
+        delete bowerJSON.resolutions[pkg];
       } else {
-        bowerJSON.resolutions[pkg] = depSet[kindOfDependency][pkg];
+        bowerJSON[kindOfDependency][pkg] = version;
+
+        if (depSet.resolutions && depSet.resolutions[pkg]) {
+          bowerJSON.resolutions[pkg] = depSet.resolutions[pkg];
+        } else {
+          bowerJSON.resolutions[pkg] = version;
+        }
       }
     });
   },
diff --git a/lib/dependency-manager-adapters/npm.js b/lib/dependency-manager-adapters/npm.js
index 3400a1e..0a844bb 100644
--- a/lib/dependency-manager-adapters/npm.js
+++ b/lib/dependency-manager-adapters/npm.js
@@ -70,7 +70,7 @@ module.exports = CoreObject.extend({
     if (fs.existsSync(filename)) {
       return JSON.parse(fs.readFileSync(filename)).version;
     } else {
-      throw 'File ' + filename + ' does not exist';
+      return null;
     }
   },
   _install: function() {
@@ -102,7 +102,7 @@ module.exports = CoreObject.extend({
       }
 
       var version = depSet[kindOfDependency][pkg];
-      if (version === undefined) {
+      if (version === null) {
         delete packageJSON[kindOfDependency][pkg];
       } else {
         packageJSON[kindOfDependency][pkg] = version;
diff --git a/lib/utils/result-summary.js b/lib/utils/result-summary.js
index 88624a2..bd8d651 100644
--- a/lib/utils/result-summary.js
+++ b/lib/utils/result-summary.js
@@ -58,7 +58,7 @@ module.exports = CoreObject.extend({
       } else {
         colorForDepFn = chalk.yellow;
       }
-      tableRow = [dep.name, dep.versionExpected, dep.versionSeen, dep.packageManager].map(function(column) {
+      tableRow = [dep.name, dep.versionExpected || 'Not Installed', dep.versionSeen || 'Not Installed', dep.packageManager].map(function(column) {
         return colorForDepFn(column);
       });
       table.push(tableRow);


Test patch:
diff --git a/test/dependency-manager-adapters/bower-adapter-test.js b/test/dependency-manager-adapters/bower-adapter-test.js
index b644b38..2bb6a09 100644
--- a/test/dependency-manager-adapters/bower-adapter-test.js
+++ b/test/dependency-manager-adapters/bower-adapter-test.js
@@ -193,6 +193,17 @@ describe('bowerAdapter', function() {
 
       expect(resultJSON.resolutions.jquery).to.equal('2.1.3');
     });
+
+    it('can remove a package', function() {
+      var bowerAdapter = new BowerAdapter({cwd: tmpdir});
+      var bowerJSON = { dependencies: { jquery: '1.11.1' }, resolutions: { jquery: '1.11.1' } };
+      var depSet = { dependencies: { jquery: null } };
+
+      var resultJSON = bowerAdapter._bowerJSONForDependencySet(bowerJSON, depSet);
+
+      expect(resultJSON.dependencies).to.not.have.property('jquery');
+      expect(resultJSON.resolutions).to.not.have.property('jquery');
+    });
   });
 
   describe('#_findBowerPath()', function() {
diff --git a/test/dependency-manager-adapters/npm-adapter-test.js b/test/dependency-manager-adapters/npm-adapter-test.js
index e22c45c..77cafca 100644
--- a/test/dependency-manager-adapters/npm-adapter-test.js
+++ b/test/dependency-manager-adapters/npm-adapter-test.js
@@ -145,7 +145,7 @@ describe('npmAdapter', function() {
     it('can remove a package', function() {
       var npmAdapter = new NpmAdapter({cwd: tmpdir});
       var packageJSON = { devDependencies: { 'ember-feature-flags': '1.0.0' } };
-      var depSet = { devDependencies: { 'ember-feature-flags': undefined } };
+      var depSet = { devDependencies: { 'ember-feature-flags': null } };
 
       var resultJSON = npmAdapter._packageJSONForDependencySet(packageJSON, depSet);
 
diff --git a/test/fixtures/bower.json b/test/fixtures/bower.json
index 20e2441..9e00732 100644
--- a/test/fixtures/bower.json
+++ b/test/fixtures/bower.json
@@ -1,6 +1,7 @@
 {
   "name": "a-test-project",
   "dependencies": {
-    "jquery": "^1.11.1"
+    "jquery": "^1.11.1",
+    "bootstrap": "3.0.0"
   }
 }
diff --git a/test/tasks/try-each-test.js b/test/tasks/try-each-test.js
index 12cad0d..2db2508 100644
--- a/test/tasks/try-each-test.js
+++ b/test/tasks/try-each-test.js
@@ -64,7 +64,8 @@ var config = {
       name: 'first',
       bower: {
         dependencies: {
-          ember: '1.13.0'
+          ember: '1.13.0',
+          bootstrap: null
         }
       },
       npm: {
@@ -314,7 +315,7 @@ describe('tryEach', function() {
   describe('with stubbed dependency manager', function() {
     it('passes along timeout options to run', function() {
       // With stubbed dependency manager, timing out is warning for accidentally not using the stub
-      this.timeout(600);
+      this.timeout(1200);
 
       var config = {
         scenarios: [{
@@ -368,7 +369,7 @@ describe('tryEach', function() {
     describe('allowedToFail', function() {
       it('exits appropriately if all failures were allowedToFail', function() {
         // With stubbed dependency manager, timing out is warning for accidentally not using the stub
-        this.timeout(600);
+        this.timeout(1200);
 
         var config = {
           scenarios: [{
@@ -423,7 +424,7 @@ describe('tryEach', function() {
 
       it('exits appropriately if any failures were not allowedToFail', function() {
         // With stubbed dependency manager, timing out is warning for accidentally not using the stub
-        this.timeout(600);
+        this.timeout(1200);
 
         var config = {
           scenarios: [{
@@ -477,7 +478,7 @@ describe('tryEach', function() {
 
       it('exits appropriately if all allowedToFail pass', function() {
         // With stubbed dependency manager, timing out is warning for accidentally not using the stub
-        this.timeout(600);
+        this.timeout(1200);
 
         var config = {
           scenarios: [{
@@ -535,7 +536,7 @@ describe('tryEach', function() {
     describe('configurable command', function() {
       it('defaults to `ember test`', function() {
         // With stubbed dependency manager, timing out is warning for accidentally not using the stub
-        this.timeout(600);
+        this.timeout(1200);
 
         var config = {
           scenarios: [{
@@ -592,7 +593,7 @@ describe('tryEach', function() {
 
       it('allows passing in of the command to run', function() {
         // With stubbed dependency manager, timing out is warning for accidentally not using the stub
-        this.timeout(600);
+        this.timeout(1200);
 
         var config = {
           command: 'ember test-this',
@@ -641,7 +642,7 @@ describe('tryEach', function() {
 
       it('uses command from config', function() {
         // With stubbed dependency manager, timing out is warning for accidentally not using the stub
-        this.timeout(600);
+        this.timeout(1200);
 
         var config = {
           command: 'ember test --test-port=2345',
@@ -757,7 +758,7 @@ describe('tryEach', function() {
 
     it('sets EMBER_TRY_CURRENT_SCENARIO', function() {
       // With stubbed dependency manager, timing out is warning for accidentally not using the stub
-      this.timeout(600);
+      this.timeout(1200);
 
       var config = {
         scenarios: [{
diff --git a/testem.js b/testem.js
index cf056bd..26044b2 100644
--- a/testem.js
+++ b/testem.js
@@ -4,9 +4,10 @@ module.exports = {
   "test_page": "tests/index.html?hidepassed",
   "disable_watching": true,
   "launch_in_ci": [
-    "Chrome"
+    "PhantomJS"
   ],
   "launch_in_dev": [
+    "PhantomJS",
     "Chrome"
   ]
 };