Skip to content

Commit

Permalink
fix: 🐛 issue with graceful closing the process
Browse files Browse the repository at this point in the history
When a user requests to quit the presentation, it used process.exit()
which is not a best way to do that. This commit replaces it with
process.stdin.pause() so it can gracefully shutdown and exit the process
because there are no more listeners to handle.
  • Loading branch information
ghaiklor committed Mar 24, 2020
1 parent bd38e0b commit 268dccf
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 38 deletions.
5 changes: 2 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest (Current File)",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"runtimeExecutable": "~/.config/nvm/13.11.0/bin/node",
"console": "integratedTerminal",
"args": [
"${relativeFile}",
"--coverage",
Expand Down
76 changes: 42 additions & 34 deletions src/kittik-deck/spec/Deck.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,59 @@ import { Deck, DeckDeclaration } from '../src/Deck';

const DECK_DECLARATION: DeckDeclaration = {
cursor: Canvas.create(),
shapes: [{
name: 'Global Shape',
type: 'Text',
options: {
text: 'Hello, World!'
shapes: [
{
name: 'Global Shape',
type: 'Text',
options: {
text: 'Hello, World!'
}
}
}],
animations: [{
name: 'Global Animation',
type: 'Print',
options: {
duration: 1
],
animations: [
{
name: 'Global Animation',
type: 'Print',
options: {
duration: 1
}
}
}],
slides: [{
shapes: [],
order: [{
shape: 'Global Shape',
animations: [
'Global Animation'
]
}]
}]
],
slides: [
{
shapes: [],
order: [{
shape: 'Global Shape',
animations: [
'Global Animation'
]
}]
},
{
shapes: [],
order: [{
shape: 'Global Shape',
animations: [
'Global Animation'
]
}]
}
]
};

describe.skip('Deck', () => {
it('Should properly render next slide', async () => {
describe('Deck', () => {
it('Should properly render next and previous slides', async () => {
const deck = new Deck(DECK_DECLARATION);
const renderSpy = jest.spyOn(deck, 'renderSlide').mockResolvedValue();

await deck.nextSlide();
deck.exit();

expect(renderSpy).toBeCalledTimes(1);
expect(renderSpy).toBeCalledWith(0);
});

it('Should properly render previous slide', async () => {
const deck = new Deck(DECK_DECLARATION);
const renderSpy = jest.spyOn(deck, 'renderSlide').mockResolvedValue();

await deck.nextSlide();
await deck.previousSlide();
await deck.previousSlide();
deck.exit();

expect(renderSpy).toBeCalledTimes(1);
expect(renderSpy).toBeCalledTimes(2);
expect(renderSpy).toBeCalledWith(0);
expect(renderSpy).toBeCalledWith(1);
});
});
3 changes: 2 additions & 1 deletion src/kittik-deck/src/Deck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ export class Deck {
}

exit(): void {
process.stdin.pause();

this.cursor.showCursor().restoreScreen().reset();
process.stdin.removeAllListeners();
}
}

0 comments on commit 268dccf

Please sign in to comment.