-
Notifications
You must be signed in to change notification settings - Fork 213
Expand file tree
/
Copy pathlocal-json-server.test.ts
More file actions
38 lines (30 loc) · 1.11 KB
/
local-json-server.test.ts
File metadata and controls
38 lines (30 loc) · 1.11 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
import { spawn } from 'child_process';
import { getParams, getCommandOutput } from '../utils';
import { join } from 'path';
import * as fs from 'fs';
const dbPath = join(__dirname, 'fake-db.json');
describe('local-json-server', () => {
let serverProcess: any;
let originalData: string | undefined;
beforeAll(async () => {
// Start json-server
serverProcess = spawn('npm', ['run', 'json-server'], { detached: true });
// Store original state of fake-bd.json
originalData = fs.readFileSync(dbPath, 'utf8');
});
afterAll(() => {
// Kill the process group to ensure child processes are cleaned up
process.kill(-serverProcess.pid);
// Restore original state
if (originalData) {
fs.writeFileSync(dbPath, originalData);
}
});
test('local-json-server test case', () => {
const indexEntryPoint = join(process.cwd(), 'packages/cli/lib/index.js');
const fixturesPath = join(__dirname, 'local-json-server.yaml');
const args = getParams(indexEntryPoint, ['respect', fixturesPath]);
const result = getCommandOutput(args);
expect(result).toMatchSnapshot();
});
});