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:
authorRuy Adorno <ruyadorno@hotmail.com>2022-06-02 00:11:16 +0300
committerGitHub <noreply@github.com>2022-06-02 00:11:16 +0300
commitaee6fc857458ac660bf90ecd0af94212c7269fd7 (patch)
tree464eec61f9a60ea2e97d76ffd04f6a886f6b1396 /test
parent66981ecf08b888fde9188c162cc928fff7d6d9d6 (diff)
feat(init): reify on init new workspace (#4892)
Adds a minimalistic reify step that updates the installed tree after initializing a new workspace. Moved the shared update logic from `lib/commands/version.js` to a `lib/workspaces/update-workspaces.js` module that is reused between both `npm version` and `npm init`. Relates to: https://github.com/npm/rfcs/issues/556 Relates to: https://github.com/npm/cli/pull/4588
Diffstat (limited to 'test')
-rw-r--r--test/lib/commands/init.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/lib/commands/init.js b/test/lib/commands/init.js
index 82e7e0524..32816adbc 100644
--- a/test/lib/commands/init.js
+++ b/test/lib/commands/init.js
@@ -288,6 +288,7 @@ t.test('workspaces', t => {
t.teardown(() => {
npm._mockOutputs.length = 0
})
+ npm._mockOutputs.length = 0
npm.localPrefix = t.testdir({
'package.json': JSON.stringify({
name: 'top-level',
@@ -306,6 +307,39 @@ t.test('workspaces', t => {
t.matchSnapshot(npm._mockOutputs, 'should print helper info')
})
+ t.test('post workspace-init reify', async t => {
+ const _consolelog = console.log
+ console.log = () => null
+ t.teardown(() => {
+ console.log = _consolelog
+ npm._mockOutputs.length = 0
+ delete npm.flatOptions.workspacesUpdate
+ })
+ npm.started = Date.now()
+ npm._mockOutputs.length = 0
+ npm.flatOptions.workspacesUpdate = true
+ npm.localPrefix = t.testdir({
+ 'package.json': JSON.stringify({
+ name: 'top-level',
+ }),
+ })
+
+ const Init = t.mock('../../../lib/commands/init.js', {
+ ...mocks,
+ 'init-package-json': (dir, initFile, config, cb) => {
+ t.equal(dir, resolve(npm.localPrefix, 'a'), 'should use the ws path')
+ return require('init-package-json')(dir, initFile, config, cb)
+ },
+ })
+ const init = new Init(npm)
+ await init.execWorkspaces([], ['a'])
+ const output = npm._mockOutputs.map(arr => arr.map(i => i.replace(/[0-9]*ms$/, '100ms')))
+ t.matchSnapshot(output, 'should print helper info')
+ const lockFilePath = resolve(npm.localPrefix, 'package-lock.json')
+ const lockFile = fs.readFileSync(lockFilePath, { encoding: 'utf8' })
+ t.matchSnapshot(lockFile, 'should reify tree on init ws complete')
+ })
+
t.test('no args, existing folder', async t => {
t.teardown(() => {
npm._mockOutputs.length = 0