Update tests/commands

This commit is contained in:
Aleksandr Statciuk 2022-08-15 02:22:01 +03:00
parent 0b2ab738e8
commit 2b84b126c9
5 changed files with 61 additions and 17 deletions

View File

@ -0,0 +1,48 @@
const fs = require('fs-extra')
const path = require('path')
const { execSync } = require('child_process')
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
fs.mkdirSync('tests/__data__/output/database')
fs.copyFileSync(
'tests/__data__/input/database/db_clear.streams.db',
'tests/__data__/output/database/streams.db'
)
const stdout = execSync(
'DB_DIR=tests/__data__/output/database npm run db:clear -- --threshold 7',
{
encoding: 'utf8'
}
)
})
it('can clear database', () => {
let output = content('tests/__data__/output/database/streams.db')
let expected = content('tests/__data__/expected/database/db_clear.streams.db')
output = output.map(i => {
i._id = null
return i
})
expected = expected.map(i => {
i._id = null
return i
})
expect(output).toMatchObject(expected)
})
function content(filepath) {
const data = fs.readFileSync(path.resolve(filepath), {
encoding: 'utf8'
})
return data
.split('\n')
.filter(l => l)
.map(l => {
return JSON.parse(l)
})
}

View File

@ -4,9 +4,10 @@ const { execSync } = require('child_process')
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
fs.mkdirSync('tests/__data__/output/database')
const stdout = execSync(
'DB_DIR=tests/__data__/output/database npm run db:create -- --input-dir=tests/__data__/input/streams --max-clusters=1',
'DB_DIR=tests/__data__/output/database DATA_DIR=tests/__data__/input/data npm run db:create -- --input-dir=tests/__data__/input/streams --max-clusters=1',
{ encoding: 'utf8' }
)
})
@ -24,14 +25,7 @@ it('can create database', () => {
return i
})
expect(output).toEqual(
expect.arrayContaining([
expect.objectContaining(expected[0]),
expect.objectContaining(expected[1]),
expect.objectContaining(expected[2]),
expect.objectContaining(expected[3])
])
)
expect(output).toMatchObject(expect.arrayContaining(expected))
})
function content(filepath) {

View File

@ -5,13 +5,14 @@ const dayjs = require('dayjs')
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
fs.mkdirSync('tests/__data__/output/database')
fs.copyFileSync(
'tests/__data__/input/database/db_export.streams.db',
'tests/__data__/output/streams.db'
'tests/__data__/output/database/streams.db'
)
const stdout = execSync(
'DB_DIR=tests/__data__/output DATA_DIR=tests/__data__/input/data PUBLIC_DIR=tests/__data__/output/.api npm run db:export',
'DB_DIR=tests/__data__/output/database DATA_DIR=tests/__data__/input/data PUBLIC_DIR=tests/__data__/output/.api npm run db:export',
{ encoding: 'utf8' }
)
})

View File

@ -4,15 +4,15 @@ const { execSync } = require('child_process')
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
fs.mkdirSync('tests/__data__/output/database')
fs.copyFileSync(
'tests/__data__/input/database/db_matrix.streams.db',
'tests/__data__/output/streams.db'
'tests/__data__/output/database/streams.db'
)
})
it('can create valid matrix', () => {
const result = execSync('DB_DIR=tests/__data__/output npm run db:matrix', {
const result = execSync('DB_DIR=tests/__data__/output/database npm run db:matrix', {
encoding: 'utf8'
})
expect(result).toBe(

View File

@ -4,15 +4,16 @@ const path = require('path')
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
fs.mkdirSync('tests/__data__/output/database')
fs.copyFileSync(
'tests/__data__/input/database/db_update.streams.db',
'tests/__data__/output/streams.db'
'tests/__data__/output/database/streams.db'
)
})
it('can save results', () => {
const stdout = execSync(
'DB_DIR=tests/__data__/output LOGS_DIR=tests/__data__/input/logs/cluster/load npm run db:update',
'DB_DIR=tests/__data__/output/database LOGS_DIR=tests/__data__/input/logs/cluster/load npm run db:update',
{ encoding: 'utf8' }
)
expect(stdout).toEqual(`
@ -31,7 +32,7 @@ removed 1 duplicates
done
`)
expect(content('tests/__data__/output/streams.db')).toEqual(
expect(content('tests/__data__/output/database/streams.db')).toEqual(
content('tests/__data__/expected/database/db_update.streams.db')
)
})