Skip to content

Commit 67dab73

Browse files
committed
test(custom-jar): add unit tests
1 parent 9374ae6 commit 67dab73

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

apps/generator-cli/src/app/services/generator.service.spec.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ describe('GeneratorService', () => {
128128
command: `java -jar "/path/to/4.2.1.jar" generate ${appendix.join(' ')}`,
129129
});
130130

131+
const cmdWithCustomJar = (name: string, customJar: string, appendix: string[]) => ({
132+
name,
133+
command: `java -cp "/path/to/4.2.1.jar:${customJar}" org.openapitools.codegen.OpenAPIGenerator generate ${appendix.join(' ')}`,
134+
});
135+
131136
describe.each([
132137
['foo.json', [
133138
cmd('[angular] abc/app/pet.yaml', [
@@ -183,6 +188,18 @@ describe('GeneratorService', () => {
183188
'--some-bool',
184189
]),
185190
]],
191+
['bar.json', [
192+
cmdWithCustomJar('[bar] api/cat.yaml', '../some/custom.jar', [
193+
`--input-spec="${cwd}/api/cat.yaml"`,
194+
`--output="bar/cat"`,
195+
'--some-bool',
196+
]),
197+
cmdWithCustomJar('[bar] api/bird.json', '../some/custom.jar', [
198+
`--input-spec="${cwd}/api/bird.json"`,
199+
`--output="bar/bird"`,
200+
'--some-bool',
201+
]),
202+
], '../some/custom.jar'],
186203
['none.json', []],
187204
['also-none.json', []],
188205
['no-glob.json', [
@@ -200,13 +217,13 @@ describe('GeneratorService', () => {
200217
`--ext="json"`,
201218
]),
202219
]],
203-
])('%s', (filePath, expectedCommands) => {
220+
])('%s', (filePath, expectedCommands, customGenerator) => {
204221

205222
let returnValue: boolean
206223

207224
beforeEach(async () => {
208225
configGet.mockImplementation((path, defaultValue) => config[filePath] || defaultValue)
209-
returnValue = await fixture.generate()
226+
returnValue = await fixture.generate(customGenerator)
210227
})
211228

212229
it('calls the config get well', () => {

apps/generator-cli/src/app/services/pass-through.service.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,18 @@ describe('PassThroughService', () => {
190190
)
191191
})
192192

193+
if (name === 'generate') {
194+
it('can delegate with custom jar to generate command', async () => {
195+
await program.parseAsync([name, ...argv, '--generator-key=genKey', '--custom-generator=../some/custom.jar'], { from: 'user' })
196+
197+
expect(generate).toHaveBeenNthCalledWith(
198+
1,
199+
'../some/custom.jar',
200+
'genKey'
201+
)
202+
})
203+
}
204+
193205
// if (name === 'help') {
194206
// it('prints the help info and does not delegate, if args length = 0', async () => {
195207
// childProcess.spawn.mockReset()

0 commit comments

Comments
 (0)