forked from promptfoo/promptfoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson.test.ts
40 lines (33 loc) · 1.1 KB
/
json.test.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
import { getAjv, resetAjv } from '../../src/assertions/json';
describe('getAjv', () => {
beforeAll(() => {
process.env.NODE_ENV = 'test';
});
beforeEach(() => {
delete process.env.PROMPTFOO_DISABLE_AJV_STRICT_MODE;
resetAjv();
});
afterEach(() => {
delete process.env.PROMPTFOO_DISABLE_AJV_STRICT_MODE;
});
it('should create an Ajv instance with default options', () => {
const ajv = getAjv();
expect(ajv).toBeDefined();
expect(ajv.opts.strictSchema).toBe(true);
});
it('should disable strict mode when PROMPTFOO_DISABLE_AJV_STRICT_MODE is set', () => {
process.env.PROMPTFOO_DISABLE_AJV_STRICT_MODE = 'true';
const ajv = getAjv();
expect(ajv.opts.strictSchema).toBe(false);
});
it('should add formats to the Ajv instance', () => {
const ajv = getAjv();
expect(ajv.formats).toBeDefined();
expect(Object.keys(ajv.formats)).not.toHaveLength(0);
});
it('should reuse the same instance on subsequent calls', () => {
const firstInstance = getAjv();
const secondInstance = getAjv();
expect(firstInstance).toBe(secondInstance);
});
});