From 0c9921940092e4fb941456964681ba1ebccfb4bf Mon Sep 17 00:00:00 2001 From: freearhey <7253922+freearhey@users.noreply.github.com> Date: Mon, 30 Dec 2024 09:30:56 +0300 Subject: [PATCH] Create update.test.ts --- tests/commands/sites/update.test.ts | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/commands/sites/update.test.ts diff --git a/tests/commands/sites/update.test.ts b/tests/commands/sites/update.test.ts new file mode 100644 index 00000000..e38414d3 --- /dev/null +++ b/tests/commands/sites/update.test.ts @@ -0,0 +1,36 @@ +import { execSync } from 'child_process' +import fs from 'fs-extra' +import path from 'path' + +beforeEach(() => { + fs.emptyDirSync('tests/__data__/output') + fs.mkdirSync('tests/__data__/output/.sites') + fs.copyFileSync( + 'tests/__data__/input/.sites/config.json', + 'tests/__data__/output/.sites/config.json' + ) + fs.copyFileSync( + 'tests/__data__/input/.sites/template.md', + 'tests/__data__/output/.sites/template.md' + ) +}) + +it('can update SITES.md', () => { + const stdout = execSync('DOT_SITES_DIR=tests/__data__/output/.sites npm run sites:update', { + encoding: 'utf8' + }) + + expect(content('tests/__data__/output/sites.md')).toEqual( + content('tests/__data__/expected/_sites.md') + ) + + expect(true).toBe(true) +}) + +function content(filepath: string) { + const data = fs.readFileSync(path.resolve(filepath), { + encoding: 'utf8' + }) + + return JSON.stringify(data) +}