Update tests

This commit is contained in:
freearhey
2025-04-22 03:47:28 +03:00
parent d42b102cdf
commit 88e62715e8
8 changed files with 175 additions and 111 deletions

View File

@@ -1,6 +1,14 @@
import { execSync } from 'child_process'
import fs from 'fs-extra'
import path from 'path'
import os from 'os'
let ENV_VAR =
'DATA_DIR=tests/__data__/input/data LOGS_DIR=tests/__data__/input/readme_update README_DIR=tests/__data__/output/.readme'
if (os.platform() === 'win32') {
ENV_VAR =
'SET "DATA_DIR=tests/__data__/input/data" && SET "LOGS_DIR=tests/__data__/input/readme_update" && SET "README_DIR=tests/__data__/output/.readme" &&'
}
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
@@ -13,17 +21,18 @@ beforeEach(() => {
'tests/__data__/input/readme_update/.readme/template.md',
'tests/__data__/output/.readme/template.md'
)
execSync(
'DATA_DIR=tests/__data__/input/data LOGS_DIR=tests/__data__/input/readme_update README_DIR=tests/__data__/output/.readme npm run readme:update',
{ encoding: 'utf8' }
)
})
it('can update readme.md', () => {
expect(content('tests/__data__/output/readme.md')).toEqual(
content('tests/__data__/expected/readme_update/_readme.md')
)
describe('readme:update', () => {
it('can update readme.md', () => {
const cmd = `${ENV_VAR} npm run readme:update`
const stdout = execSync(cmd, { encoding: 'utf8' })
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
expect(content('tests/__data__/output/readme.md')).toEqual(
content('tests/__data__/expected/readme_update/_readme.md')
)
})
})
function content(filepath: string) {