mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-27 11:31:45 -04:00
- Rename `installing/core` → `installing/deps-installer` and `installing/headless` → `installing/deps-restorer` for clearer naming
- Rename all `plugin-commands-*` directories to use `-commands` suffix convention
- Merge multiple command packages per domain into a single `commands/` directory (one commands package per domain rule):
- `building/{build-commands,policy-commands}` → `building/commands`
- `deps/compliance/{audit-commands,licenses-commands,sbom-commands}` → `deps/compliance/commands`
- `deps/inspection/{listing-commands,outdated-commands}` → `deps/inspection/commands`
- `store/{store-commands,inspecting-commands}` → `store/commands`
- `releasing/{publish-commands,deploy-commands}` → `releasing/commands`
- `cli/{completion-commands,doctor-commands}` → `cli/commands`
- `engine/pm/{self-updater-commands,setup-commands}` → `engine/pm/commands`
- `engine/runtime/{runtime-commands,env-commands}` → `engine/runtime/commands`
- `cache/cache-commands` → `cache/commands`
- Fix relative paths in merged test files (pnpmBin, __typings__ references)
- Update jest config to ignore `utils/` dirs at any nesting depth under `test/`
- Fix stale package names in changeset files
212 lines
4.3 KiB
TypeScript
212 lines
4.3 KiB
TypeScript
import { complete } from '../../src/completion/complete.js'
|
|
|
|
test('complete an option value', async () => {
|
|
const completions = await complete(
|
|
{
|
|
cliOptionsTypesByCommandName: {
|
|
install: () => ({
|
|
'resolution-strategy': ['fast', 'fewer-dependencies'],
|
|
}),
|
|
},
|
|
completionByCommandName: {},
|
|
initialCompletion: () => [],
|
|
shorthandsByCommandName: {},
|
|
universalOptionsTypes: {},
|
|
universalShorthands: {},
|
|
},
|
|
{
|
|
cmd: 'install',
|
|
currentTypedWordType: null,
|
|
lastOption: '--resolution-strategy',
|
|
options: {},
|
|
params: [],
|
|
}
|
|
)
|
|
expect(completions).toStrictEqual([
|
|
{ name: 'fast' },
|
|
{ name: 'fewer-dependencies' },
|
|
])
|
|
})
|
|
|
|
test('complete a command', async () => {
|
|
const ctx = {
|
|
cliOptionsTypesByCommandName: {
|
|
run: () => ({
|
|
'if-present': Boolean,
|
|
}),
|
|
},
|
|
completionByCommandName: {
|
|
run: async () => [{ name: 'test' }],
|
|
},
|
|
initialCompletion: () => [],
|
|
shorthandsByCommandName: {},
|
|
universalOptionsTypes: {
|
|
filter: String,
|
|
},
|
|
universalShorthands: {},
|
|
}
|
|
expect(
|
|
await complete(ctx,
|
|
{
|
|
cmd: 'run',
|
|
currentTypedWordType: 'value',
|
|
lastOption: null,
|
|
options: {},
|
|
params: [],
|
|
}
|
|
)
|
|
).toStrictEqual(
|
|
[{ name: 'test' }]
|
|
)
|
|
expect(
|
|
await complete(ctx,
|
|
{
|
|
cmd: 'run',
|
|
currentTypedWordType: null,
|
|
lastOption: null,
|
|
options: {},
|
|
params: [],
|
|
}
|
|
)
|
|
).toStrictEqual(
|
|
[
|
|
{ name: 'test' },
|
|
{ name: '--filter' },
|
|
{ name: '--if-present' },
|
|
{ name: '--no-if-present' },
|
|
]
|
|
)
|
|
expect(
|
|
await complete(ctx,
|
|
{
|
|
cmd: 'run',
|
|
currentTypedWordType: 'option',
|
|
lastOption: null,
|
|
options: {},
|
|
params: [],
|
|
}
|
|
)
|
|
).toStrictEqual(
|
|
[
|
|
{ name: '--filter' },
|
|
{ name: '--if-present' },
|
|
{ name: '--no-if-present' },
|
|
]
|
|
)
|
|
})
|
|
|
|
test('if command completion fails, return empty array', async () => {
|
|
expect(
|
|
await complete(
|
|
{
|
|
cliOptionsTypesByCommandName: {},
|
|
completionByCommandName: {
|
|
run: async () => {
|
|
throw new Error('error')
|
|
},
|
|
},
|
|
initialCompletion: () => [],
|
|
shorthandsByCommandName: {},
|
|
universalOptionsTypes: {
|
|
filter: String,
|
|
},
|
|
universalShorthands: {},
|
|
},
|
|
{
|
|
cmd: 'run',
|
|
currentTypedWordType: 'value',
|
|
lastOption: null,
|
|
options: {},
|
|
params: [],
|
|
}
|
|
)
|
|
).toStrictEqual(
|
|
[]
|
|
)
|
|
})
|
|
|
|
test('initial completion', async () => {
|
|
const ctx = {
|
|
cliOptionsTypesByCommandName: {},
|
|
completionByCommandName: {},
|
|
initialCompletion: () => [
|
|
{ name: 'add' },
|
|
{ name: 'install' },
|
|
],
|
|
shorthandsByCommandName: {},
|
|
universalOptionsTypes: {
|
|
filter: String,
|
|
},
|
|
universalShorthands: {},
|
|
}
|
|
expect(
|
|
await complete(ctx,
|
|
{
|
|
cmd: null,
|
|
currentTypedWordType: null,
|
|
lastOption: null,
|
|
options: {},
|
|
params: [],
|
|
}
|
|
)
|
|
).toStrictEqual([
|
|
{ name: 'add' },
|
|
{ name: 'install' },
|
|
{ name: '--filter' },
|
|
{ name: '--version' },
|
|
])
|
|
expect(
|
|
await complete(ctx,
|
|
{
|
|
cmd: 'ad',
|
|
currentTypedWordType: 'value',
|
|
lastOption: null,
|
|
options: {},
|
|
params: [],
|
|
}
|
|
)
|
|
).toStrictEqual([
|
|
{ name: 'add' },
|
|
{ name: 'install' },
|
|
])
|
|
expect(
|
|
await complete(ctx,
|
|
{
|
|
cmd: null,
|
|
currentTypedWordType: 'option',
|
|
lastOption: null,
|
|
options: {},
|
|
params: [],
|
|
}
|
|
)
|
|
).toStrictEqual([
|
|
{ name: '--filter' },
|
|
{ name: '--version' },
|
|
])
|
|
})
|
|
|
|
test('suggest no completions for after --version', async () => {
|
|
expect(
|
|
await complete(
|
|
{
|
|
cliOptionsTypesByCommandName: {},
|
|
completionByCommandName: {},
|
|
initialCompletion: () => [
|
|
{ name: 'add' },
|
|
{ name: 'install' },
|
|
],
|
|
shorthandsByCommandName: {},
|
|
universalOptionsTypes: {},
|
|
universalShorthands: {},
|
|
},
|
|
{
|
|
cmd: null,
|
|
currentTypedWordType: null,
|
|
lastOption: null,
|
|
options: { version: true },
|
|
params: [],
|
|
}
|
|
)
|
|
).toStrictEqual([])
|
|
})
|