Skip to content

Commit 2ad30b5

Browse files
committed
chore(project): add tests for bundle extends
1 parent e3069e3 commit 2ad30b5

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { bundleExtends } from '../bundle-extends.js';
2+
3+
import type { Plugin, RawGovernanceConfig } from '../types.js';
4+
import type { UserContext } from '../../walk.js';
5+
6+
describe('bundleExtends', () => {
7+
const dummyCtx = {
8+
resolve: vi.fn(),
9+
getVisitorData: vi.fn(),
10+
} as unknown as UserContext;
11+
12+
const dummyPlugins: Plugin[] = [];
13+
14+
it('should throw a descriptive error when extends entry is not a string', () => {
15+
const node = {
16+
extends: [42],
17+
} as unknown as RawGovernanceConfig;
18+
19+
expect(() => bundleExtends({ node, ctx: dummyCtx, plugins: dummyPlugins })).toThrow(
20+
'Invalid "extends" entry at index 0. Expected a non-empty string (ruleset name, path, or URL), but got 42.'
21+
);
22+
});
23+
24+
it('should throw a descriptive error when extends entry is an empty string', () => {
25+
const node = {
26+
extends: [' '],
27+
} as unknown as RawGovernanceConfig;
28+
29+
expect(() => bundleExtends({ node, ctx: dummyCtx, plugins: dummyPlugins })).toThrow(
30+
'Invalid "extends" entry at index 0. Expected a non-empty string (ruleset name, path, or URL), but got " ".'
31+
);
32+
});
33+
34+
it('should throw a descriptive error when an extends entry cannot be resolved as a file or URL', () => {
35+
const node = {
36+
extends: ['missing-config.yaml'],
37+
} as unknown as RawGovernanceConfig;
38+
39+
const ctx = {
40+
...dummyCtx,
41+
resolve: vi.fn().mockReturnValue({
42+
location: undefined,
43+
node: undefined,
44+
}),
45+
} as unknown as UserContext;
46+
47+
expect(() => bundleExtends({ node, ctx, plugins: dummyPlugins })).toThrow(
48+
'Could not resolve "extends" entry "missing-config.yaml". Make sure the path, URL, or ruleset name is correct.'
49+
);
50+
});
51+
});

0 commit comments

Comments
 (0)