diff options
author | FallenRiteMonk <fallenritemonk@gmail.com> | 2018-04-05 11:52:34 -0400 |
---|---|---|
committer | Myles Borins <mylesborins@google.com> | 2018-04-05 16:01:07 -0400 |
commit | 25a816dcda7b1db0929501acfe13f2fe5119759b (patch) | |
tree | d3df4377a11dfb643b5976d2048d9bb4ee527903 /deps/npm/test/tap/install-save-consistent-newlines.js | |
parent | b29c36b80746733994257b7380245102bc3c4cd6 (diff) | |
download | android-node-v8-25a816dcda7b1db0929501acfe13f2fe5119759b.tar.gz android-node-v8-25a816dcda7b1db0929501acfe13f2fe5119759b.tar.bz2 android-node-v8-25a816dcda7b1db0929501acfe13f2fe5119759b.zip |
deps: upgrade npm to 5.8.0
PR-URL: https://github.com/nodejs/node/pull/19560
Fixes: https://github.com/nodejs/node/issues/19271
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Diffstat (limited to 'deps/npm/test/tap/install-save-consistent-newlines.js')
-rw-r--r-- | deps/npm/test/tap/install-save-consistent-newlines.js | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/deps/npm/test/tap/install-save-consistent-newlines.js b/deps/npm/test/tap/install-save-consistent-newlines.js new file mode 100644 index 0000000000..6250377445 --- /dev/null +++ b/deps/npm/test/tap/install-save-consistent-newlines.js @@ -0,0 +1,122 @@ +'use strict' + +const fs = require('graceful-fs') +const path = require('path') + +const mkdirp = require('mkdirp') +const mr = require('npm-registry-mock') +const osenv = require('osenv') +const rimraf = require('rimraf') +const test = require('tap').test + +const common = require('../common-tap.js') + +const pkg = path.join(__dirname, 'install-save-consistent-newlines') + +const EXEC_OPTS = { cwd: pkg } + +const json = { + name: 'install-save-consistent-newlines', + version: '0.0.1', + description: 'fixture' +} + +var server + +test('setup', function (t) { + setup('\n') + mr({ port: common.port }, function (er, s) { + server = s + t.end() + }) +}) + +test('\'npm install --save\' should keep the original package.json line endings (LF)', function (t) { + common.npm( + [ + '--loglevel', 'silent', + '--registry', common.registry, + '--save', + 'install', 'underscore@1.3.1' + ], + EXEC_OPTS, + function (err, code) { + t.ifError(err, 'npm ran without issue') + t.notOk(code, 'npm install exited without raising an error code') + + const pkgPath = path.resolve(pkg, 'package.json') + const pkgStr = fs.readFileSync(pkgPath, 'utf8') + + t.match(pkgStr, '\n') + t.notMatch(pkgStr, '\r') + + const pkgLockPath = path.resolve(pkg, 'package-lock.json') + const pkgLockStr = fs.readFileSync(pkgLockPath, 'utf8') + + t.match(pkgLockStr, '\n') + t.notMatch(pkgLockStr, '\r') + + t.end() + } + ) +}) + +test('\'npm install --save\' should keep the original package.json line endings (CRLF)', function (t) { + setup('\r\n') + + common.npm( + [ + '--loglevel', 'silent', + '--registry', common.registry, + '--save', + 'install', 'underscore@1.3.1' + ], + EXEC_OPTS, + function (err, code) { + t.ifError(err, 'npm ran without issue') + t.notOk(code, 'npm install exited without raising an error code') + + const pkgPath = path.resolve(pkg, 'package.json') + const pkgStr = fs.readFileSync(pkgPath, 'utf8') + + t.match(pkgStr, '\r\n') + t.notMatch(pkgStr, /[^\r]\n/) + + const pkgLockPath = path.resolve(pkg, 'package-lock.json') + const pkgLockStr = fs.readFileSync(pkgLockPath, 'utf8') + + t.match(pkgLockStr, '\r\n') + t.notMatch(pkgLockStr, /[^\r]\n/) + + t.end() + } + ) +}) + +test('cleanup', function (t) { + server.close() + cleanup() + t.end() +}) + +function cleanup () { + process.chdir(osenv.tmpdir()) + rimraf.sync(pkg) +} + +function setup (lineEnding) { + cleanup() + mkdirp.sync(path.resolve(pkg, 'node_modules')) + + var jsonStr = JSON.stringify(json, null, 2) + + if (lineEnding === '\r\n') { + jsonStr = jsonStr.replace(/\n/g, '\r\n') + } + + fs.writeFileSync( + path.join(pkg, 'package.json'), + jsonStr + ) + process.chdir(pkg) +} |