node/deps/npm/test/tap/install-windows-newlines.js
Myles Borins ace4fe566f
deps: update npm to 5.5.1
Closes: https://github.com/nodejs/node/pull/16280

PR-URL: https://github.com/nodejs/node/pull/16509
Fixes: https://github.com/nodejs/node/issues/14161
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2017-10-29 21:32:15 -04:00

91 lines
2.1 KiB
JavaScript

var fs = require('graceful-fs')
var path = require('path')
var existsSync = fs.existsSync || path.existsSync
var mkdirp = require('mkdirp')
var rimraf = require('rimraf')
var test = require('tap').test
var common = require('../common-tap.js')
var pkg = path.join(__dirname, 'install-windows-newlines')
var EXEC_OPTS = { cwd: pkg, stdio: [0, 1, 2] }
var json = {
name: 'install-windows-newlines',
description: 'fixture',
version: '0.0.0',
dependencies: {
'cli-dependency': 'file:cli-dependency'
}
}
var dependency = {
name: 'cli-dependency',
description: 'fixture',
version: '0.0.0',
bin: {
hashbang: './hashbang.js',
nohashbang: './nohashbang.js'
}
}
test('setup', function (t) {
cleanup()
mkdirp.sync(path.join(pkg, 'cli-dependency'))
fs.writeFileSync(
path.join(pkg, 'cli-dependency', 'package.json'),
JSON.stringify(dependency, null, 2)
)
fs.writeFileSync(
path.join(pkg, 'cli-dependency', 'hashbang.js'),
'#!/usr/bin/env node\r\nconsole.log(\'Hello, world!\')\r\n'
)
fs.writeFileSync(
path.join(pkg, 'cli-dependency', 'nohashbang.js'),
'\'use strict\'\r\nconsole.log(\'Goodbye, world!\')\r\n'
)
mkdirp.sync(path.join(pkg, 'node_modules'))
fs.writeFileSync(
path.join(pkg, 'package.json'),
JSON.stringify(json, null, 2)
)
return common.npm(['install'], EXEC_OPTS).spread((code) => {
t.equal(code, 0, 'npm install did not raise error code')
t.ok(
existsSync(path.resolve(pkg, 'node_modules/.bin/hashbang')),
'hashbang installed'
)
t.ok(
existsSync(path.resolve(pkg, 'node_modules/.bin/nohashbang')),
'nohashbang installed'
)
t.notOk(
fs.readFileSync(
path.resolve(pkg, 'node_modules/cli-dependency/hashbang.js'),
'utf8'
).includes('\r\n'),
'hashbang dependency cli newlines converted'
)
t.ok(
fs.readFileSync(
path.resolve(pkg, 'node_modules/cli-dependency/nohashbang.js'),
'utf8'
).includes('\r\n'),
'nohashbang dependency cli newlines retained'
)
})
})
test('cleanup', function (t) {
cleanup()
t.end()
})
function cleanup () {
rimraf.sync(pkg)
}