diff options
author | Gar <gar+gh@danger.computer> | 2021-03-31 01:37:48 +0300 |
---|---|---|
committer | Gar <gar+gh@danger.computer> | 2021-04-01 00:02:08 +0300 |
commit | 32717a60eb55fcf8c7e5016223bfee78a6daba0e (patch) | |
tree | d16c57e3c80280a3d971d3cbf1ff7b9099c10015 /test | |
parent | ec520ce32d5e834a32ebd58491df4200e01ce690 (diff) |
feat(view): add workspace support
PR-URL: https://github.com/npm/cli/pull/3001
Credit: @wraithgar
Close: #3001
Reviewed-by: @nlf
Diffstat (limited to 'test')
-rw-r--r-- | test/lib/view.js | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/test/lib/view.js b/test/lib/view.js index d136a1f41..91ce18786 100644 --- a/test/lib/view.js +++ b/test/lib/view.js @@ -238,6 +238,7 @@ const packument = (nv, opts) => { } t.beforeEach(cleanLogs) + t.test('should log package info', t => { const View = requireInject('../../lib/view.js', { pacote: { @@ -548,6 +549,131 @@ t.test('throws when unpublished', (t) => { }) }) +t.test('workspaces', t => { + t.beforeEach((done) => { + warnMsg = undefined + config.json = false + done() + }) + const testDir = t.testdir({ + 'package.json': JSON.stringify({ + name: 'workspaces-test-package', + version: '1.2.3', + workspaces: ['test-workspace-a', 'test-workspace-b'], + }), + 'test-workspace-a': { + 'package.json': JSON.stringify({ + name: 'green', + version: '1.2.3', + }), + }, + 'test-workspace-b': { + 'package.json': JSON.stringify({ + name: 'orange', + version: '1.2.3', + }), + }, + }) + const View = requireInject('../../lib/view.js', { + pacote: { + packument, + }, + }) + const config = { + tag: 'latest', + } + let warnMsg + const npm = mockNpm({ + log: { + warn: (msg) => { + warnMsg = msg + }, + }, + config, + localPrefix: testDir, + }) + const view = new View(npm) + + t.test('all workspaces', t => { + view.execWorkspaces([], [], (err) => { + t.error(err) + t.matchSnapshot(logs) + t.end() + }) + }) + + t.test('one specific workspace', t => { + view.execWorkspaces([], ['green'], (err) => { + t.error(err) + t.matchSnapshot(logs) + t.end() + }) + }) + + t.test('all workspaces --json', t => { + config.json = true + view.execWorkspaces([], [], (err) => { + t.error(err) + t.matchSnapshot(logs) + t.end() + }) + }) + + t.test('all workspaces single field', t => { + view.execWorkspaces(['.', 'name'], [], (err) => { + t.error(err) + t.matchSnapshot(logs) + t.end() + }) + }) + + t.test('all workspaces nonexistent field', t => { + view.execWorkspaces(['.', 'foo'], [], (err) => { + t.error(err) + t.matchSnapshot(logs) + t.end() + }) + }) + + t.test('all workspaces nonexistent field --json', t => { + config.json = true + view.execWorkspaces(['.', 'foo'], [], (err) => { + t.error(err) + t.matchSnapshot(logs) + t.end() + }) + }) + + t.test('all workspaces single field --json', t => { + config.json = true + view.execWorkspaces(['.', 'name'], [], (err) => { + t.error(err) + t.matchSnapshot(logs) + t.end() + }) + }) + + t.test('single workspace --json', t => { + config.json = true + view.execWorkspaces([], ['green'], (err) => { + t.error(err) + t.matchSnapshot(logs) + t.end() + }) + }) + + t.test('remote package name', t => { + view.execWorkspaces(['pink'], [], (err) => { + t.error(err) + t.matchSnapshot(warnMsg) + t.matchSnapshot(logs) + t.end() + }) + }) + + t.end() +}) + t.test('completion', async t => { const View = requireInject('../../lib/view.js', { pacote: { |