39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
|
import { readFile, mkdtemp, rm, writeFile } from 'node:fs/promises';
|
|
import { tmpdir } from 'node:os';
|
|
import path from 'node:path';
|
|
|
|
import { runCommand } from '../../src/cli/run-command.js';
|
|
import { fixture } from '../test-commons.js';
|
|
|
|
describe('pm-xblox run (runCommand)', () => {
|
|
let outDir: string;
|
|
|
|
beforeAll(async () => {
|
|
outDir = await mkdtemp(path.join(tmpdir(), 'xblox-cli-'));
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await rm(outDir, { recursive: true, force: true });
|
|
});
|
|
|
|
it('runs fixture and returns neg', async () => {
|
|
const { result } = await runCommand({
|
|
source: fixture('if-else.json'),
|
|
loglevel: 'error',
|
|
});
|
|
expect(result).toBe('neg');
|
|
});
|
|
|
|
it('writes --output JSON', async () => {
|
|
const outPath = path.join(outDir, 'out.json');
|
|
await runCommand({
|
|
source: fixture('if-else-zero.json'),
|
|
output: outPath,
|
|
loglevel: 'error',
|
|
});
|
|
const text = await readFile(outPath, 'utf8');
|
|
expect(JSON.parse(text)).toEqual({ result: 'zero', results: ['zero'] });
|
|
});
|
|
});
|