41 lines
1.8 KiB
TypeScript
41 lines
1.8 KiB
TypeScript
import { getTmpFile, download, getPackageVersion, getFileChecksum } from './file.ts'
|
|
import { expect } from 'chai'
|
|
import { describe } from 'mocha'
|
|
import { dirname, basename, join, isAbsolute } from 'node:path';
|
|
import { fileURLToPath } from 'url';
|
|
export const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
const fixtureImage0 = join(__dirname, './fixtures/sample.webp')
|
|
|
|
describe('file', function () {
|
|
describe('integration', function () {
|
|
describe('download', function () {
|
|
it('should get the file', async function () {
|
|
const file = await download({ url: 'https://futureporn-b2.b-cdn.net/sample.webp' })
|
|
expect(file).to.match(/\/tmp\/.*sample\.webp$/)
|
|
})
|
|
})
|
|
})
|
|
describe('unit', function () {
|
|
describe('getTmpFile', function () {
|
|
it('should give a /tmp/<random>_<basename> path', function () {
|
|
expect(getTmpFile('my-cool-image.webp')).to.match(/\/tmp\/.*_my-cool-image\.webp/)
|
|
expect(getTmpFile('video.mp4')).to.match(/\/tmp\/.*_video\.mp4/)
|
|
})
|
|
})
|
|
describe('getPackageVersion', function () {
|
|
it('should get the version from package.json', function () {
|
|
expect(getPackageVersion(join(__dirname, '../package.json'))).to.match(/\d+\.\d+\.\d+/)
|
|
})
|
|
it('should handle a relative path', function () {
|
|
expect(getPackageVersion('../package.json')).to.match(/\d+\.\d+\.\d+/)
|
|
})
|
|
})
|
|
describe('getFileChecksum', function () {
|
|
it('should get a MD5sum of a file', async function () {
|
|
const checksum = await getFileChecksum(fixtureImage0)
|
|
expect(checksum).to.equal('a1fe79a39fa6e63d0faca57527792823')
|
|
})
|
|
})
|
|
})
|
|
}) |