Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 29 additions & 25 deletions hosting/tests/unit/slugGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,38 @@ import { describe, it, expect } from "vitest";
import { generateVibeSlug } from "@vibes.diy/hosting";

describe("Vibe Slug Generator", () => {
it("should generate 30 unique slugs with no repeats", () => {
const generatedSlugs = new Set();
const slugs = [];
it(
"should generate 30 unique slugs with no repeats",
{ timeout: 10000 },
() => {
Comment on lines +5 to +8

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Pass timeout as number, not options object

Vitest’s it signature is it(name, fn, timeout?), so the second argument must be the test function. Lines 5‑8 now pass an options object { timeout: 10000 } as the second parameter and the actual callback as the third, which causes Vitest to throw at runtime (TypeError: fn is not a function) and prevents the suite from running at all. If you need a longer timeout you must keep the callback as the second argument and pass 10000 as the third parameter (or use the newer test.runIf helpers).

Useful? React with 👍 / 👎.

const generatedSlugs = new Set();
const slugs = [];

// Generate 30 slugs
for (let i = 0; i < 30; i++) {
const slug = generateVibeSlug();
slugs.push(slug);
generatedSlugs.add(slug);
}
// Generate 30 slugs
for (let i = 0; i < 30; i++) {
const slug = generateVibeSlug();
slugs.push(slug);
generatedSlugs.add(slug);
}

// Print all generated slugs to console
console.log("\nGenerated 30 vibe slugs:");
slugs.forEach((slug, index) => {
console.log(`${index + 1}. ${slug}`);
});
// Print all generated slugs to console
console.log("\nGenerated 30 vibe slugs:");
slugs.forEach((slug, index) => {
console.log(`${index + 1}. ${slug}`);
});

// Check that we have 30 unique slugs (no duplicates)
console.log(`\nUnique slugs: ${generatedSlugs.size}/30`);
// Check that we have 30 unique slugs (no duplicates)
console.log(`\nUnique slugs: ${generatedSlugs.size}/30`);

// Test passes if all 30 slugs are unique
expect(generatedSlugs.size).toBe(30);
// Test passes if all 30 slugs are unique
expect(generatedSlugs.size).toBe(30);

// Verify slug format (system-character-number)
slugs.forEach((slug) => {
const parts = slug.split("-");
expect(parts.length).toBe(3);
expect(parts[2]).toMatch(/^\d{4}$/); // Should be 4-digit number
});
});
// Verify slug format (system-character-number)
slugs.forEach((slug) => {
const parts = slug.split("-");
expect(parts.length).toBe(3);
expect(parts[2]).toMatch(/^\d{4}$/); // Should be 4-digit number
});
}
);
});
Loading