|
| 1 | +import { spawnSync } from 'node:child_process'; |
| 2 | +import { describe, it } from 'node:test'; |
| 3 | +import { dirname, join } from 'node:path'; |
| 4 | +import { fileURLToPath } from 'node:url'; |
| 5 | + |
| 6 | +const __dirname = dirname(fileURLToPath(import.meta.url)); |
| 7 | +const CLI = join(__dirname, '../../bin/cgmd.js'); |
| 8 | + |
| 9 | +function runCLI(args) { |
| 10 | + return spawnSync(process.execPath, [CLI, ...args], { encoding: 'utf8', timeout: 10000 }); |
| 11 | +} |
| 12 | + |
| 13 | +describe('CodeGridMarkdown - CLI', function () { |
| 14 | + |
| 15 | + describe('引数なし', function () { |
| 16 | + it('エラーで終了すること', function (t) { |
| 17 | + const result = runCLI([]); |
| 18 | + t.assert.strictEqual(result.status, 1); |
| 19 | + }); |
| 20 | + |
| 21 | + it('エラーメッセージが出ること', async (t) => { |
| 22 | + const result = runCLI([]); |
| 23 | + await t.assert.snapshot(result.stderr); |
| 24 | + }); |
| 25 | + }); |
| 26 | + |
| 27 | + describe('--help', function () { |
| 28 | + it('ヘルプを出力して終了すること', function (t) { |
| 29 | + const result = runCLI(['--help']); |
| 30 | + t.assert.strictEqual(result.status, 0); |
| 31 | + }); |
| 32 | + |
| 33 | + it('ヘルプテキストが出ること', async (t) => { |
| 34 | + const result = runCLI(['--help']); |
| 35 | + await t.assert.snapshot(result.stdout); |
| 36 | + }); |
| 37 | + }); |
| 38 | + |
| 39 | + describe('文字列入力(ファイルが存在しない場合は文字列として扱う)', function () { |
| 40 | + it('MarkdownをHTMLに変換できること', async (t) => { |
| 41 | + const result = runCLI(['# Hello\n\nWorld']); |
| 42 | + t.assert.strictEqual(result.status, 0); |
| 43 | + await t.assert.snapshot(result.stdout); |
| 44 | + }); |
| 45 | + |
| 46 | + it('CGMD構文を含むMarkdownを変換できること', async (t) => { |
| 47 | + const result = runCLI(['[note]\nこれはノートです。\n[/note]']); |
| 48 | + t.assert.strictEqual(result.status, 0); |
| 49 | + await t.assert.snapshot(result.stdout); |
| 50 | + }); |
| 51 | + }); |
| 52 | + |
| 53 | + describe('ファイル入力', function () { |
| 54 | + it('example/cg.mdを変換できること', async (t) => { |
| 55 | + const mdFile = join(__dirname, '../../example/cg.md'); |
| 56 | + const result = runCLI([mdFile]); |
| 57 | + t.assert.strictEqual(result.status, 0); |
| 58 | + await t.assert.snapshot(result.stdout); |
| 59 | + }); |
| 60 | + }); |
| 61 | + |
| 62 | +}); |
0 commit comments