a reactive (signals based) hypermedia web framework (wip)
stormlightlabs.github.io/volt/
hypermedia
frontend
signals
1import { getLibSrcPath } from "$utils/paths.js";
2import { readFile } from "node:fs/promises";
3import path from "node:path";
4import { describe, expect, it } from "vitest";
5
6describe("stats command", () => {
7 it("should count lines excluding doc comments", async () => {
8 const srcPath = await getLibSrcPath();
9 const testDir = path.join(srcPath, "core");
10 const signalFile = path.join(testDir, "signal.ts");
11 const content = await readFile(signalFile, "utf8");
12
13 const lines = content.split("\n");
14 let codeLines = 0;
15 let inDocComment = false;
16
17 for (const line of lines) {
18 const trimmed = line.trim();
19
20 if (trimmed.startsWith("/**")) {
21 inDocComment = true;
22 continue;
23 }
24
25 if (inDocComment) {
26 if (trimmed.endsWith("*/")) {
27 inDocComment = false;
28 }
29 continue;
30 }
31
32 if (trimmed === "" || trimmed.startsWith("//")) {
33 continue;
34 }
35
36 codeLines++;
37 }
38
39 expect(codeLines).toBeGreaterThan(0);
40 expect(codeLines).toBeLessThan(lines.length);
41 });
42
43 it("should exclude empty lines", () => {
44 const content = `
45function test() {
46 return true;
47}
48
49export { test };
50`;
51
52 const lines = content.split("\n");
53 let codeLines = 0;
54
55 for (const line of lines) {
56 const trimmed = line.trim();
57
58 if (trimmed === "" || trimmed.startsWith("//")) {
59 continue;
60 }
61
62 codeLines++;
63 }
64
65 expect(codeLines).toBe(4);
66 });
67
68 it("should exclude single-line comments", () => {
69 const content = `// This is a comment
70function test() {
71 // Another comment
72 return true;
73}`;
74
75 const lines = content.split("\n");
76 let codeLines = 0;
77
78 for (const line of lines) {
79 const trimmed = line.trim();
80
81 if (trimmed === "" || trimmed.startsWith("//")) {
82 continue;
83 }
84
85 codeLines++;
86 }
87
88 expect(codeLines).toBe(3);
89 });
90
91 it("should exclude doc comment blocks", () => {
92 const content = `/**
93 * This is a doc comment
94 * @param foo - some param
95 */
96function test(foo: string) {
97 return foo;
98}`;
99
100 const lines = content.split("\n");
101 let codeLines = 0;
102 let inDocComment = false;
103
104 for (const line of lines) {
105 const trimmed = line.trim();
106
107 if (trimmed.startsWith("/**")) {
108 inDocComment = true;
109 continue;
110 }
111
112 if (inDocComment) {
113 if (trimmed.endsWith("*/")) {
114 inDocComment = false;
115 }
116 continue;
117 }
118
119 if (trimmed === "" || trimmed.startsWith("//")) {
120 continue;
121 }
122
123 codeLines++;
124 }
125
126 expect(codeLines).toBe(3);
127 });
128});