CB-13303 : setting production flag to default during npm install and test
diff --git a/index.js b/index.js
index fd4c583..60a3176 100644
--- a/index.js
+++ b/index.js
@@ -40,9 +40,10 @@
var fetchArgs = opts.link ? ['link'] : ['install'];
opts = opts || {};
var tree1;
+ opts.production = opts.production || true;
// check if npm is installed
- return isNpmInstalled()
+ return module.exports.isNpmInstalled()
.then(function () {
if (dest && target) {
// add target to fetchArgs Array
@@ -60,6 +61,10 @@
// set the directory where npm install will be run
opts.cwd = dest;
+ // npm should use production by default when install is npm run
+ if (opts.production) {
+ fetchArgs.push('--production');
+ }
// if user added --save flag, pass it to npm install command
if (opts.save) {
@@ -88,7 +93,7 @@
// This could happen on a platform update.
var id = getJsonDiff(tree1, tree2) || trimID(target);
- return getPath(id, dest, target);
+ return module.exports.getPath(id, dest, target);
})
.fail(function (err) {
return Q.reject(new CordovaError(err));
@@ -194,6 +199,7 @@
return finalDest;
}
+module.exports.getPath = getPath;
/*
* Make an additional search in destination folder using repository.url property from package.json
*
@@ -235,6 +241,7 @@
return Q();
}
+module.exports.isNpmInstalled = isNpmInstalled;
/*
* A function that deletes the target from node_modules and runs npm uninstall
*
diff --git a/package.json b/package.json
index 3b9d8bf..f82ad1b 100644
--- a/package.json
+++ b/package.json
@@ -40,7 +40,7 @@
"scripts": {
"test": "npm run eslint && npm run jasmine",
"eslint": "eslint index.js spec/fetch.spec.js",
- "jasmine": "jasmine spec/fetch.spec.js"
+ "jasmine": "jasmine spec/fetch.spec.js spec/fetch-unit.spec.js"
},
"engines": {
"node": ">=4.0.0",
diff --git a/spec/fetch-unit.spec.js b/spec/fetch-unit.spec.js
new file mode 100644
index 0000000..faf53c7
--- /dev/null
+++ b/spec/fetch-unit.spec.js
@@ -0,0 +1,47 @@
+/**
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+*/
+
+/* eslint-env jasmine */
+var fetch = require('../index.js');
+var shell = require('shelljs');
+var fs = require('fs');
+var Q = require('q');
+var superspawn = require('cordova-common').superspawn;
+
+describe('unit tests for index.js', function () {
+ beforeEach(function () {
+ spyOn(superspawn, 'spawn').and.returnValue(true);
+ spyOn(shell, 'mkdir').and.returnValue(true);
+ spyOn(shell, 'which').and.returnValue(Q());
+ spyOn(fetch, 'isNpmInstalled').and.returnValue(Q());
+ spyOn(fetch, 'getPath').and.returnValue('some/path');
+ spyOn(fs, 'existsSync').and.returnValue(false);
+ });
+
+ it('npm install should be called with production flag (default)', function (done) {
+ var opts = { cwd: 'some/path', production: true };
+ fetch('platform', 'tmpDir', opts)
+ .then(function (result) {
+ expect(superspawn.spawn).toHaveBeenCalledWith('npm', [ 'install', 'platform', '--production' ], jasmine.any(Object));
+ })
+ .fail(function (err) {
+ console.error(err);
+ expect(err).toBeUndefined();
+ })
+ .fin(done);
+ }, 600000);
+});