Skip to content

Commit 94a21ca

Browse files
committed
feat: ✨ initial setup, fake source for testing
1 parent 46e575f commit 94a21ca

9 files changed

+1843
-2
lines changed

package-lock.json

Lines changed: 1554 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
"description": "A plugin for vitest that generates a coverage summary in json format",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"coverage": "vitest run --coverage"
89
},
910
"author": "Typeguard Inc.",
10-
"license": "MIT"
11+
"license": "MIT",
12+
"devDependencies": {
13+
"@vitest/coverage-v8": "^3.2.4",
14+
"vitest": "^3.2.4"
15+
}
1116
}

test-src/bananaCalculator.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
export function calculateBananaRipeness(bananaColor) {
2+
if (bananaColor === "green") {
3+
return "not ready yet, you impatient monkey!";
4+
} else if (bananaColor === "yellow") {
5+
return "perfect for eating!";
6+
} else if (bananaColor === "brown") {
7+
return "time to make banana bread!";
8+
} else {
9+
return "that's not a banana color, silly!";
10+
}
11+
}
12+
13+
export function countBananasInBunch(bunchSize) {
14+
let totalBananas = 0;
15+
for (let i = 0; i < bunchSize; i++) {
16+
totalBananas += 1;
17+
}
18+
return totalBananas;
19+
}
20+
21+
export function estimateBananaCalories(bananaCount) {
22+
const caloriesPerBanana = 105;
23+
return bananaCount * caloriesPerBanana;
24+
}
25+
26+
// This function won't be tested to achieve ~85% coverage
27+
export function secretBananaRecipe() {
28+
const ingredients = ["bananas", "flour", "sugar", "eggs"];
29+
const secretIngredient = "love";
30+
return `Mix ${ingredients.join(", ")} and add ${secretIngredient}`;
31+
}

test-src/bananaCalculator.test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { describe, it, expect } from "vitest";
2+
import {
3+
calculateBananaRipeness,
4+
countBananasInBunch,
5+
estimateBananaCalories,
6+
} from "./bananaCalculator.js";
7+
8+
describe("Banana Calculator", () => {
9+
describe("calculateBananaRipeness", () => {
10+
it("should return message for green bananas", () => {
11+
expect(calculateBananaRipeness("green")).toBe(
12+
"not ready yet, you impatient monkey!"
13+
);
14+
});
15+
16+
it("should return message for yellow bananas", () => {
17+
expect(calculateBananaRipeness("yellow")).toBe("perfect for eating!");
18+
});
19+
20+
it("should return message for brown bananas", () => {
21+
expect(calculateBananaRipeness("brown")).toBe(
22+
"time to make banana bread!"
23+
);
24+
});
25+
26+
it("should return message for unknown color", () => {
27+
expect(calculateBananaRipeness("purple")).toBe(
28+
"that's not a banana color, silly!"
29+
);
30+
});
31+
});
32+
33+
describe("countBananasInBunch", () => {
34+
it("should count bananas correctly", () => {
35+
expect(countBananasInBunch(5)).toBe(5);
36+
expect(countBananasInBunch(0)).toBe(0);
37+
expect(countBananasInBunch(10)).toBe(10);
38+
});
39+
});
40+
41+
describe("estimateBananaCalories", () => {
42+
it("should calculate calories correctly", () => {
43+
expect(estimateBananaCalories(1)).toBe(105);
44+
expect(estimateBananaCalories(3)).toBe(315);
45+
expect(estimateBananaCalories(0)).toBe(0);
46+
});
47+
});
48+
});

test-src/pizzaNinja.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
export function throwPizzaShuriken(target) {
2+
if (target === "enemy") {
3+
return "Pizza shuriken hits! Enemy is now covered in cheese!";
4+
} else if (target === "friend") {
5+
return "Friendly pizza shuriken! Sharing is caring!";
6+
} else {
7+
return "Pizza shuriken missed! The floor is now delicious.";
8+
}
9+
}
10+
11+
export function calculatePizzaSlices(pizzaDiameter) {
12+
const baseSlices = 8;
13+
if (pizzaDiameter > 16) {
14+
return baseSlices * 2;
15+
} else if (pizzaDiameter > 12) {
16+
return baseSlices;
17+
} else {
18+
return baseSlices / 2;
19+
}
20+
}
21+
22+
export function ninjaPizzaDelivery(distance) {
23+
const deliveryTime = distance * 2;
24+
if (deliveryTime < 10) {
25+
return "Lightning fast ninja delivery!";
26+
} else if (deliveryTime < 20) {
27+
return "Standard ninja speed delivery.";
28+
} else {
29+
return "Ninja got lost in the shadows...";
30+
}
31+
}
32+
33+
// This function won't be tested to achieve ~85% coverage
34+
export function secretNinjaTechnique() {
35+
const techniques = ["shadow clone", "pizza jutsu", "cheese transformation"];
36+
return `Mastered: ${techniques.join(", ")}`;
37+
}

test-src/pizzaNinja.test.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { describe, it, expect } from "vitest";
2+
import {
3+
throwPizzaShuriken,
4+
calculatePizzaSlices,
5+
ninjaPizzaDelivery,
6+
} from "./pizzaNinja.js";
7+
8+
describe("Pizza Ninja", () => {
9+
describe("throwPizzaShuriken", () => {
10+
it("should hit enemy with pizza shuriken", () => {
11+
expect(throwPizzaShuriken("enemy")).toBe(
12+
"Pizza shuriken hits! Enemy is now covered in cheese!"
13+
);
14+
});
15+
16+
it("should share pizza with friend", () => {
17+
expect(throwPizzaShuriken("friend")).toBe(
18+
"Friendly pizza shuriken! Sharing is caring!"
19+
);
20+
});
21+
22+
it("should miss other targets", () => {
23+
expect(throwPizzaShuriken("wall")).toBe(
24+
"Pizza shuriken missed! The floor is now delicious."
25+
);
26+
});
27+
});
28+
29+
describe("calculatePizzaSlices", () => {
30+
it("should calculate slices for large pizza", () => {
31+
expect(calculatePizzaSlices(18)).toBe(16);
32+
});
33+
34+
it("should calculate slices for medium pizza", () => {
35+
expect(calculatePizzaSlices(14)).toBe(8);
36+
});
37+
38+
it("should calculate slices for small pizza", () => {
39+
expect(calculatePizzaSlices(10)).toBe(4);
40+
});
41+
});
42+
43+
describe("ninjaPizzaDelivery", () => {
44+
it("should deliver lightning fast", () => {
45+
expect(ninjaPizzaDelivery(3)).toBe("Lightning fast ninja delivery!");
46+
});
47+
48+
it("should deliver at standard speed", () => {
49+
expect(ninjaPizzaDelivery(8)).toBe("Standard ninja speed delivery.");
50+
});
51+
52+
it("should get lost on long distances", () => {
53+
expect(ninjaPizzaDelivery(15)).toBe("Ninja got lost in the shadows...");
54+
});
55+
});
56+
});

test-src/spaceHamster.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
export function launchHamsterRocket(hamsterName) {
2+
if (hamsterName === "Astro") {
3+
return "Astro is ready for space exploration!";
4+
} else if (hamsterName === "Cosmo") {
5+
return "Cosmo is floating in zero gravity!";
6+
} else {
7+
return "Unknown hamster astronaut!";
8+
}
9+
}
10+
11+
export function calculateHamsterOrbit(planetSize) {
12+
const orbitTime = planetSize * 3.14;
13+
if (orbitTime < 10) {
14+
return "Quick hamster orbit!";
15+
} else if (orbitTime < 30) {
16+
return "Standard hamster orbit.";
17+
} else {
18+
return "Long hamster journey through space!";
19+
}
20+
}
21+
22+
export function feedSpaceHamster(foodType) {
23+
const spaceFoods = ["moon cheese", "star seeds", "galaxy pellets"];
24+
if (spaceFoods.includes(foodType)) {
25+
return `Hamster loves ${foodType}!`;
26+
} else {
27+
return "Hamster prefers space food!";
28+
}
29+
}
30+
31+
// This function won't be tested to achieve ~85% coverage
32+
export function hamsterSpaceSuit() {
33+
const suitParts = ["helmet", "oxygen tank", "mini jetpack"];
34+
return `Space hamster equipped with: ${suitParts.join(", ")}`;
35+
}

test-src/spaceHamster.test.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { describe, it, expect } from "vitest";
2+
import {
3+
launchHamsterRocket,
4+
calculateHamsterOrbit,
5+
feedSpaceHamster,
6+
} from "./spaceHamster.js";
7+
8+
describe("Space Hamster", () => {
9+
describe("launchHamsterRocket", () => {
10+
it("should launch Astro hamster", () => {
11+
expect(launchHamsterRocket("Astro")).toBe(
12+
"Astro is ready for space exploration!"
13+
);
14+
});
15+
16+
it("should launch Cosmo hamster", () => {
17+
expect(launchHamsterRocket("Cosmo")).toBe(
18+
"Cosmo is floating in zero gravity!"
19+
);
20+
});
21+
22+
it("should handle unknown hamster", () => {
23+
expect(launchHamsterRocket("Fluffy")).toBe("Unknown hamster astronaut!");
24+
});
25+
});
26+
27+
describe("calculateHamsterOrbit", () => {
28+
it("should calculate quick orbit", () => {
29+
expect(calculateHamsterOrbit(2)).toBe("Quick hamster orbit!");
30+
});
31+
32+
it("should calculate standard orbit", () => {
33+
expect(calculateHamsterOrbit(8)).toBe("Standard hamster orbit.");
34+
});
35+
36+
it("should calculate long orbit", () => {
37+
expect(calculateHamsterOrbit(12)).toBe(
38+
"Long hamster journey through space!"
39+
);
40+
});
41+
});
42+
43+
describe("feedSpaceHamster", () => {
44+
it("should feed moon cheese", () => {
45+
expect(feedSpaceHamster("moon cheese")).toBe(
46+
"Hamster loves moon cheese!"
47+
);
48+
});
49+
50+
it("should feed star seeds", () => {
51+
expect(feedSpaceHamster("star seeds")).toBe("Hamster loves star seeds!");
52+
});
53+
54+
it("should feed galaxy pellets", () => {
55+
expect(feedSpaceHamster("galaxy pellets")).toBe(
56+
"Hamster loves galaxy pellets!"
57+
);
58+
});
59+
60+
it("should reject non-space food", () => {
61+
expect(feedSpaceHamster("carrots")).toBe("Hamster prefers space food!");
62+
});
63+
});
64+
});

vitest.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defineConfig } from "vitest/config";
2+
3+
export default defineConfig({
4+
test: {
5+
coverage: {
6+
provider: "v8",
7+
reporter: ["text", "json"],
8+
reportsDirectory: "./coverage",
9+
},
10+
},
11+
});

0 commit comments

Comments
 (0)