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

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

Comments

Loading...