mirror of
https://github.com/hanzoai/lint-staged.git
synced 2026-10-30 19:37:36 +00:00
146 lines
3.7 KiB
JavaScript
146 lines
3.7 KiB
JavaScript
import { describe, it } from 'vitest'
|
|
|
|
import {
|
|
cleanupSkipped,
|
|
getInitialState,
|
|
restoreOriginalStateEnabled,
|
|
restoreOriginalStateSkipped,
|
|
restoreUnstagedChangesSkipped,
|
|
updateIndexSkipped,
|
|
} from '../../lib/state.js'
|
|
import {
|
|
GitError,
|
|
RestoreOriginalStateError,
|
|
RestoreUnstagedChangesError,
|
|
TaskError,
|
|
} from '../../lib/symbols.js'
|
|
|
|
describe('updateIndexSkipped', () => {
|
|
it('should return false when reverting is disabled', ({ expect }) => {
|
|
const state = getInitialState()
|
|
const result = updateIndexSkipped({
|
|
...state,
|
|
shouldRevert: false,
|
|
})
|
|
|
|
expect(result).toEqual(false)
|
|
})
|
|
|
|
it('should return false when backup is disabled', ({ expect }) => {
|
|
const state = getInitialState()
|
|
const result = updateIndexSkipped({
|
|
...state,
|
|
shouldBackup: false,
|
|
})
|
|
|
|
expect(result).toEqual(false)
|
|
})
|
|
|
|
it('should return error message when there is an unknown git error', ({ expect }) => {
|
|
const state = getInitialState()
|
|
const result = updateIndexSkipped({
|
|
...state,
|
|
shouldBackup: true,
|
|
errors: new Set([GitError]),
|
|
})
|
|
|
|
expect(typeof result === 'string').toEqual(true)
|
|
})
|
|
})
|
|
|
|
describe('restoreUnstagedChangesSkipped', () => {
|
|
it('should return error message when there is an unknown git error', ({ expect }) => {
|
|
const state = getInitialState()
|
|
const result = restoreUnstagedChangesSkipped({
|
|
...state,
|
|
errors: new Set([GitError]),
|
|
})
|
|
|
|
expect(typeof result === 'string').toEqual(true)
|
|
})
|
|
})
|
|
|
|
describe('restoreOriginalStateEnabled', () => {
|
|
it('should return false by default', ({ expect }) => {
|
|
const state = getInitialState()
|
|
const result = restoreOriginalStateEnabled({
|
|
...state,
|
|
})
|
|
|
|
expect(result).toEqual(false)
|
|
})
|
|
|
|
it('should return true when backup enabled and there are task errors', ({ expect }) => {
|
|
const state = getInitialState()
|
|
const result = restoreOriginalStateEnabled({
|
|
...state,
|
|
shouldBackup: true,
|
|
errors: new Set([TaskError]),
|
|
})
|
|
|
|
expect(result).toEqual(true)
|
|
})
|
|
|
|
it('should return true when backup enabled and unstaged changes failed to restore', ({
|
|
expect,
|
|
}) => {
|
|
const state = getInitialState()
|
|
const result = restoreOriginalStateEnabled({
|
|
...state,
|
|
shouldBackup: true,
|
|
shouldRevert: true,
|
|
errors: new Set([RestoreUnstagedChangesError]),
|
|
})
|
|
|
|
expect(result).toEqual(true)
|
|
})
|
|
|
|
it('should return false when reverting is disabled', ({ expect }) => {
|
|
const state = getInitialState()
|
|
const result = restoreOriginalStateEnabled({
|
|
...state,
|
|
shouldBackup: true,
|
|
shouldRevert: false,
|
|
errors: new Set([TaskError]),
|
|
})
|
|
|
|
expect(result).toEqual(false)
|
|
})
|
|
})
|
|
|
|
describe('restoreOriginalStateSkipped', () => {
|
|
it('should return error message when there is an unknown git error', ({ expect }) => {
|
|
const state = getInitialState()
|
|
const result = restoreOriginalStateSkipped({
|
|
...state,
|
|
errors: new Set([GitError]),
|
|
})
|
|
|
|
expect(typeof result === 'string').toEqual(true)
|
|
})
|
|
})
|
|
|
|
describe('shouldSkipCleanup', () => {
|
|
it('should return error message when reverting to original state fails', ({ expect }) => {
|
|
const state = getInitialState()
|
|
const result = cleanupSkipped({
|
|
...state,
|
|
errors: new Set([RestoreOriginalStateError]),
|
|
})
|
|
|
|
expect(typeof result === 'string').toEqual(true)
|
|
})
|
|
|
|
it('should return error message when when restorating unstaged changes failed', ({ expect }) => {
|
|
const state = getInitialState()
|
|
const result = cleanupSkipped({
|
|
...state,
|
|
shouldBackup: true,
|
|
shouldRevert: false,
|
|
errors: new Set([GitError, RestoreUnstagedChangesError]),
|
|
})
|
|
|
|
expect(typeof result === 'string').toEqual(true)
|
|
})
|
|
})
|