-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
init: use npx for extended initializers (#20303)
PR-URL: npm/npm#20303 Credit: @jdalton Reviewed-By: @zkat
- Loading branch information
Showing
4 changed files
with
111 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* 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 <pkg-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-pkg-name', 'expands pkg-name') | ||
t.ok(defaultNpm.endsWith('npm-cli.js'), 'passes npx bin path') | ||
} | ||
|
||
npm.load({ loglevel: 'silent' }, function () { | ||
var init = requireInject('../../lib/init', { | ||
'init-package-json': initJsonMock, | ||
'libnpx': libnpxMock | ||
}) | ||
|
||
init(['pkg-name'], function () {}) | ||
|
||
t.end() | ||
}) | ||
}) | ||
|
||
test('npm init with scoped packages', 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-pkg-name', 'expands @scope/pkg-name') | ||
} | ||
|
||
init(['@scope/pkg-name'], function () {}) | ||
|
||
t.end() | ||
}) | ||
}) |