aboutsummaryrefslogtreecommitdiff
path: root/deps/npm/test/tap/init-create.js
diff options
context:
space:
mode:
authorRebecca Turner <me@re-becca.org>2018-04-20 18:26:37 -0700
committerRebecca Turner <me@re-becca.org>2018-05-24 23:24:45 -0700
commit468ab4519e1b92473acefb22801497a1af6aebae (patch)
treebdac1d062cd4b094bde3a21147bab5d82c792ece /deps/npm/test/tap/init-create.js
parentac8226115e2192a7a46ba07789fa5136f74223e1 (diff)
downloadandroid-node-v8-468ab4519e1b92473acefb22801497a1af6aebae.tar.gz
android-node-v8-468ab4519e1b92473acefb22801497a1af6aebae.tar.bz2
android-node-v8-468ab4519e1b92473acefb22801497a1af6aebae.zip
deps: upgrade npm to 6.1.0
PR-URL: https://github.com/nodejs/node/pull/20190 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Diffstat (limited to 'deps/npm/test/tap/init-create.js')
-rw-r--r--deps/npm/test/tap/init-create.js171
1 files changed, 171 insertions, 0 deletions
diff --git a/deps/npm/test/tap/init-create.js b/deps/npm/test/tap/init-create.js
new file mode 100644
index 0000000000..22d9090a97
--- /dev/null
+++ b/deps/npm/test/tap/init-create.js
@@ -0,0 +1,171 @@
+/* eslint-disable standard/no-callback-literal */
+var test = require('tap').test
+var requireInject = require('require-inject')
+
+var npm = require('../../lib/npm.js')
+
+test('npm init <name>', function (t) {
+ var initJsonMock = function () {
+ t.ok(false, 'should not run initJson()')
+ }
+ initJsonMock.yes = function () {
+ t.ok(false, 'should not run initJson.yes()')
+ return false
+ }
+ var libnpxMock = function () {
+ return Promise.resolve()
+ }
+ libnpxMock.parseArgs = function (argv, defaultNpm) {
+ t.ok(argv[0].includes('node'), 'node is the first arg')
+ t.equals(argv[2], '--always-spawn', 'set npx opts.alwaysSpawn')
+ t.equals(argv[3], 'create-name', 'expands name')
+ t.ok(defaultNpm.endsWith('npm-cli.js'), 'passes npm bin path')
+ }
+
+ npm.load({ loglevel: 'silent' }, function () {
+ var init = requireInject('../../lib/init', {
+ 'init-package-json': initJsonMock,
+ 'libnpx': libnpxMock
+ })
+
+ init(['name'], function () {})
+
+ t.end()
+ })
+})
+
+test('npm init expands scopes', function (t) {
+ var libnpxMock = function () {
+ return Promise.resolve()
+ }
+
+ npm.load({ loglevel: 'silent' }, function () {
+ var init = requireInject('../../lib/init', {
+ 'libnpx': libnpxMock
+ })
+
+ libnpxMock.parseArgs = function (argv) {
+ t.equals(argv[3], '@scope/create', 'expands @scope')
+ }
+
+ init(['@scope'], function () {})
+
+ libnpxMock.parseArgs = function (argv) {
+ t.equals(argv[3], '@scope/create-name', 'expands @scope/name')
+ }
+
+ init(['@scope/name'], function () {})
+
+ t.end()
+ })
+})
+
+test('npm init expands version names', function (t) {
+ var libnpxMock = function () {
+ return Promise.resolve()
+ }
+
+ npm.load({ loglevel: 'silent' }, function () {
+ var init = requireInject('../../lib/init', {
+ 'libnpx': libnpxMock
+ })
+
+ libnpxMock.parseArgs = function (argv) {
+ t.equals(argv[3], 'create-name@1.2.3', 'expands name@1.2.3')
+ }
+
+ init(['name@1.2.3'], function () {})
+
+ libnpxMock.parseArgs = function (argv) {
+ t.equals(argv[3], 'create-name@^1.2.3', 'expands name@^1.2.3')
+ }
+
+ init(['name@^1.2.3'], function () {})
+
+ t.end()
+ })
+})
+
+test('npm init expands git names', function (t) {
+ var libnpxMock = function () {
+ return Promise.resolve()
+ }
+
+ npm.load({ loglevel: 'silent' }, function () {
+ var init = requireInject('../../lib/init', {
+ 'libnpx': libnpxMock
+ })
+
+ libnpxMock.parseArgs = function (argv) {
+ t.equals(argv[3], 'user/create-foo', 'expands git repo')
+ }
+
+ init(['user/foo'], function () {})
+
+ libnpxMock.parseArgs = function (argv) {
+ t.equals(argv[3], 'git+https://github.com/user/create-foo', 'expands git url')
+ }
+
+ init(['git+https://github.com/user/foo'], function () {})
+
+ t.end()
+ })
+})
+
+test('npm init errors on folder and tarballs', function (t) {
+ npm.load({ loglevel: 'silent' }, function () {
+ var init = require('../../lib/init')
+
+ try {
+ init(['../foo/bar/'], function () {})
+ } catch (e) {
+ t.equals(e.code, 'EUNSUPPORTED')
+ }
+
+ t.throws(
+ () => init(['../foo/bar/'], function () {}),
+ /Unrecognized initializer: \.\.\/foo\/bar\//
+ )
+
+ t.throws(
+ () => init(['file:foo.tar.gz'], function () {}),
+ /Unrecognized initializer: file:foo\.tar\.gz/
+ )
+
+ t.throws(
+ () => init(['http://x.com/foo.tgz'], function () {}),
+ /Unrecognized initializer: http:\/\/x\.com\/foo\.tgz/
+ )
+
+ t.end()
+ })
+})
+
+test('npm init forwards arguments', function (t) {
+ var libnpxMock = function () {
+ return Promise.resolve()
+ }
+
+ npm.load({ loglevel: 'silent' }, function () {
+ var origArgv = process.argv
+ var init = requireInject('../../lib/init', {
+ 'libnpx': libnpxMock
+ })
+
+ libnpxMock.parseArgs = function (argv) {
+ process.argv = origArgv
+ t.same(argv.slice(4), ['a', 'b', 'c'])
+ }
+ process.argv = [
+ process.argv0,
+ 'NPM_CLI_PATH',
+ 'init',
+ 'name',
+ 'a', 'b', 'c'
+ ]
+
+ init(['name'], function () {})
+
+ t.end()
+ })
+})