-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathparse-only.spec.ts
89 lines (74 loc) · 2.38 KB
/
parse-only.spec.ts
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg
//
// SPDX-License-Identifier: AGPL-3.0-only
import fs from 'node:fs';
import path from 'node:path';
import process from 'node:process';
import { fileURLToPath } from 'node:url';
import { type JayveeInterpreter } from '@jvalue/jayvee-interpreter-lib';
import { runAction } from './run-action';
import { type RunOptions } from './run-options';
const interpreterMock: JayveeInterpreter = {
interpretModel: vi.fn(),
interpretFile: vi.fn(),
interpretString: vi.fn(),
parseModel: vi.fn(),
};
vi.stubGlobal('DefaultJayveeInterpreter', interpreterMock);
const dirPathOfThisTest = path.dirname(fileURLToPath(import.meta.url));
const pathProjectRootRelativeToThisTest = path.join('..', '..', '..');
describe('Parse Only', () => {
const pathToValidModelFromProjectRoot = path.join('example', 'cars.jv');
const pathToInvalidModelFromProjectRoot = path.join(
'apps',
'interpreter',
'test',
'assets',
'broken-model.jv',
);
const defaultOptions: RunOptions = {
pipeline: '.*',
env: new Map<string, string>(),
debug: false,
debugGranularity: 'minimal',
debugTarget: 'all',
parseOnly: false,
};
afterEach(() => {
// Assert that model is not executed
expect(interpreterMock.interpretString).not.toBeCalled();
expect(interpreterMock.interpretModel).not.toBeCalled();
});
beforeEach(() => {
vi.clearAllMocks();
vi.spyOn(process, 'exit').mockImplementation(() => {
throw new Error();
});
});
it('should exit with 0 on a valid option', async () => {
await expect(
runAction(pathToValidModelFromProjectRoot, {
...defaultOptions,
parseOnly: true,
}),
).rejects.toBeDefined();
expect(process.exit).toBeCalledTimes(1);
expect(process.exit).toHaveBeenCalledWith(0);
});
it('should exit with 1 on error', async () => {
const modelPathRelativeToThisTest = path.join(
dirPathOfThisTest,
pathProjectRootRelativeToThisTest,
pathToInvalidModelFromProjectRoot,
);
expect(fs.existsSync(modelPathRelativeToThisTest)).toBe(true);
await expect(
runAction(pathToInvalidModelFromProjectRoot, {
...defaultOptions,
parseOnly: true,
}),
).rejects.toBeDefined();
expect(process.exit).toBeCalledTimes(1);
expect(process.exit).toHaveBeenCalledWith(1);
});
});