Update tests

This commit is contained in:
freearhey 2025-04-29 00:18:17 +03:00
parent 67387a0a29
commit 37b4197fb2
6 changed files with 198 additions and 150 deletions

View file

@ -0,0 +1,38 @@
import { execSync } from 'child_process'
import * as fs from 'fs-extra'
import os from 'os'
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
})
describe('db:export', () => {
let ENV_VAR = 'DATA_DIR=tests/__data__/input/db/export/data API_DIR=tests/__data__/output/api'
if (os.platform() === 'win32') {
ENV_VAR =
'SET "DATA_DIR=tests/__data__/input/db/export/data" && SET "API_DIR=tests/__data__/output/api" &&'
}
it('can export data as json', () => {
const cmd = `${ENV_VAR} npm run db:export`
const stdout = execSync(cmd, { encoding: 'utf8' })
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
expect(content('output/api/blocklist.json')).toEqual(
content('expected/db/export/api/blocklist.json')
)
expect(content('output/api/channels.json')).toEqual(
content('expected/db/export/api/channels.json')
)
expect(content('output/api/timezones.json')).toEqual(
content('expected/db/export/api/timezones.json')
)
expect(content('output/api/feeds.json')).toEqual(content('expected/db/export/api/feeds.json'))
})
})
function content(filepath: string) {
return fs.readFileSync(`tests/__data__/${filepath}`, {
encoding: 'utf8'
})
}