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

meteorIntegration.test.ts 3.0 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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
  1. // Special test for METEOR assertion integration
  2. describe('METEOR assertion', () => {
  3. beforeEach(() => {
  4. jest.resetModules();
  5. });
  6. afterEach(() => {
  7. jest.resetModules();
  8. jest.restoreAllMocks();
  9. });
  10. it('should use the handleMeteorAssertion when natural is available', async () => {
  11. // Setup a mock for the meteor module
  12. jest.mock('../../src/assertions/meteor', () => ({
  13. handleMeteorAssertion: jest.fn().mockResolvedValue({
  14. pass: true,
  15. score: 0.85,
  16. reason: 'METEOR test passed',
  17. assertion: { type: 'meteor' },
  18. }),
  19. }));
  20. // Import after mocking
  21. const { runAssertion } = await import('../../src/assertions');
  22. const result = await runAssertion({
  23. prompt: 'Test prompt',
  24. provider: {} as any,
  25. assertion: {
  26. type: 'meteor',
  27. value: 'Expected output',
  28. threshold: 0.7,
  29. },
  30. test: {} as any,
  31. providerResponse: { output: 'Actual output' },
  32. });
  33. // Verify the mock was called and the result is as expected
  34. const { handleMeteorAssertion } = await import('../../src/assertions/meteor');
  35. expect(handleMeteorAssertion).toHaveBeenCalledWith(expect.anything());
  36. expect(result.pass).toBe(true);
  37. expect(result.score).toBe(0.85);
  38. expect(result.reason).toBe('METEOR test passed');
  39. });
  40. it('should handle errors when natural package is missing', async () => {
  41. // Mock dynamic import to simulate the module not being found
  42. jest.mock('../../src/assertions/meteor', () => {
  43. throw new Error("Cannot find module 'natural'");
  44. });
  45. // Import after mocking
  46. const { runAssertion } = await import('../../src/assertions');
  47. const result = await runAssertion({
  48. prompt: 'Test prompt',
  49. provider: {} as any,
  50. assertion: {
  51. type: 'meteor',
  52. value: 'Expected output',
  53. threshold: 0.7,
  54. },
  55. test: {} as any,
  56. providerResponse: { output: 'Actual output' },
  57. });
  58. // Verify the error is handled correctly
  59. expect(result.pass).toBe(false);
  60. expect(result.score).toBe(0);
  61. expect(result.reason).toBe(
  62. 'METEOR assertion requires the natural package. Please install it using: npm install natural',
  63. );
  64. expect(result.assertion).toEqual({
  65. type: 'meteor',
  66. value: 'Expected output',
  67. threshold: 0.7,
  68. });
  69. });
  70. it('should rethrow other errors that are not related to missing module', async () => {
  71. // Mock dynamic import to simulate some other error
  72. jest.mock('../../src/assertions/meteor', () => {
  73. throw new Error('Some other error');
  74. });
  75. // Import after mocking
  76. const { runAssertion } = await import('../../src/assertions');
  77. // The error should be rethrown
  78. await expect(
  79. runAssertion({
  80. prompt: 'Test prompt',
  81. provider: {} as any,
  82. assertion: {
  83. type: 'meteor',
  84. value: 'Expected output',
  85. threshold: 0.7,
  86. },
  87. test: {} as any,
  88. providerResponse: { output: 'Actual output' },
  89. }),
  90. ).rejects.toThrow('Some other error');
  91. });
  92. });
Tip!

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

Comments

Loading...