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

constants.test.ts 4.2 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
  1. import { jest } from '@jest/globals';
  2. import {
  3. VERSION,
  4. DEFAULT_QUERY_LIMIT,
  5. DEFAULT_API_BASE_URL,
  6. getShareApiBaseUrl,
  7. getDefaultShareViewBaseUrl,
  8. getShareViewBaseUrl,
  9. getDefaultPort,
  10. TERMINAL_MAX_WIDTH,
  11. CLOUD_PROVIDER_PREFIX,
  12. } from '../src/constants';
  13. describe('constants', () => {
  14. beforeEach(() => {
  15. jest.clearAllMocks();
  16. process.env = {};
  17. });
  18. it('should export VERSION from package.json', () => {
  19. expect(VERSION).toBeDefined();
  20. });
  21. it('should have DEFAULT_QUERY_LIMIT set to 100', () => {
  22. expect(DEFAULT_QUERY_LIMIT).toBe(100);
  23. });
  24. it('should have DEFAULT_API_BASE_URL set to api.promptfoo.app', () => {
  25. expect(DEFAULT_API_BASE_URL).toBe('https://api.promptfoo.app');
  26. });
  27. describe('getShareApiBaseUrl', () => {
  28. it('should return DEFAULT_API_BASE_URL by default', () => {
  29. expect(getShareApiBaseUrl()).toBe(DEFAULT_API_BASE_URL);
  30. });
  31. it('should return NEXT_PUBLIC_PROMPTFOO_REMOTE_API_BASE_URL if set', () => {
  32. process.env.NEXT_PUBLIC_PROMPTFOO_REMOTE_API_BASE_URL = 'https://custom.api.com';
  33. expect(getShareApiBaseUrl()).toBe('https://custom.api.com');
  34. });
  35. it('should return NEXT_PUBLIC_PROMPTFOO_BASE_URL if set', () => {
  36. process.env.NEXT_PUBLIC_PROMPTFOO_BASE_URL = 'https://custom.base.com';
  37. expect(getShareApiBaseUrl()).toBe('https://custom.base.com');
  38. });
  39. it('should return PROMPTFOO_REMOTE_API_BASE_URL if set', () => {
  40. process.env.PROMPTFOO_REMOTE_API_BASE_URL = 'https://remote.api.com';
  41. expect(getShareApiBaseUrl()).toBe('https://remote.api.com');
  42. });
  43. it('should prioritize NEXT_PUBLIC_PROMPTFOO_REMOTE_API_BASE_URL over others', () => {
  44. process.env.NEXT_PUBLIC_PROMPTFOO_REMOTE_API_BASE_URL = 'https://custom.api.com';
  45. process.env.NEXT_PUBLIC_PROMPTFOO_BASE_URL = 'https://custom.base.com';
  46. process.env.PROMPTFOO_REMOTE_API_BASE_URL = 'https://remote.api.com';
  47. expect(getShareApiBaseUrl()).toBe('https://custom.api.com');
  48. });
  49. });
  50. describe('getDefaultShareViewBaseUrl', () => {
  51. it('should return promptfoo.app by default', () => {
  52. expect(getDefaultShareViewBaseUrl()).toBe('https://promptfoo.app');
  53. });
  54. it('should return PROMPTFOO_SHARING_APP_BASE_URL if set', () => {
  55. process.env.PROMPTFOO_SHARING_APP_BASE_URL = 'https://custom.share.com';
  56. expect(getDefaultShareViewBaseUrl()).toBe('https://custom.share.com');
  57. });
  58. });
  59. describe('getShareViewBaseUrl', () => {
  60. it('should return promptfoo.app by default', () => {
  61. expect(getShareViewBaseUrl()).toBe('https://promptfoo.app');
  62. });
  63. it('should return NEXT_PUBLIC_PROMPTFOO_BASE_URL if set', () => {
  64. process.env.NEXT_PUBLIC_PROMPTFOO_BASE_URL = 'https://custom.base.com';
  65. expect(getShareViewBaseUrl()).toBe('https://custom.base.com');
  66. });
  67. it('should return PROMPTFOO_REMOTE_APP_BASE_URL if set', () => {
  68. process.env.PROMPTFOO_REMOTE_APP_BASE_URL = 'https://remote.app.com';
  69. expect(getShareViewBaseUrl()).toBe('https://remote.app.com');
  70. });
  71. it('should prioritize NEXT_PUBLIC_PROMPTFOO_BASE_URL over others', () => {
  72. process.env.NEXT_PUBLIC_PROMPTFOO_BASE_URL = 'https://custom.base.com';
  73. process.env.PROMPTFOO_REMOTE_APP_BASE_URL = 'https://remote.app.com';
  74. expect(getShareViewBaseUrl()).toBe('https://custom.base.com');
  75. });
  76. });
  77. describe('getDefaultPort', () => {
  78. it('should return 15500 by default', () => {
  79. expect(getDefaultPort()).toBe(15500);
  80. });
  81. it('should return API_PORT if set', () => {
  82. process.env.API_PORT = '3000';
  83. expect(getDefaultPort()).toBe(3000);
  84. });
  85. it('should handle invalid API_PORT value', () => {
  86. process.env.API_PORT = 'invalid';
  87. expect(getDefaultPort()).toBe(15500);
  88. });
  89. });
  90. describe('TERMINAL_MAX_WIDTH', () => {
  91. it('should match expected terminal width', () => {
  92. const expectedWidth =
  93. process?.stdout?.isTTY && process?.stdout?.columns && process?.stdout?.columns > 10
  94. ? process.stdout.columns - 10
  95. : 120;
  96. expect(TERMINAL_MAX_WIDTH).toBe(expectedWidth);
  97. });
  98. });
  99. it('should have CLOUD_PROVIDER_PREFIX set correctly', () => {
  100. expect(CLOUD_PROVIDER_PREFIX).toBe('promptfoo://provider/');
  101. });
  102. });
Tip!

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

Comments

Loading...