|
| 1 | +/* |
| 2 | +Copyright 2019 Adobe Inc. All rights reserved. |
| 3 | +This file is licensed to you under the Apache License, Version 2.0 (the "License"); |
| 4 | +you may not use this file except in compliance with the License. You may obtain a copy |
| 5 | +of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +
|
| 7 | +Unless required by applicable law or agreed to in writing, software distributed under |
| 8 | +the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS |
| 9 | +OF ANY KIND, either express or implied. See the License for the specific language |
| 10 | +governing permissions and limitations under the License. |
| 11 | +*/ |
| 12 | + |
| 13 | +const hook = require('../../../src/hooks/init/AliasHelpHook') |
| 14 | +const { Help } = require('@oclif/core') |
| 15 | + |
| 16 | +describe('AliasHelpHook', () => { |
| 17 | + let exitSpy |
| 18 | + let helpSpy |
| 19 | + |
| 20 | + beforeEach(() => { |
| 21 | + helpSpy = jest.spyOn(Help.prototype, 'showHelp').mockResolvedValue() |
| 22 | + exitSpy = jest.spyOn(process, 'exit').mockImplementation() |
| 23 | + }) |
| 24 | + |
| 25 | + afterEach(() => { |
| 26 | + helpSpy.mockRestore() |
| 27 | + exitSpy.mockRestore() |
| 28 | + }) |
| 29 | + |
| 30 | + test('intercepts rt with help flag', async () => { |
| 31 | + const context = { config: {} } |
| 32 | + const options = { id: 'rt', argv: ['--help'] } |
| 33 | + |
| 34 | + await hook.call(context, options) |
| 35 | + |
| 36 | + expect(helpSpy).toHaveBeenCalledWith(['runtime']) |
| 37 | + expect(exitSpy).toHaveBeenCalledWith(0) |
| 38 | + }) |
| 39 | + |
| 40 | + test('does not intercept runtime with help flag', async () => { |
| 41 | + const context = { config: {} } |
| 42 | + const options = { id: 'runtime', argv: ['--help'] } |
| 43 | + |
| 44 | + await hook.call(context, options) |
| 45 | + |
| 46 | + expect(helpSpy).not.toHaveBeenCalled() |
| 47 | + expect(exitSpy).not.toHaveBeenCalled() |
| 48 | + }) |
| 49 | + |
| 50 | + test('does not intercept rt without help flag', async () => { |
| 51 | + const context = { config: {} } |
| 52 | + const options = { id: 'rt', argv: [] } |
| 53 | + |
| 54 | + await hook.call(context, options) |
| 55 | + |
| 56 | + expect(helpSpy).not.toHaveBeenCalled() |
| 57 | + expect(exitSpy).not.toHaveBeenCalled() |
| 58 | + }) |
| 59 | +}) |
0 commit comments