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>2021-05-18 21:12:15 +0300
committerisaacs <i@izs.me>2021-05-20 20:37:04 +0300
commit83df3666cd82819230fb45f2a40afd531fe3b3c7 (patch)
treeb5b021f857e718baa07f64c02e731e30ef14e77a /test
parentfde35466915b5ac5958c827fa7e919e1f186db51 (diff)
feat(outdated): add workspaces support
- Add listing outdated direct deps of a workspace in `npm outdated` - Add ability to filter the results of `npm outdated` using `-w` config - Added tests and docs Fixes: https://github.com/npm/statusboard/issues/303 PR-URL: https://github.com/npm/cli/pull/3260 Credit: @ruyadorno Close: #3260 Reviewed-by: @isaacs
Diffstat (limited to 'test')
-rw-r--r--test/lib/outdated.js234
1 files changed, 234 insertions, 0 deletions
diff --git a/test/lib/outdated.js b/test/lib/outdated.js
index f7d572821..462ec0fc6 100644
--- a/test/lib/outdated.js
+++ b/test/lib/outdated.js
@@ -84,6 +84,7 @@ const globalDir = t.testdir({
})
const outdated = (dir, opts) => {
+ logs = ''
const Outdated = t.mock('../../lib/outdated.js', {
pacote: {
packument,
@@ -91,6 +92,7 @@ const outdated = (dir, opts) => {
})
const npm = mockNpm({
...opts,
+ localPrefix: dir,
prefix: dir,
globalDir: `${globalDir}/node_modules`,
output,
@@ -439,3 +441,235 @@ t.test('should skip git specs', t => {
t.end()
})
})
+
+t.test('workspaces', async t => {
+ const testDir = t.testdir({
+ 'package.json': JSON.stringify({
+ name: 'workspaces-project',
+ version: '1.0.0',
+ workspaces: ['packages/*'],
+ dependencies: {
+ dog: '^1.0.0',
+ },
+ }),
+ node_modules: {
+ a: t.fixture('symlink', '../packages/a'),
+ b: t.fixture('symlink', '../packages/b'),
+ c: t.fixture('symlink', '../packages/c'),
+ cat: {
+ 'package.json': JSON.stringify({
+ name: 'cat',
+ version: '1.0.0',
+ dependencies: {
+ dog: '2.0.0',
+ },
+ }),
+ node_modules: {
+ dog: {
+ 'package.json': JSON.stringify({
+ name: 'dog',
+ version: '2.0.0',
+ }),
+ },
+ },
+ },
+ chai: {
+ 'package.json': JSON.stringify({
+ name: 'chai',
+ version: '1.0.0',
+ }),
+ },
+ dog: {
+ 'package.json': JSON.stringify({
+ name: 'dog',
+ version: '1.0.1',
+ }),
+ },
+ foo: {
+ 'package.json': JSON.stringify({
+ name: 'foo',
+ version: '1.0.0',
+ dependencies: {
+ chai: '^1.0.0',
+ },
+ }),
+ },
+ zeta: {
+ 'package.json': JSON.stringify({
+ name: 'zeta',
+ version: '1.0.0',
+ }),
+ },
+ },
+ packages: {
+ a: {
+ 'package.json': JSON.stringify({
+ name: 'a',
+ version: '1.0.0',
+ dependencies: {
+ b: '^1.0.0',
+ cat: '^1.0.0',
+ foo: '^1.0.0',
+ },
+ }),
+ },
+ b: {
+ 'package.json': JSON.stringify({
+ name: 'b',
+ version: '1.0.0',
+ dependencies: {
+ zeta: '^1.0.0',
+ },
+ }),
+ },
+ c: {
+ 'package.json': JSON.stringify({
+ name: 'c',
+ version: '1.0.0',
+ dependencies: {
+ theta: '^1.0.0',
+ },
+ }),
+ },
+ },
+ })
+
+ await new Promise((res, rej) => {
+ outdated(testDir, {}).exec([], err => {
+ if (err)
+ rej(err)
+
+ t.matchSnapshot(logs, 'should display ws outdated deps human output')
+ res()
+ })
+ })
+
+ await new Promise((res, rej) => {
+ outdated(testDir, {
+ config: {
+ json: true,
+ },
+ }).exec([], err => {
+ if (err)
+ rej(err)
+
+ t.matchSnapshot(logs, 'should display ws outdated deps json output')
+ res()
+ })
+ })
+
+ await new Promise((res, rej) => {
+ outdated(testDir, {
+ config: {
+ parseable: true,
+ },
+ }).exec([], err => {
+ if (err)
+ rej(err)
+
+ t.matchSnapshot(logs, 'should display ws outdated deps parseable output')
+ res()
+ })
+ })
+
+ await new Promise((res, rej) => {
+ outdated(testDir, {
+ config: {
+ all: true,
+ },
+ }).exec([], err => {
+ if (err)
+ rej(err)
+
+ t.matchSnapshot(logs, 'should display all dependencies')
+ res()
+ })
+ })
+
+ await new Promise((res, rej) => {
+ outdated(testDir, {
+ color: true,
+ }).exec([], err => {
+ if (err)
+ rej(err)
+
+ t.matchSnapshot(logs, 'should highlight ws in dependend by section')
+ res()
+ })
+ })
+
+ await new Promise((res, rej) => {
+ outdated(testDir, {}).execWorkspaces([], ['a'], err => {
+ if (err)
+ rej(err)
+
+ t.matchSnapshot(logs, 'should display results filtered by ws')
+ res()
+ })
+ })
+
+ await new Promise((res, rej) => {
+ outdated(testDir, {
+ config: {
+ json: true,
+ },
+ }).execWorkspaces([], ['a'], err => {
+ if (err)
+ rej(err)
+
+ t.matchSnapshot(logs, 'should display json results filtered by ws')
+ res()
+ })
+ })
+
+ await new Promise((res, rej) => {
+ outdated(testDir, {
+ config: {
+ parseable: true,
+ },
+ }).execWorkspaces([], ['a'], err => {
+ if (err)
+ rej(err)
+
+ t.matchSnapshot(logs, 'should display parseable results filtered by ws')
+ res()
+ })
+ })
+
+ await new Promise((res, rej) => {
+ outdated(testDir, {
+ config: {
+ all: true,
+ },
+ }).execWorkspaces([], ['a'], err => {
+ if (err)
+ rej(err)
+
+ t.matchSnapshot(logs,
+ 'should display nested deps when filtering by ws and using --all')
+ res()
+ })
+ })
+
+ await new Promise((res, rej) => {
+ outdated(testDir, {}).execWorkspaces([], ['b'], err => {
+ if (err)
+ rej(err)
+
+ t.matchSnapshot(logs,
+ 'should display no results if ws has no deps to display')
+ res()
+ })
+ })
+
+ await new Promise((res, rej) => {
+ outdated(testDir, {}).execWorkspaces([], ['c'], err => {
+ if (err)
+ rej(err)
+
+ t.matchSnapshot(logs,
+ 'should display missing deps when filtering by ws')
+ res()
+ })
+ })
+})