-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tasks): Kill tasks via ctrl-c (#327)
- Loading branch information
Showing
14 changed files
with
524 additions
and
58 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
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
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
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,32 @@ | ||
// Karma configuration file, see link for more information | ||
// https://karma-runner.github.io/1.0/config/configuration-file.html | ||
|
||
module.exports = function (config) { | ||
config.set({ | ||
basePath: '', | ||
frameworks: ['jasmine', '@angular-devkit/build-angular'], | ||
plugins: [ | ||
require('karma-jasmine'), | ||
require('karma-chrome-launcher'), | ||
require('karma-jasmine-html-reporter'), | ||
require('karma-coverage-istanbul-reporter'), | ||
require('@angular-devkit/build-angular/plugins/karma') | ||
], | ||
client: { | ||
clearContext: false // leave Jasmine Spec Runner output visible in browser | ||
}, | ||
coverageIstanbulReporter: { | ||
dir: require('path').join(__dirname, '../../coverage'), | ||
reports: ['html', 'lcovonly'], | ||
fixWebpackSourcePaths: true | ||
}, | ||
failOnEmptyTestSuite: false, | ||
reporters: ['progress', 'kjhtml'], | ||
port: 9876, | ||
colors: true, | ||
logLevel: config.LOG_INFO, | ||
autoWatch: true, | ||
browsers: ['Chrome'], | ||
singleRun: false | ||
}); | ||
}; |
115 changes: 115 additions & 0 deletions
115
libs/feature-action-bar/src/lib/action-bar.component.spec.ts
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,115 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { | ||
CommandStatus, | ||
CommandRunner, | ||
CommandResponse | ||
} from '@angular-console/utils'; | ||
import { ActionBarComponent } from './action-bar.component'; | ||
import { FeatureActionBarModule } from './feature-action-bar.module'; | ||
import { BehaviorSubject, Subject } from 'rxjs'; | ||
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; | ||
|
||
describe('ActionBarComponent', () => { | ||
let component: ActionBarComponent; | ||
let fixture: ComponentFixture<ActionBarComponent>; | ||
let mockCommandRunner: jasmine.SpyObj<CommandRunner>; | ||
let mockCommands: Subject<CommandResponse[]>; | ||
|
||
beforeEach(async(() => { | ||
mockCommands = new Subject<CommandResponse[]>(); | ||
mockCommandRunner = jasmine.createSpyObj<CommandRunner>('CommandRunner', [ | ||
'stopCommandViaCtrlC', | ||
'listAllCommands' | ||
]); | ||
mockCommandRunner.listAllCommands.and.returnValue(mockCommands); | ||
TestBed.configureTestingModule({ | ||
imports: [NoopAnimationsModule, FeatureActionBarModule], | ||
providers: [{ provide: CommandRunner, useValue: mockCommandRunner }] | ||
}).compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(ActionBarComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
describe('ctrl-c', () => { | ||
it('should not kill multiple commands', () => { | ||
const commandResponse: CommandResponse = { | ||
id: 'commandId', | ||
out: '', | ||
outChunk: '', | ||
detailedStatus: {}, | ||
status: CommandStatus.IN_PROGRESS, | ||
command: '' | ||
}; | ||
mockCommands.next([commandResponse, commandResponse]); | ||
|
||
// Dont call if multiple events | ||
document.dispatchEvent( | ||
new KeyboardEvent('keypress', { ctrlKey: true, key: 'c' }) | ||
); | ||
expect(mockCommandRunner.stopCommandViaCtrlC).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should not kill an opened command', () => { | ||
const commandResponse: CommandResponse = { | ||
id: 'commandId', | ||
out: '', | ||
outChunk: '', | ||
detailedStatus: {}, | ||
status: CommandStatus.IN_PROGRESS, | ||
command: '' | ||
}; | ||
mockCommands.next([commandResponse]); | ||
|
||
component.actionsExpanded.next(true); | ||
mockCommands.next([commandResponse]); | ||
document.dispatchEvent( | ||
new KeyboardEvent('keypress', { ctrlKey: true, key: 'c' }) | ||
); | ||
expect(mockCommandRunner.stopCommandViaCtrlC).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should kill a single command', () => { | ||
const commandResponse: CommandResponse = { | ||
id: 'commandId', | ||
out: '', | ||
outChunk: '', | ||
detailedStatus: {}, | ||
status: CommandStatus.IN_PROGRESS, | ||
command: '' | ||
}; | ||
mockCommands.next([commandResponse]); | ||
|
||
document.dispatchEvent( | ||
new KeyboardEvent('keypress', { ctrlKey: true, key: 'c' }) | ||
); | ||
expect(mockCommandRunner.stopCommandViaCtrlC).toHaveBeenCalledWith( | ||
commandResponse.id | ||
); | ||
}); | ||
|
||
it('should only kill running events', () => { | ||
const commandResponse: CommandResponse = { | ||
id: 'commandId', | ||
out: '', | ||
outChunk: '', | ||
detailedStatus: {}, | ||
status: CommandStatus.TERMINATED, | ||
command: '' | ||
}; | ||
mockCommands.next([commandResponse]); | ||
document.dispatchEvent( | ||
new KeyboardEvent('keypress', { ctrlKey: true, key: 'c' }) | ||
); | ||
expect(mockCommandRunner.stopCommandViaCtrlC).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
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
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,22 @@ | ||
// This file is required by karma.conf.js and loads recursively all the .spec and framework files | ||
|
||
import 'core-js/es7/reflect'; | ||
import 'zone.js/dist/zone'; | ||
import 'zone.js/dist/zone-testing'; | ||
import { getTestBed } from '@angular/core/testing'; | ||
import { | ||
BrowserDynamicTestingModule, | ||
platformBrowserDynamicTesting | ||
} from '@angular/platform-browser-dynamic/testing'; | ||
|
||
declare const require: any; | ||
|
||
// First, initialize the Angular testing environment. | ||
getTestBed().initTestEnvironment( | ||
BrowserDynamicTestingModule, | ||
platformBrowserDynamicTesting() | ||
); | ||
// Then we find all the tests. | ||
const context = require.context('./', true, /\.spec\.ts$/); | ||
// And load the modules. | ||
context.keys().map(context); |
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,9 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../dist/out-tsc/libs/feature-action-bar", | ||
"types": ["jasmine", "node"] | ||
}, | ||
"files": ["src/test.ts"], | ||
"include": ["**/*.spec.ts", "**/*.d.ts"] | ||
} |
56 changes: 56 additions & 0 deletions
56
libs/ui/src/lib/command-output/command-output.component.spec.ts
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,56 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { CommandOutputComponent } from './command-output.component'; | ||
import { UiModule } from '../ui.module'; | ||
import { CommandStatus, CommandRunner } from '@angular-console/utils'; | ||
|
||
describe('CommandOutputComponent', () => { | ||
let component: CommandOutputComponent; | ||
let fixture: ComponentFixture<CommandOutputComponent>; | ||
let mockCommandRunner: jasmine.SpyObj<CommandRunner>; | ||
|
||
beforeEach(async(() => { | ||
mockCommandRunner = jasmine.createSpyObj<CommandRunner>('CommandRunner', [ | ||
'stopCommandViaCtrlC' | ||
]); | ||
TestBed.configureTestingModule({ | ||
imports: [UiModule], | ||
providers: [{ provide: CommandRunner, useValue: mockCommandRunner }] | ||
}).compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(CommandOutputComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should kill running commands via ctrl-c', () => { | ||
component.commandResponse = { | ||
id: 'commandId', | ||
out: '', | ||
outChunk: '', | ||
detailedStatus: {}, | ||
status: CommandStatus.IN_PROGRESS, | ||
command: '' | ||
}; | ||
|
||
document.dispatchEvent( | ||
new KeyboardEvent('keypress', { ctrlKey: true, key: 'c' }) | ||
); | ||
|
||
expect(mockCommandRunner.stopCommandViaCtrlC).toHaveBeenCalledWith( | ||
component.commandResponse.id | ||
); | ||
|
||
mockCommandRunner.stopCommandViaCtrlC.calls.reset(); | ||
component.commandResponse.status = CommandStatus.TERMINATED; | ||
document.dispatchEvent( | ||
new KeyboardEvent('keypress', { ctrlKey: true, key: 'c' }) | ||
); | ||
expect(mockCommandRunner.stopCommandViaCtrlC).not.toHaveBeenCalled(); | ||
}); | ||
}); |
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
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
Oops, something went wrong.