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:
authorGar <gar+gh@danger.computer>2021-04-06 18:28:36 +0300
committerGar <gar+gh@danger.computer>2021-04-08 20:27:43 +0300
commit6e31df4e7957337962fd3d93e495931e3592bb9e (patch)
tree7e8d514f2fb149d4ec0bec5cbe21ee381f0ee0c7 /test
parent1f3e88ebaf4901d8f9f07b43404d824fef7e5ff5 (diff)
feat(pack): add workspace support
PR-URL: https://github.com/npm/cli/pull/3033 Credit: @wraithgar Close: #3033 Reviewed-by: @darcyclarke
Diffstat (limited to 'test')
-rw-r--r--test/fixtures/mock-npm.js14
-rw-r--r--test/lib/pack.js103
2 files changed, 117 insertions, 0 deletions
diff --git a/test/fixtures/mock-npm.js b/test/fixtures/mock-npm.js
index c47758111..01f482bde 100644
--- a/test/fixtures/mock-npm.js
+++ b/test/fixtures/mock-npm.js
@@ -2,10 +2,24 @@
// npm.config You still need a separate flatOptions but this is the first step
// to eventually just using npm itself
+const mockLog = {
+ clearProgress: () => {},
+ disableProgress: () => {},
+ enableProgress: () => {},
+ http: () => {},
+ info: () => {},
+ levels: [],
+ notice: () => {},
+ pause: () => {},
+ silly: () => {},
+ verbose: () => {},
+ warn: () => {},
+}
const mockNpm = (base = {}) => {
const config = base.config || {}
const flatOptions = base.flatOptions || {}
return {
+ log: mockLog,
...base,
flatOptions,
config: {
diff --git a/test/lib/pack.js b/test/lib/pack.js
index a5163acfd..4bcfe8ae3 100644
--- a/test/lib/pack.js
+++ b/test/lib/pack.js
@@ -1,6 +1,7 @@
const t = require('tap')
const requireInject = require('require-inject')
const mockNpm = require('../fixtures/mock-npm')
+const pacote = require('pacote')
const OUTPUT = []
const output = (...msg) => OUTPUT.push(msg)
@@ -11,6 +12,16 @@ const libnpmpack = async (spec, opts) => {
return ''
}
+const mockPacote = {
+ manifest: (spec) => {
+ if (spec.type === 'directory')
+ return pacote.manifest(spec)
+ return {
+ name: spec.name || 'test-package',
+ version: spec.version || '1.0.0-test',
+ }
+ },
+}
t.afterEach(cb => {
OUTPUT.length = 0
@@ -152,3 +163,95 @@ t.test('should log pack contents', (t) => {
t.end()
})
})
+
+t.test('workspaces', (t) => {
+ const testDir = t.testdir({
+ 'package.json': JSON.stringify({
+ name: 'workspaces-test',
+ version: '1.0.0',
+ workspaces: ['workspace-a', 'workspace-b'],
+ }, null, 2),
+ 'workspace-a': {
+ 'package.json': JSON.stringify({
+ name: 'workspace-a',
+ version: '1.0.0',
+ }),
+ },
+ 'workspace-b': {
+ 'package.json': JSON.stringify({
+ name: 'workspace-b',
+ version: '1.0.0',
+ }),
+ },
+ })
+ const Pack = requireInject('../../lib/pack.js', {
+ libnpmpack,
+ pacote: mockPacote,
+ npmlog: {
+ notice: () => {},
+ showProgress: () => {},
+ clearProgress: () => {},
+ },
+ })
+ const npm = mockNpm({
+ localPrefix: testDir,
+ config: {
+ unicode: false,
+ json: false,
+ 'dry-run': false,
+ },
+ output,
+ })
+ const pack = new Pack(npm)
+
+ t.test('all workspaces', (t) => {
+ pack.execWorkspaces([], [], er => {
+ if (er)
+ throw er
+
+ t.strictSame(OUTPUT, [
+ ['workspace-a-1.0.0.tgz'],
+ ['workspace-b-1.0.0.tgz'],
+ ])
+ t.end()
+ })
+ })
+
+ t.test('all workspaces, `.` first arg', (t) => {
+ pack.execWorkspaces(['.'], [], er => {
+ if (er)
+ throw er
+
+ t.strictSame(OUTPUT, [
+ ['workspace-a-1.0.0.tgz'],
+ ['workspace-b-1.0.0.tgz'],
+ ])
+ t.end()
+ })
+ })
+
+ t.test('one workspace', (t) => {
+ pack.execWorkspaces([], ['workspace-a'], er => {
+ if (er)
+ throw er
+
+ t.strictSame(OUTPUT, [
+ ['workspace-a-1.0.0.tgz'],
+ ])
+ t.end()
+ })
+ })
+
+ t.test('specific package', (t) => {
+ pack.execWorkspaces(['abbrev'], [], er => {
+ if (er)
+ throw er
+
+ t.strictSame(OUTPUT, [
+ ['abbrev-1.0.0-test.tgz'],
+ ])
+ t.end()
+ })
+ })
+ t.end()
+})