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

checkNodeVersion.test.ts 1.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
  1. import chalk from 'chalk';
  2. import { checkNodeVersion } from '../src/checkNodeVersion';
  3. import logger from '../src/logger';
  4. jest.mock('../package.json', () => ({
  5. engines: { node: '>=18.0.1' },
  6. }));
  7. const setNodeVersion = (version: string) => {
  8. Object.defineProperty(process, 'version', {
  9. value: version,
  10. configurable: true,
  11. });
  12. };
  13. describe('checkNodeVersion', () => {
  14. const originalProcessVersion = process.version;
  15. afterEach(() => {
  16. setNodeVersion(originalProcessVersion);
  17. });
  18. it('should handle version strings correctly and throw if required version is not met', () => {
  19. setNodeVersion('v18.0.0');
  20. expect(() => checkNodeVersion()).toThrow(
  21. 'You are using Node.js 18.0.0. This version is not supported. Please use Node.js >=18.0.1.',
  22. );
  23. });
  24. it('should not throw if Node.js version is supported', () => {
  25. setNodeVersion('v18.0.1');
  26. expect(() => checkNodeVersion()).not.toThrow();
  27. });
  28. it('should log a warning if Node.js version format is unexpected', () => {
  29. setNodeVersion('v18');
  30. checkNodeVersion();
  31. expect(logger.warn).toHaveBeenCalledWith(
  32. chalk.yellow('Unexpected Node.js version format: v18. Please use Node.js >=18.0.1.'),
  33. );
  34. });
  35. });
Tip!

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

Comments

Loading...