@craftpipe/contextpack 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,103 @@
1
+ import { describe, it, expect, vi } from 'vitest';
2
+
3
+ import tokenizerModule from '../lib/tokenizer.js';
4
+ const { estimateTokens, calculateBundleSize, estimateSavings } = tokenizerModule;
5
+
6
+ describe('estimateTokens', () => {
7
+ it('is a function', () => {
8
+ expect(typeof estimateTokens).toBe('function');
9
+ });
10
+
11
+ it('does not throw when called with an empty string', () => {
12
+ expect(() => estimateTokens('')).not.toThrow();
13
+ });
14
+
15
+ it('does not throw when called with null', () => {
16
+ expect(() => estimateTokens(null)).not.toThrow();
17
+ });
18
+
19
+ it('does not throw when called with undefined', () => {
20
+ expect(() => estimateTokens(undefined)).not.toThrow();
21
+ });
22
+
23
+ it('does not throw when called with a normal string', () => {
24
+ expect(() => estimateTokens('function hello() { return 42; }')).not.toThrow();
25
+ });
26
+
27
+ it('does not throw when called with a number', () => {
28
+ expect(() => estimateTokens(12345)).not.toThrow();
29
+ });
30
+
31
+ it('does not throw when called with an object', () => {
32
+ expect(() => estimateTokens({ content: 'hello world' })).not.toThrow();
33
+ });
34
+
35
+ it('returns a value', () => {
36
+ const result = estimateTokens('hello world');
37
+ expect(result).toBeDefined();
38
+ });
39
+ });
40
+
41
+ describe('calculateBundleSize', () => {
42
+ it('is a function', () => {
43
+ expect(typeof calculateBundleSize).toBe('function');
44
+ });
45
+
46
+ it('does not throw when called with an empty object', () => {
47
+ expect(() => calculateBundleSize({})).not.toThrow();
48
+ });
49
+
50
+ it('does not throw when called with null', () => {
51
+ expect(() => calculateBundleSize(null)).not.toThrow();
52
+ });
53
+
54
+ it('does not throw when called with undefined', () => {
55
+ expect(() => calculateBundleSize(undefined)).not.toThrow();
56
+ });
57
+
58
+ it('does not throw when called with a bundle-shaped object', () => {
59
+ const bundle = {
60
+ metadata: { fileCount: 5, totalSize: 1024 },
61
+ fileSummaries: [{ path: 'a.js', summary: 'exports foo' }],
62
+ symbolIndex: { foo: ['a.js'] },
63
+ dependencyMap: {},
64
+ };
65
+ expect(() => calculateBundleSize(bundle)).not.toThrow();
66
+ });
67
+
68
+ it('returns a value', () => {
69
+ const result = calculateBundleSize({});
70
+ expect(result).toBeDefined();
71
+ });
72
+ });
73
+
74
+ describe('estimateSavings', () => {
75
+ it('is a function', () => {
76
+ expect(typeof estimateSavings).toBe('function');
77
+ });
78
+
79
+ it('does not throw when called with two numbers', () => {
80
+ expect(() => estimateSavings(1000, 400)).not.toThrow();
81
+ });
82
+
83
+ it('does not throw when called with null', () => {
84
+ expect(() => estimateSavings(null, null)).not.toThrow();
85
+ });
86
+
87
+ it('does not throw when called with undefined', () => {
88
+ expect(() => estimateSavings(undefined, undefined)).not.toThrow();
89
+ });
90
+
91
+ it('does not throw when called with zero values', () => {
92
+ expect(() => estimateSavings(0, 0)).not.toThrow();
93
+ });
94
+
95
+ it('does not throw when called with objects', () => {
96
+ expect(() => estimateSavings({ tokens: 1000 }, { tokens: 400 })).not.toThrow();
97
+ });
98
+
99
+ it('returns a value', () => {
100
+ const result = estimateSavings(1000, 400);
101
+ expect(result).toBeDefined();
102
+ });
103
+ });
@@ -0,0 +1,111 @@
1
+ import { describe, it, expect, vi } from 'vitest';
2
+
3
+ import validatorModule from '../lib/validator.js';
4
+ const { validateBundle, checkCircularDependencies, checkSymbolConflicts } = validatorModule;
5
+
6
+ describe('validateBundle', () => {
7
+ it('is a function', () => {
8
+ expect(typeof validateBundle).toBe('function');
9
+ });
10
+
11
+ it('does not throw when called with an empty object', () => {
12
+ expect(() => validateBundle({})).not.toThrow();
13
+ });
14
+
15
+ it('does not throw when called with null', () => {
16
+ expect(() => validateBundle(null)).not.toThrow();
17
+ });
18
+
19
+ it('does not throw when called with undefined', () => {
20
+ expect(() => validateBundle(undefined)).not.toThrow();
21
+ });
22
+
23
+ it('does not throw when called with a well-formed bundle', () => {
24
+ const bundle = {
25
+ metadata: { projectDir: '/fake', fileCount: 2, totalSize: 512, createdAt: new Date().toISOString() },
26
+ fileSummaries: [
27
+ { path: 'a.js', summary: 'exports foo', symbols: ['foo'], size: 100 },
28
+ { path: 'b.js', summary: 'exports bar', symbols: ['bar'], size: 200 },
29
+ ],
30
+ symbolIndex: { foo: ['a.js'], bar: ['b.js'] },
31
+ dependencyMap: { 'a.js': [], 'b.js': ['a.js'] },
32
+ };
33
+ expect(() => validateBundle(bundle)).not.toThrow();
34
+ });
35
+
36
+ it('returns a value', () => {
37
+ const result = validateBundle({});
38
+ expect(result).toBeDefined();
39
+ });
40
+
41
+ it('returns an object', () => {
42
+ const result = validateBundle({});
43
+ expect(typeof result).toBe('object');
44
+ });
45
+ });
46
+
47
+ describe('checkCircularDependencies', () => {
48
+ it('is a function', () => {
49
+ expect(typeof checkCircularDependencies).toBe('function');
50
+ });
51
+
52
+ it('does not throw when called with an empty object', () => {
53
+ expect(() => checkCircularDependencies({})).not.toThrow();
54
+ });
55
+
56
+ it('does not throw when called with null', () => {
57
+ expect(() => checkCircularDependencies(null)).not.toThrow();
58
+ });
59
+
60
+ it('does not throw when called with undefined', () => {
61
+ expect(() => checkCircularDependencies(undefined)).not.toThrow();
62
+ });
63
+
64
+ it('does not throw when called with a simple acyclic dependency map', () => {
65
+ const depMap = { 'a.js': ['b.js'], 'b.js': ['c.js'], 'c.js': [] };
66
+ expect(() => checkCircularDependencies(depMap)).not.toThrow();
67
+ });
68
+
69
+ it('does not throw when called with a circular dependency map', () => {
70
+ const depMap = { 'a.js': ['b.js'], 'b.js': ['a.js'] };
71
+ expect(() => checkCircularDependencies(depMap)).not.toThrow();
72
+ });
73
+
74
+ it('returns a value', () => {
75
+ const result = checkCircularDependencies({});
76
+ expect(result).toBeDefined();
77
+ });
78
+ });
79
+
80
+ describe('checkSymbolConflicts', () => {
81
+ it('is a function', () => {
82
+ expect(typeof checkSymbolConflicts).toBe('function');
83
+ });
84
+
85
+ it('does not throw when called with an empty object', () => {
86
+ expect(() => checkSymbolConflicts({})).not.toThrow();
87
+ });
88
+
89
+ it('does not throw when called with null', () => {
90
+ expect(() => checkSymbolConflicts(null)).not.toThrow();
91
+ });
92
+
93
+ it('does not throw when called with undefined', () => {
94
+ expect(() => checkSymbolConflicts(undefined)).not.toThrow();
95
+ });
96
+
97
+ it('does not throw when called with a symbol index with no conflicts', () => {
98
+ const symbolIndex = { foo: ['a.js'], bar: ['b.js'] };
99
+ expect(() => checkSymbolConflicts(symbolIndex)).not.toThrow();
100
+ });
101
+
102
+ it('does not throw when called with a symbol index with conflicts', () => {
103
+ const symbolIndex = { foo: ['a.js', 'b.js'], bar: ['c.js'] };
104
+ expect(() => checkSymbolConflicts(symbolIndex)).not.toThrow();
105
+ });
106
+
107
+ it('returns a value', () => {
108
+ const result = checkSymbolConflicts({});
109
+ expect(result).toBeDefined();
110
+ });
111
+ });
@@ -0,0 +1,13 @@
1
+ import { defineConfig } from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ environment: 'node',
6
+ include: ['tests/**/*.test.mjs'],
7
+ globals: false,
8
+ testTimeout: 10000,
9
+ hookTimeout: 10000,
10
+ isolate: true,
11
+ pool: 'forks',
12
+ },
13
+ });