Skip to content

Commit

Permalink
test(licenses): list licenses for workspace member
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueGreenMagick committed Apr 22, 2024
1 parent 6630c8f commit 0a0eef0
Show file tree
Hide file tree
Showing 9 changed files with 305 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,42 @@ exports[`pnpm licenses: filter outputs: show-packages 1`] = `
"
`;

exports[`pnpm licenses: list all dependencies of workspace: show-packages 1`] = `
"┌─────────────────────────┬─────────┐
│ Package │ License │
├─────────────────────────┼─────────┤
│ @types/ini (dev) │ MIT │
├─────────────────────────┼─────────┤
│ @types/is-windows (dev) │ MIT │
├─────────────────────────┼─────────┤
│ @types/uuid (dev) │ MIT │
├─────────────────────────┼─────────┤
│ @types/which (dev) │ MIT │
├─────────────────────────┼─────────┤
│ ansi-regex │ MIT │
├─────────────────────────┼─────────┤
│ is-positive │ MIT │
├─────────────────────────┼─────────┤
│ wordwrap │ MIT │
└─────────────────────────┴─────────┘
"
`;

exports[`pnpm licenses: list only dependencies of selected workspace member: show-packages 1`] = `
"┌────────────────────┬─────────┐
│ Package │ License │
├────────────────────┼─────────┤
│ @types/which (dev) │ MIT │
├────────────────────┼─────────┤
│ ansi-regex │ MIT │
├────────────────────┼─────────┤
│ is-positive │ MIT │
├────────────────────┼─────────┤
│ wordwrap │ MIT │
└────────────────────┴─────────┘
"
`;

exports[`pnpm licenses: should correctly read LICENSE file with executable file mode: show-packages-details 1`] = `
"┌──────────────────────────────┬─────────┬────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Package │ License │ Details │
Expand Down Expand Up @@ -116,3 +152,14 @@ exports[`pnpm licenses: show-packages 1`] = `
└──────────────────┴────────────┘
"
`;

exports[`pnpm licenses: workspace production dependency: show-packages 1`] = `
"┌─────────────┬─────────┐
│ Package │ License │
├─────────────┼─────────┤
│ is-positive │ MIT │
├─────────────┼─────────┤
│ wordwrap │ MIT │
└─────────────┴─────────┘
"
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "alpha",
"version": "1.0.0",
"dependencies": {
"is-positive": "^3.1.0",
"beta-alias": "workspace:beta@*"
},
"devDependencies": {
"@types/uuid": "^9.0.8",
"gamma": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "beta",
"version": "1.0.0",
"dependencies": {
"is-positive": "^3.1.0",
"delta": "workspace:delta"
},
"devDependencies": {
"@types/which": "^3.0.3",
"gamma": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "delta",
"version": "1.0.0",
"dependencies": {
"wordwrap": "^1.0.0"
},
"devDependencies": {
"@types/is-windows": "^1.0.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "gamma",
"version": "1.0.0",
"dependencies": {
"ansi-regex": "^6.0.1"
},
"devDependencies": {
"@types/ini": "^1.3.31"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "workspace-dependency",
"version": "1.0.0",
"private": true
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
packages:
- alpha
- beta
- gamma
- delta
102 changes: 102 additions & 0 deletions reviewing/plugin-commands-licenses/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,105 @@ test('pnpm licenses should work git repository name containing capital letters',

expect(exitCode).toBe(0)
})

test('pnpm licenses: list only dependencies of selected workspace member', async () => {
const workspaceDir = tempDir()
f.copy('workspace-dependency', workspaceDir)

const { allProjects, allProjectsGraph, selectedProjectsGraph } =
await readProjects(workspaceDir, [])

const storeDir = path.join(workspaceDir, 'store')
await install.handler({
...DEFAULT_OPTS,
dir: workspaceDir,
workspaceDir,
lockfileDir: workspaceDir,
pnpmHomeDir: '',
storeDir,
allProjects,
allProjectsGraph,
selectedProjectsGraph,
})

const betaPackageDir = path.join(workspaceDir, 'beta')
const { output, exitCode } = await licenses.handler({
...DEFAULT_OPTS,
dir: betaPackageDir,
lockfileDir: workspaceDir,
pnpmHomeDir: '',
long: false,
storeDir: path.resolve(storeDir, 'v3'),
}, ['list'])

expect(exitCode).toBe(0)
expect(stripAnsi(output)).toMatchSnapshot('show-packages')
})

test('pnpm licenses: workspace production dependency', async () => {
const workspaceDir = tempDir()
f.copy('workspace-dependency', workspaceDir)

const { allProjects, allProjectsGraph, selectedProjectsGraph } =
await readProjects(workspaceDir, [])

const storeDir = path.join(workspaceDir, 'store')
await install.handler({
...DEFAULT_OPTS,
dir: workspaceDir,
workspaceDir,
lockfileDir: workspaceDir,
pnpmHomeDir: '',
storeDir,
allProjects,
allProjectsGraph,
selectedProjectsGraph,
})

const alphaPackageDir = path.join(workspaceDir, 'alpha')
const { output, exitCode } = await licenses.handler({
...DEFAULT_OPTS,
dir: alphaPackageDir,
lockfileDir: workspaceDir,
pnpmHomeDir: '',
long: false,
storeDir: path.resolve(storeDir, 'v3'),
dev: false,
}, ['list'])

expect(exitCode).toBe(0)
expect(stripAnsi(output)).toMatchSnapshot('show-packages')
})

test('pnpm licenses: list all dependencies of workspace', async () => {
const workspaceDir = tempDir()
f.copy('workspace-dependency', workspaceDir)

const { allProjects, allProjectsGraph, selectedProjectsGraph } =
await readProjects(workspaceDir, [])

const storeDir = path.join(workspaceDir, 'store')
await install.handler({
...DEFAULT_OPTS,
dir: workspaceDir,
workspaceDir,
lockfileDir: workspaceDir,
pnpmHomeDir: '',
storeDir,
allProjects,
allProjectsGraph,
selectedProjectsGraph,
})

const { output, exitCode } = await licenses.handler({
...DEFAULT_OPTS,
dir: workspaceDir,
lockfileDir: workspaceDir,
pnpmHomeDir: '',
long: false,
storeDir: path.resolve(storeDir, 'v3'),
}, ['list'])

expect(exitCode).toBe(0)
expect(stripAnsi(output)).toMatchSnapshot('show-packages')
})

0 comments on commit 0a0eef0

Please sign in to comment.