-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): sort --help output by flag priority (#14869)
(cherry picked from commit 20b66fc)
- Loading branch information
1 parent
385934c
commit ff2c50c
Showing
2 changed files
with
110 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { Schema } from './params'; | ||
import { logger } from './logger'; | ||
import { printHelp } from './print-help'; | ||
|
||
describe('printHelp', () => { | ||
it('should sort options by priority and name', () => { | ||
const schema: Schema = { | ||
properties: { | ||
aImp: { | ||
'x-priority': 'important', | ||
}, | ||
bImp: { | ||
'x-priority': 'important', | ||
}, | ||
aNormal: {}, | ||
bNormal: {}, | ||
aDep: { | ||
'x-deprecated': 'great reason', | ||
}, | ||
bDep: { | ||
'x-deprecated': 'even better reason', | ||
}, | ||
aReq: {}, | ||
bReq: {}, | ||
aInt: { | ||
'x-priority': 'internal', | ||
}, | ||
bInt: { | ||
'x-priority': 'internal', | ||
}, | ||
}, | ||
required: ['aReq', 'bReq'], | ||
description: 'description', | ||
}; | ||
|
||
let output = ''; | ||
jest.spyOn(logger, 'info').mockImplementation((x) => (output = x)); | ||
|
||
printHelp('nx g @nrwl/demo:example', schema, { | ||
mode: 'generate', | ||
plugin: '@nrwl/demo', | ||
entity: 'example', | ||
aliases: ['ex'], | ||
}); | ||
|
||
const flagsFromOutput = output | ||
.match(/--[a|b]\S*/g) | ||
.map((x) => x.replace('--', '')); | ||
|
||
expect(flagsFromOutput).toMatchInlineSnapshot(` | ||
Array [ | ||
"aReq", | ||
"bReq", | ||
"aImp", | ||
"bImp", | ||
"aNormal", | ||
"bNormal", | ||
"aInt", | ||
"bInt", | ||
"aDep", | ||
"bDep", | ||
] | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters