Skip to content

Commit

Permalink
✅ Import mockProcessExit from jest-mock-process.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaditmshah committed Sep 29, 2022
1 parent 6b05751 commit 3237e0a
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions test/commands/commit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import inquirer from 'inquirer'
import { execa } from 'execa'
import fs from 'fs'
import chalk from 'chalk'
const mockProcess = require('jest-mock-process')
import { mockProcessExit } from 'jest-mock-process'

import configurationVault from '@utils/configurationVault'
import getDefaultCommitContent from '@utils/getDefaultCommitContent'
Expand Down Expand Up @@ -162,7 +162,7 @@ describe('commit command', () => {
Promise.resolve(stubs.clientCommitAnswers)
)
getEmojis.mockResolvedValue(stubs.gitmojis)
mockProcess.mockProcessExit()
mockProcessExit()
process.argv[3] = stubs.argv
process.argv[COMMIT_MESSAGE_SOURCE] = undefined
getDefaultCommitContent.mockReturnValueOnce(
Expand Down Expand Up @@ -192,7 +192,7 @@ describe('commit command', () => {
Promise.resolve(stubs.clientCommitAnswersWithScope)
)
getEmojis.mockResolvedValue(stubs.gitmojis)
mockProcess.mockProcessExit()
mockProcessExit()
process.argv[3] = stubs.argv
process.argv[COMMIT_MESSAGE_SOURCE] = stubs.commitSource
getDefaultCommitContent.mockReturnValueOnce(
Expand Down Expand Up @@ -223,7 +223,7 @@ describe('commit command', () => {
Simulation needed because if we just mock process exit, then the code execution resume in the test.
*/
process.argv[COMMIT_MESSAGE_SOURCE] = stubs.commitSource
mockProcess.mockProcessExit(new Error('ProcessExit0'))
mockProcessExit(new Error('ProcessExit0'))
execa.mockReturnValueOnce(Promise.resolve(stubs.gitAbsoluteDir))
// mock that we found one of the rebase trigger (file existence in .git)
fs.existsSync.mockReturnValueOnce(true)
Expand All @@ -245,7 +245,7 @@ describe('commit command', () => {
when the hook mode detect that the user is rebasing. (Simulated to not kill the tests)
Simulation needed because if we just mock process exit, then the code execution resume in the test.
*/
mockProcess.mockProcessExit(new Error('ProcessExit0'))
mockProcessExit(new Error('ProcessExit0'))
execa.mockReturnValueOnce(Promise.resolve(stubs.gitAbsoluteDir))
// mock that we are amending
process.argv[COMMIT_MESSAGE_SOURCE] = 'commit sha123'
Expand Down Expand Up @@ -282,7 +282,7 @@ describe('commit command', () => {
getEmojis.mockResolvedValue(stubs.gitmojis)

// Use an exception to suspend code execution to simulate process.exit
mockProcess.mockProcessExit(new Error('SIGINT'))
mockProcessExit(new Error('SIGINT'))
process.argv[3] = stubs.argv
process.argv[COMMIT_MESSAGE_SOURCE] = stubs.commitSource

Expand All @@ -303,7 +303,7 @@ describe('commit command', () => {

describe('with git auto merge trigger by git pull', () => {
it('should cancel the hook', async () => {
mockProcess.mockProcessExit(new Error('ProcessExit0'))
mockProcessExit(new Error('ProcessExit0'))
execa.mockReturnValueOnce(Promise.resolve(stubs.gitAbsoluteDir))
// mock that we are merging
process.argv[3] = '.git/MERGE_MSG'
Expand All @@ -318,7 +318,6 @@ describe('commit command', () => {
expect(process.exit).toHaveBeenCalledWith(0)
})
})

})

describe('guard', () => {
Expand Down

0 comments on commit 3237e0a

Please sign in to comment.