Skip to content

Commit

Permalink
chore: fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
nytamin committed Feb 15, 2024
1 parent d0d6b60 commit 797e958
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/internal-tests/src/__mocks__/proper-lockfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const locks = new Set<string>()
export async function lock(
filePath: string,
_options: {
onCompromised: (err: Error) => void
}
): Promise<() => Promise<void>> {
await sleep(1)

if (locks.has(filePath)) {
const err = new Error('ELOCKED: File is already locked')
;(err as any).code = 'ELOCKED'
throw err
} else {
locks.add(filePath)
}

return async () => {
// release lock

if (!locks.has(filePath)) {
const err = new Error('ELOCKED: File is already released')
;(err as any).code = 'ERELEASED'
throw err
} else {
locks.delete(filePath)
}
}
}

async function sleep(duration: number): Promise<void> {
return new Promise((r) => setTimeout(r, duration))
}
1 change: 1 addition & 0 deletions tests/internal-tests/src/__tests__/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jest.mock('child_process')
jest.mock('windows-network-drive')
jest.mock('tv-automation-quantel-gateway-client')
jest.mock('@parcel/watcher')
jest.mock('proper-lockfile')

const fs = fsOrg as any as typeof fsMockType
const WND = WNDOrg as any as typeof WNDType
Expand Down
1 change: 1 addition & 0 deletions tests/internal-tests/src/__tests__/issues.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jest.mock('child_process')
jest.mock('windows-network-drive')
jest.mock('tv-automation-quantel-gateway-client')
jest.mock('@parcel/watcher')
jest.mock('proper-lockfile')

const fs = fsOrg as any as typeof fsMockType

Expand Down

0 comments on commit 797e958

Please sign in to comment.