-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.test.ts
More file actions
57 lines (51 loc) · 2.05 KB
/
build.test.ts
File metadata and controls
57 lines (51 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { describe, it, expect, beforeAll } from 'vitest';
import { execFile } from 'node:child_process';
import { promisify } from 'node:util';
import { readFileSync } from 'node:fs';
import { rm } from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
import path from 'node:path';
const exec = promisify(execFile);
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const PROJECT_ROOT = path.resolve(__dirname, '..');
const DIST_DIR = path.resolve(PROJECT_ROOT, 'dist');
const DIST_ENTRY = path.resolve(DIST_DIR, 'index.js');
const pkg = JSON.parse(readFileSync(path.resolve(PROJECT_ROOT, 'package.json'), 'utf-8'));
async function runBuiltCli(args: string[]): Promise<{ stdout: string; stderr: string; exitCode: number }> {
try {
const { stdout, stderr } = await exec(
'node', [DIST_ENTRY, ...args],
{ cwd: PROJECT_ROOT, env: { ...process.env, SLACK_BOT_TOKEN: '' }, timeout: 10000 }
);
return { stdout, stderr, exitCode: 0 };
} catch (error: any) {
return {
stdout: error.stdout || '',
stderr: error.stderr || '',
exitCode: error.code ?? 1,
};
}
}
describe('Build verification', () => {
beforeAll(async () => {
await rm(DIST_DIR, { recursive: true, force: true });
await exec('npx', ['tsc'], { cwd: PROJECT_ROOT, timeout: 30000 });
}, 35000);
it('--version outputs the package version', async () => {
const result = await runBuiltCli(['--version']);
expect(result.exitCode).toBe(0);
expect(result.stdout.trim()).toBe(pkg.version);
});
it('list-methods outputs valid JSON with a methods array', async () => {
const result = await runBuiltCli(['list-methods']);
expect(result.exitCode).toBe(0);
const output = JSON.parse(result.stdout);
expect(Array.isArray(output.methods)).toBe(true);
expect(output.methods.length).toBeGreaterThan(0);
});
it('exits non-zero with usage help when no arguments provided', async () => {
const result = await runBuiltCli([]);
expect(result.exitCode).not.toBe(0);
expect(result.stderr).toContain('method');
});
});