1
0
Fork 0
toolkit/packages/cache/__tests__/cacheUtils.test.ts

41 lines
1.2 KiB
TypeScript
Raw Normal View History

import {promises as fs} from 'fs'
import * as path from 'path'
2022-07-14 07:50:44 +00:00
import { coerce } from 'semver'
import * as cacheUtils from '../src/internal/cacheUtils'
2021-05-03 15:09:44 +00:00
test('getArchiveFileSizeInBytes returns file size', () => {
const filePath = path.join(__dirname, '__fixtures__', 'helloWorld.txt')
2021-05-03 15:09:44 +00:00
const size = cacheUtils.getArchiveFileSizeInBytes(filePath)
expect(size).toBe(11)
})
test('unlinkFile unlinks file', async () => {
const testDirectory = await fs.mkdtemp('unlinkFileTest')
const testFile = path.join(testDirectory, 'test.txt')
await fs.writeFile(testFile, 'hello world')
2020-05-15 16:18:50 +00:00
await expect(fs.stat(testFile)).resolves.not.toThrow()
await cacheUtils.unlinkFile(testFile)
// This should throw as testFile should not exist
await expect(fs.stat(testFile)).rejects.toThrow()
await fs.rmdir(testDirectory)
})
test('assertDefined throws if undefined', () => {
expect(() => cacheUtils.assertDefined('test', undefined)).toThrowError()
})
test('assertDefined returns value', () => {
expect(cacheUtils.assertDefined('test', 5)).toBe(5)
})
test('resolvePaths works on current directory', async () => {
2022-07-14 07:50:44 +00:00
const paths = await cacheUtils.resolvePaths(['.'])
expect(paths).toContain('.')
})