Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

json.test.ts 1.1 KB

You have to be logged in to leave a comment. Sign In
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
  1. import { getAjv, resetAjv } from '../../src/assertions/json';
  2. describe('getAjv', () => {
  3. beforeAll(() => {
  4. process.env.NODE_ENV = 'test';
  5. });
  6. beforeEach(() => {
  7. delete process.env.PROMPTFOO_DISABLE_AJV_STRICT_MODE;
  8. resetAjv();
  9. });
  10. afterEach(() => {
  11. delete process.env.PROMPTFOO_DISABLE_AJV_STRICT_MODE;
  12. });
  13. it('should create an Ajv instance with default options', () => {
  14. const ajv = getAjv();
  15. expect(ajv).toBeDefined();
  16. expect(ajv.opts.strictSchema).toBe(true);
  17. });
  18. it('should disable strict mode when PROMPTFOO_DISABLE_AJV_STRICT_MODE is set', () => {
  19. process.env.PROMPTFOO_DISABLE_AJV_STRICT_MODE = 'true';
  20. const ajv = getAjv();
  21. expect(ajv.opts.strictSchema).toBe(false);
  22. });
  23. it('should add formats to the Ajv instance', () => {
  24. const ajv = getAjv();
  25. expect(ajv.formats).toBeDefined();
  26. expect(Object.keys(ajv.formats)).not.toHaveLength(0);
  27. });
  28. it('should reuse the same instance on subsequent calls', () => {
  29. const firstInstance = getAjv();
  30. const secondInstance = getAjv();
  31. expect(firstInstance).toBe(secondInstance);
  32. });
  33. });
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...