import { getTmpFile, download, getPackageVersion } 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)); 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/_ 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+/) }) }) }) })