[Dev] Add imports, Handle kebab-case fileName argument in test boilerplate script (#4072)
* add imports, handle kebab-case fileName argument * fix spacing
This commit is contained in:
parent
8df7422e8f
commit
401568609b
|
@ -20,54 +20,59 @@ const type = args[0]; // "move" or "ability"
|
||||||
let fileName = args[1]; // The file name
|
let fileName = args[1]; // The file name
|
||||||
|
|
||||||
if (!type || !fileName) {
|
if (!type || !fileName) {
|
||||||
console.error('Please provide both a type ("move", "ability", or "item") and a file name.');
|
console.error('Please provide a type ("move", "ability", or "item") and a file name.');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert fileName from to snake_case if camelCase is given
|
// Convert fileName from kebab-case or camelCase to snake_case
|
||||||
fileName = fileName.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase();
|
fileName = fileName
|
||||||
|
.replace(/-+/g, '_') // Convert kebab-case (dashes) to underscores
|
||||||
|
.replace(/([a-z])([A-Z])/g, '$1_$2') // Convert camelCase to snake_case
|
||||||
|
.toLowerCase(); // Ensure all lowercase
|
||||||
|
|
||||||
// Format the description for the test case
|
// Format the description for the test case
|
||||||
const formattedName = fileName
|
const formattedName = fileName
|
||||||
.replace(/_/g, ' ')
|
.replace(/_/g, ' ')
|
||||||
.replace(/\b\w/g, char => char.toUpperCase());
|
.replace(/\b\w/g, char => char.toUpperCase());
|
||||||
|
|
||||||
// Determine the directory based on the type
|
// Determine the directory based on the type
|
||||||
let dir;
|
let dir;
|
||||||
let description;
|
let description;
|
||||||
if (type === 'move') {
|
if (type === 'move') {
|
||||||
dir = path.join(__dirname, 'src', 'test', 'moves');
|
dir = path.join(__dirname, 'src', 'test', 'moves');
|
||||||
description = `Moves - ${formattedName}`;
|
description = `Moves - ${formattedName}`;
|
||||||
} else if (type === 'ability') {
|
} else if (type === 'ability') {
|
||||||
dir = path.join(__dirname, 'src', 'test', 'abilities');
|
dir = path.join(__dirname, 'src', 'test', 'abilities');
|
||||||
description = `Abilities - ${formattedName}`;
|
description = `Abilities - ${formattedName}`;
|
||||||
} else if (type === "item") {
|
} else if (type === "item") {
|
||||||
dir = path.join(__dirname, 'src', 'test', 'items');
|
dir = path.join(__dirname, 'src', 'test', 'items');
|
||||||
description = `Items - ${formattedName}`;
|
description = `Items - ${formattedName}`;
|
||||||
} else {
|
} else {
|
||||||
console.error('Invalid type. Please use "move", "ability", or "item".');
|
console.error('Invalid type. Please use "move", "ability", or "item".');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure the directory exists
|
// Ensure the directory exists
|
||||||
if (!fs.existsSync(dir)) {
|
if (!fs.existsSync(dir)) {
|
||||||
fs.mkdirSync(dir, { recursive: true });
|
fs.mkdirSync(dir, { recursive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the file with the given name
|
// Create the file with the given name
|
||||||
const filePath = path.join(dir, `${fileName}.test.ts`);
|
const filePath = path.join(dir, `${fileName}.test.ts`);
|
||||||
|
|
||||||
if (fs.existsSync(filePath)) {
|
if (fs.existsSync(filePath)) {
|
||||||
console.error(`File "${fileName}.test.ts" already exists.`);
|
console.error(`File "${fileName}.test.ts" already exists.`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define the content template
|
// Define the content template
|
||||||
const content = `import { Abilities } from "#enums/abilities";
|
const content = `import { Abilities } from "#enums/abilities";
|
||||||
|
import { Moves } from "#enums/moves";
|
||||||
|
import { Species } from "#enums/species";
|
||||||
import GameManager from "#test/utils/gameManager";
|
import GameManager from "#test/utils/gameManager";
|
||||||
import { SPLASH_ONLY } from "#test/utils/testUtils";
|
import { SPLASH_ONLY } from "#test/utils/testUtils";
|
||||||
import Phaser from "phaser";
|
import Phaser from "phaser";
|
||||||
import { afterEach, beforeAll, beforeEach, describe, it } from "vitest";
|
import { afterEach, beforeAll, beforeEach, describe, it, expect } from "vitest";
|
||||||
|
|
||||||
describe("${description}", () => {
|
describe("${description}", () => {
|
||||||
let phaserGame: Phaser.Game;
|
let phaserGame: Phaser.Game;
|
||||||
|
@ -87,14 +92,15 @@ describe("${description}", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
game = new GameManager(phaserGame);
|
game = new GameManager(phaserGame);
|
||||||
game.override
|
game.override
|
||||||
|
.moveset([Moves.SPLASH])
|
||||||
.battleType("single")
|
.battleType("single")
|
||||||
.enemyAbility(Abilities.BALL_FETCH)
|
.enemyAbility(Abilities.BALL_FETCH)
|
||||||
.enemyMoveset(SPLASH_ONLY);
|
.enemyMoveset(SPLASH_ONLY);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("test case", async () => {
|
it("test case", async () => {
|
||||||
// await game.classicMode.startBattle();
|
// await game.classicMode.startBattle([Species.MAGIKARP]);
|
||||||
// game.move.select();
|
// game.move.select(Moves.SPLASH);
|
||||||
}, TIMEOUT);
|
}, TIMEOUT);
|
||||||
});
|
});
|
||||||
`;
|
`;
|
||||||
|
|
Loading…
Reference in New Issue