Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorThorsten Lorenz <thlorenz@gmx.de>2014-03-29 06:22:43 +0400
committerisaacs <i@izs.me>2014-04-10 21:50:32 +0400
commit64eefdfe26bb27db8dc90e3ab5d27a5ef18a4470 (patch)
treec2db15c702921e378c0943258683b73a2f34e3f4 /test
parent4a5257de3870ac3dafa39667379f19f6dcd6093e (diff)
adding save-prefix configuration option
- npm install --save|--save-dev takes npm.config['save-prefix'] into account when prefixing the version in the package.json - by default the version is prefixed with '^' - added tests for this feature - added documentation for this feature including one example - tests are passing without npmconf changes, but this commit goes alongside [e045042] in npmconf repo
Diffstat (limited to 'test')
-rw-r--r--test/tap/install-save-prefix.js140
-rw-r--r--test/tap/install-save-prefix/README.md1
-rw-r--r--test/tap/install-save-prefix/index.js1
-rw-r--r--test/tap/install-save-prefix/package.json7
4 files changed, 149 insertions, 0 deletions
diff --git a/test/tap/install-save-prefix.js b/test/tap/install-save-prefix.js
new file mode 100644
index 000000000..0ce6e02fa
--- /dev/null
+++ b/test/tap/install-save-prefix.js
@@ -0,0 +1,140 @@
+var common = require('../common-tap.js')
+var test = require('tap').test
+var npm = require('../../')
+var osenv = require('osenv')
+var path = require('path')
+var fs = require('fs')
+var rimraf = require('rimraf')
+var mkdirp = require('mkdirp')
+var pkg = path.join(__dirname, 'install-save-prefix')
+var mr = require("npm-registry-mock")
+
+test("setup", function (t) {
+ mkdirp.sync(pkg)
+ mkdirp.sync(path.resolve(pkg, 'node_modules'))
+ process.chdir(pkg)
+ t.end()
+})
+
+test('"npm install --save with default save-prefix should install local pkg versioned to allow minor updates', function(t) {
+ resetPackageJSON(pkg)
+ mr(common.port, function (s) {
+ npm.load({
+ cache: pkg + "/cache",
+ loglevel: 'silent',
+ registry: common.registry }, function(err) {
+ t.ifError(err)
+ npm.config.set('save', true)
+ npm.commands.install(['underscore@1.3.1'], function(err) {
+ t.ifError(err)
+ var p = path.resolve(pkg, 'node_modules/underscore/package.json')
+ t.ok(JSON.parse(fs.readFileSync(p)))
+ var pkgJson = JSON.parse(fs.readFileSync(pkg + '/package.json', 'utf8'))
+ t.deepEqual(pkgJson.dependencies, {
+ 'underscore': '^1.3.1'
+ }, 'Underscore dependency should specify ^1.3.1')
+ npm.config.set('save', undefined)
+ s.close()
+ t.end()
+ })
+ })
+ })
+})
+
+test('"npm install --save-dev with default save-prefix should install local pkg to dev dependencies versioned to allow minor updates', function(t) {
+ resetPackageJSON(pkg)
+ mr(common.port, function (s) {
+ npm.load({
+ cache: pkg + "/cache",
+ loglevel: 'silent',
+ registry: common.registry }, function(err) {
+ t.ifError(err)
+ npm.config.set('save-dev', true)
+ npm.commands.install(['underscore@1.3.1'], function(err) {
+ t.ifError(err)
+ var p = path.resolve(pkg, 'node_modules/underscore/package.json')
+ t.ok(JSON.parse(fs.readFileSync(p)))
+ var pkgJson = JSON.parse(fs.readFileSync(pkg + '/package.json', 'utf8'))
+ t.deepEqual(pkgJson.devDependencies, {
+ 'underscore': '^1.3.1'
+ }, 'Underscore devDependency should specify ^1.3.1')
+ npm.config.set('save-dev', undefined)
+ s.close()
+ t.end()
+ })
+ })
+ })
+})
+
+test('"npm install --save with "~" save-prefix should install local pkg versioned to allow patch updates', function(t) {
+ resetPackageJSON(pkg)
+ mr(common.port, function (s) {
+ npm.load({
+ cache: pkg + "/cache",
+ loglevel: 'silent',
+ registry: common.registry }, function(err) {
+ t.ifError(err)
+ npm.config.set('save', true)
+ npm.config.set('save-prefix', '~')
+ npm.commands.install(['underscore@1.3.1'], function(err) {
+ t.ifError(err)
+ var p = path.resolve(pkg, 'node_modules/underscore/package.json')
+ t.ok(JSON.parse(fs.readFileSync(p)))
+ var pkgJson = JSON.parse(fs.readFileSync(pkg + '/package.json', 'utf8'))
+ t.deepEqual(pkgJson.dependencies, {
+ 'underscore': '~1.3.1'
+ }, 'Underscore dependency should specify ~1.3.1')
+ npm.config.set('save', undefined)
+ npm.config.set('save-prefix', undefined)
+ s.close()
+ t.end()
+ })
+ })
+ })
+})
+
+test('"npm install --save-dev with "~" save-prefix should install local pkg to dev dependencies versioned to allow patch updates', function(t) {
+ resetPackageJSON(pkg)
+ mr(common.port, function (s) {
+ npm.load({
+ cache: pkg + "/cache",
+ loglevel: 'silent',
+ registry: common.registry }, function(err) {
+ t.ifError(err)
+ npm.config.set('save-dev', true)
+ npm.config.set('save-prefix', '~')
+ npm.commands.install(['underscore@1.3.1'], function(err) {
+ t.ifError(err)
+ var p = path.resolve(pkg, 'node_modules/underscore/package.json')
+ t.ok(JSON.parse(fs.readFileSync(p)))
+ var pkgJson = JSON.parse(fs.readFileSync(pkg + '/package.json', 'utf8'))
+ t.deepEqual(pkgJson.devDependencies, {
+ 'underscore': '~1.3.1'
+ }, 'Underscore devDependency should specify ~1.3.1')
+ npm.config.set('save-dev', undefined)
+ npm.config.set('save-prefix', undefined)
+ s.close()
+ t.end()
+ })
+ })
+ })
+})
+
+test('cleanup', function(t) {
+ process.chdir(__dirname)
+ rimraf.sync(path.resolve(pkg, 'node_modules'))
+ rimraf.sync(path.resolve(pkg, 'cache'))
+ resetPackageJSON(pkg)
+ t.end()
+})
+
+function resetPackageJSON(pkg) {
+ var pkgJson = JSON.parse(fs.readFileSync(pkg + '/package.json', 'utf8'))
+ delete pkgJson.dependencies
+ delete pkgJson.devDependencies
+ delete pkgJson.optionalDependencies
+ var json = JSON.stringify(pkgJson, null, 2) + "\n"
+ fs.writeFileSync(pkg + '/package.json', json, "ascii")
+}
+
+
diff --git a/test/tap/install-save-prefix/README.md b/test/tap/install-save-prefix/README.md
new file mode 100644
index 000000000..aca67ff17
--- /dev/null
+++ b/test/tap/install-save-prefix/README.md
@@ -0,0 +1 @@
+# just a test
diff --git a/test/tap/install-save-prefix/index.js b/test/tap/install-save-prefix/index.js
new file mode 100644
index 000000000..33c1891f8
--- /dev/null
+++ b/test/tap/install-save-prefix/index.js
@@ -0,0 +1 @@
+module.exports = true
diff --git a/test/tap/install-save-prefix/package.json b/test/tap/install-save-prefix/package.json
new file mode 100644
index 000000000..84789fc22
--- /dev/null
+++ b/test/tap/install-save-prefix/package.json
@@ -0,0 +1,7 @@
+{
+ "name": "bla",
+ "description": "fixture",
+ "version": "0.0.1",
+ "main": "index.js",
+ "repository": "git://github.com/robertkowalski/bogusfixture"
+}