-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathindex.test.ts
More file actions
94 lines (83 loc) · 2.69 KB
/
Copy pathindex.test.ts
File metadata and controls
94 lines (83 loc) · 2.69 KB
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
import { describe, expect, it } from 'bun:test';
import {
validateLocalPath,
validateResourceReference,
validateResourcesArray,
validateSearchPath
} from './index.ts';
describe('validateResourceReference', () => {
it('accepts configured resource names', () => {
const result = validateResourceReference('svelte');
expect(result.valid).toBe(true);
if (result.valid) {
expect(result.value).toBe('svelte');
}
});
it('accepts and normalizes https Git URLs', () => {
const result = validateResourceReference(
'https://github.com/sveltejs/svelte.dev/tree/main/packages'
);
expect(result.valid).toBe(true);
if (result.valid) {
expect(result.value).toBe('https://github.com/sveltejs/svelte.dev');
}
});
it('accepts and normalizes npm references', () => {
const result = validateResourceReference('npm:@types/node@22.10.1');
expect(result.valid).toBe(true);
if (result.valid) {
expect(result.value).toBe('npm:@types/node@22.10.1');
}
});
it('accepts and normalizes npm package URLs', () => {
const result = validateResourceReference('https://www.npmjs.com/package/react/v/19.0.0');
expect(result.valid).toBe(true);
if (result.valid) {
expect(result.value).toBe('npm:react@19.0.0');
}
});
it('rejects malformed npm package URLs without throwing', () => {
const result = validateResourceReference('https://www.npmjs.com/package/%');
expect(result.valid).toBe(false);
if (!result.valid) {
expect(result.error).toContain('Invalid npm reference');
}
});
it('rejects invalid resource references', () => {
const result = validateResourceReference('not a resource');
expect(result.valid).toBe(false);
if (!result.valid) {
expect(result.error).toContain('Invalid resource reference');
}
});
it('rejects non-https URLs', () => {
const result = validateResourceReference('http://github.com/sveltejs/svelte');
expect(result.valid).toBe(false);
if (!result.valid) {
expect(result.error).toContain('Invalid resource reference');
}
});
});
describe('validateResourcesArray', () => {
it('validates names and URLs together', () => {
const result = validateResourcesArray([
'svelte',
'https://github.com/sveltejs/svelte.dev',
'npm:react'
]);
expect(result.valid).toBe(true);
});
});
describe('windows path handling', () => {
it('accepts absolute windows local paths with forward slashes', () => {
const result = validateLocalPath('C:/Users/test/project');
expect(result.valid).toBe(true);
});
it('rejects absolute windows search paths as searchPath', () => {
const result = validateSearchPath('C:/Users/test/project');
expect(result.valid).toBe(false);
if (!result.valid) {
expect(result.error).toContain('absolute path');
}
});
});