-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathutils.test.ts
61 lines (49 loc) · 2.03 KB
/
utils.test.ts
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
import * as fs from 'fs';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { findDefaultSdkInitFile } from '../../src/vite/utils';
vi.mock('fs');
describe('findDefaultSdkInitFile', () => {
afterEach(() => {
vi.clearAllMocks();
});
it.each(['ts', 'js', 'mjs', 'cjs', 'mts', 'cts'])(
'should return the server file path with .%s extension if it exists',
ext => {
vi.spyOn(fs, 'existsSync').mockImplementation(filePath => {
return !(filePath instanceof URL) && filePath.includes(`sentry.server.config.${ext}`);
});
const result = findDefaultSdkInitFile('server');
expect(result).toMatch(`packages/nuxt/sentry.server.config.${ext}`);
},
);
it.each(['ts', 'js', 'mjs', 'cjs', 'mts', 'cts'])(
'should return the client file path with .%s extension if it exists',
ext => {
vi.spyOn(fs, 'existsSync').mockImplementation(filePath => {
return !(filePath instanceof URL) && filePath.includes(`sentry.client.config.${ext}`);
});
const result = findDefaultSdkInitFile('client');
expect(result).toMatch(`packages/nuxt/sentry.client.config.${ext}`);
},
);
it('should return undefined if no file with specified extensions exists', () => {
vi.spyOn(fs, 'existsSync').mockReturnValue(false);
const result = findDefaultSdkInitFile('server');
expect(result).toBeUndefined();
});
it('should return undefined if no file exists', () => {
vi.spyOn(fs, 'existsSync').mockReturnValue(false);
const result = findDefaultSdkInitFile('server');
expect(result).toBeUndefined();
});
it('should return the server config file path if server.config and instrument exist', () => {
vi.spyOn(fs, 'existsSync').mockImplementation(filePath => {
return (
!(filePath instanceof URL) &&
(filePath.includes('sentry.server.config.js') || filePath.includes('instrument.server.js'))
);
});
const result = findDefaultSdkInitFile('server');
expect(result).toMatch('packages/nuxt/sentry.server.config.js');
});
});