-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathexample-tests.ts
More file actions
55 lines (46 loc) · 1.88 KB
/
example-tests.ts
File metadata and controls
55 lines (46 loc) · 1.88 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
/**
* Example test file demonstrating how to test the modular structure
* This is a basic example - you would typically use a testing framework like Jest
*/
import { compareVersions, isStaticVersion } from "./src/utils/version";
import {
isValidDirectoryName,
randomNameGenerator,
} from "./src/utils/validation";
// Simple test function
function test(description: string, testFn: () => void): void {
try {
testFn();
console.log(`✅ ${description}`);
} catch (error) {
console.log(`❌ ${description}: ${(error as Error).message}`);
}
}
// Test version utilities
test("compareVersions should handle semantic versions", () => {
const result = compareVersions("1.0.0", "1.0.1");
if (result !== -1) throw new Error(`Expected -1, got ${result}`);
});
test("compareVersions should handle equal versions", () => {
const result = compareVersions("1.0.0", "1.0.0");
if (result !== 0) throw new Error(`Expected 0, got ${result}`);
});
test("isStaticVersion should identify static versions", () => {
if (!isStaticVersion("1.0.0")) throw new Error("Should be static");
if (isStaticVersion("^1.0.0")) throw new Error("Should not be static");
});
// Test validation utilities
test("isValidDirectoryName should reject invalid names", () => {
if (isValidDirectoryName("test<>")) throw new Error("Should be invalid");
if (!isValidDirectoryName("test-app")) throw new Error("Should be valid");
});
test("randomNameGenerator should generate strings of correct length", () => {
const result = randomNameGenerator(5);
if (result.length !== 5)
throw new Error(`Expected length 5, got ${result.length}`);
});
console.log("\nAll tests completed!");
console.log("\nTo run with a proper testing framework:");
console.log("1. Install Jest: npm install --save-dev jest");
console.log("2. Add test script to package.json");
console.log("3. Create proper test files in __tests__ directory");