mirror of
https://github.com/stablyai/orca.git
synced 2026-11-14 01:47:24 +00:00
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
|
import { tmpdir } from 'node:os'
|
|
import { join } from 'node:path'
|
|
import { afterEach, describe, expect, it } from 'vitest'
|
|
import { nodeFileContentsEqual, nodeFileContentsEqualSync } from './node-file-content-equality'
|
|
|
|
const roots: string[] = []
|
|
|
|
function createFile(contents: string): string {
|
|
const root = mkdtempSync(join(tmpdir(), 'orca-file-content-equality-'))
|
|
roots.push(root)
|
|
const filePath = join(root, 'owned-launcher')
|
|
writeFileSync(filePath, contents)
|
|
return filePath
|
|
}
|
|
|
|
afterEach(() => {
|
|
for (const root of roots.splice(0)) {
|
|
rmSync(root, { recursive: true, force: true })
|
|
}
|
|
})
|
|
|
|
describe('Node file content equality', () => {
|
|
it('compares UTF-8 content without changing its bytes', async () => {
|
|
const filePath = createFile('launch 🐋\n')
|
|
|
|
await expect(nodeFileContentsEqual(filePath, 'launch 🐋\n')).resolves.toBe(true)
|
|
expect(nodeFileContentsEqualSync(filePath, 'launch 🐋\n')).toBe(true)
|
|
await expect(nodeFileContentsEqual(filePath, 'different\n')).resolves.toBe(false)
|
|
expect(nodeFileContentsEqualSync(filePath, 'different\n')).toBe(false)
|
|
})
|
|
})
|