Skip to content

Commit

Permalink
move tests file back to core
Browse files Browse the repository at this point in the history
  • Loading branch information
Greegko committed May 31, 2023
1 parent b783e31 commit 21ba589
Show file tree
Hide file tree
Showing 53 changed files with 199 additions and 205 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"request": "launch",
"name": "Debug AVA test file in Core",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/ava",
"runtimeArgs": ["${file}", "--config", "./ava.config-debug.mjs", "--file-line", "${lineNumber}"],
"runtimeArgs": ["${file}", "--config", "../ava.config-debug.mjs", "--file-line", "${lineNumber}"],
"outputCapture": "std",
"cwd": "${workspaceFolder}/packages/core-test",
"cwd": "${workspaceFolder}/packages/core/tests",
"skipFiles": ["<node_internals>/**/*.js"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
Expand Down
30 changes: 12 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"build": "npm run build:core && npm run build:web",
"build:core": "npm run build --prefix packages/core",
"build:web": "npm run build --prefix packages/web",
"test:core": "npm run test:watch --prefix packages/core-test",
"test:core": "npm run test:watch --prefix packages/core",
"prepare": "for P in packages/*/; do (cd $P && npm run prepare); done"
},
"private": true,
Expand Down
9 changes: 0 additions & 9 deletions packages/core-test/.prettierrc

This file was deleted.

4 changes: 0 additions & 4 deletions packages/core-test/ava.config.mjs

This file was deleted.

23 changes: 0 additions & 23 deletions packages/core-test/package.json

This file was deleted.

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions packages/core-test/tsconfig.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import * as fs from "fs";

const defaultSettings = {
extensions: ["ts"],
timeout: "100m",
require: ["ts-node/register"],
timeout: "5s",
require: ["ts-node/register", "reflect-metadata"],
};

const extraSettings = {};
Expand Down
5 changes: 5 additions & 0 deletions packages/core/ava.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
ignoredByWatcher: ["tests/**/*", "src/**/*"],
require: "reflect-metadata",
files: ["dist/**/*.test.js"],
};
12 changes: 10 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"scripts": {
"build": "tsc -b ./tsconfig-public-api.json",
"build:watch": "tsc -b ./tsconfig-public-api.json --watch",
"build:test": "tsc -b ./tests/tsconfig.json --watch",
"test": "ava",
"test:watch": "ava --watch",
"prepare": "ts-patch install -s"
},
"dependencies": {
Expand All @@ -13,10 +16,15 @@
"shortid": "2.2.16",
"ts-patch": "3.0.0-beta3",
"typescript": "5.0.4",
"typescript-transform-paths": "3.4.6"
"typescript-transform-paths": "3.4.6",
"ts-node": "10.9.1"
},
"devDependencies": {
"@types/shortid": "0.0.29"
"@types/chance": "1.1.3",
"@types/shortid": "0.0.29",
"@types/node": "20.1.0",
"ava": "5.2.0",
"chance": "1.1.11"
},
"types": "dist/public-api.d.ts",
"main": "dist/public-api.js"
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/modules/map/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ export * from "./interfaces";
export * from "./map-service";
export * from "./map-store";
export * from "./types";
export * from "./map-module";
export * from "./party-map-service";
export * from "./map-module";
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import {
AttackEffectType,
BattleActivityType,
EffectType,
ItemType,
RuneAttackEffectType,
UnitType,
VillageConfig,
} from "@rpg-village/core";
import { UnitType } from "@features/unit";
import { AttackEffectType, EffectType, ItemType, RuneAttackEffectType } from "@models";
import { BattleActivityType } from "@modules/battle";
import { VillageConfig } from "@modules/village";

import { createState, test } from "../utils";
import { equipmentFactory, runeFactory } from "../utils/factories";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TrainingFieldActivity } from "@rpg-village/core";
import { TrainingFieldActivity } from "@modules/village";

import { createState, test } from "../../../utils";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { ActivityType, MapActivity, VillageActivity } from "@rpg-village/core";
import { ActivityType } from "@modules/activity";
import { MapActivity } from "@modules/map";
import { VillageActivity } from "@modules/village";

import { createState, test } from "../utils";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { VillageActivity, VillageCommand } from "@rpg-village/core";
import { VillageActivity, VillageCommand } from "@modules/village";

import { test } from "../../utils";

test("should start a build activity when gold is enough", {
initState: { village: { stash: { resource: { gold: 100 } }, trainingField: 0 } },
commands: [VillageCommand.BuildTrainingField],
expectedState: (state, t) => t.withRandomId(state.activities, { name: VillageActivity.Build, startArgs: { targetBuilding: 'trainingField' } }),
expectedState: (state, t) =>
t.withRandomId(state.activities, { name: VillageActivity.Build, startArgs: { targetBuilding: "trainingField" } }),
});

test("should block the second command for building", {
initState: { village: { stash: { resource: { gold: 1000 } }, trainingField: 0 } },
commands: [VillageCommand.BuildTrainingField, VillageCommand.BuildTrainingField],
expectedState: [
(state, t) => t.withRandomId(state.activities, { name: VillageActivity.Build, startArgs: { targetBuilding: 'trainingField' } }),
(state, t) => t.deepEqual(state.village, { stash: { resource: { gold: 900 } }, trainingField: 0 })
]
(state, t) =>
t.withRandomId(state.activities, { name: VillageActivity.Build, startArgs: { targetBuilding: "trainingField" } }),
(state, t) => t.deepEqual(state.village, { stash: { resource: { gold: 900 } }, trainingField: 0 }),
],
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PortalActivity } from "@rpg-village/core";
import { PortalActivity } from "@modules/village";

import { createState, test } from "../../utils";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { values } from "rambda";

import { MapActivity, MapLocationType } from "@rpg-village/core";
import { MapActivity, MapLocationType } from "@modules/map";

import { createState, test } from "../../utils";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ActivityType, MapActivity } from "@rpg-village/core";
import { ActivityType } from "@modules/activity";
import { MapActivity } from "@modules/map";

import { createState, stashFactory, test } from "../../utils";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BlacksmithCommand, ItemType } from "@rpg-village/core";
import { ItemType } from "@models";
import { BlacksmithCommand } from "@modules/village";

import { createState, test } from "../../../utils";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AttackEffectType, BlacksmithCommand, EffectType, EquipmentSlot, StashLocation } from "@rpg-village/core";
import { AttackEffectType, EffectType, EquipmentSlot } from "@models";
import { BlacksmithCommand, StashLocation } from "@modules/village";

import { createState, test } from "../../../utils";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { MapLocationType, PortalCommand } from "@rpg-village/core";
import { MapLocationType } from "@modules/map";
import { PortalCommand } from "@modules/village";

import { createState, test } from "../../../utils";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { MapLocationType, PortalActivity, PortalCommand } from "@rpg-village/core";
import { MapLocationType } from "@modules/map";
import { PortalActivity, PortalCommand } from "@modules/village";

import { createState, test } from "../../../utils";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { values } from "rambda";

import { AttackEffectType, EffectType, ItemType, PortalCommand } from "@rpg-village/core";
import { AttackEffectType, EffectType, ItemType } from "@models";
import { PortalCommand } from "@modules/village";

import { createState, test } from "../../../utils";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ItemType, RuneWorkshopCommand } from "@rpg-village/core";
import { ItemType } from "@models";
import { RuneWorkshopCommand } from "@modules/village";

import { createState, test } from "../../../utils";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ItemType } from "@models";
import { RuneWorkshopCommand } from "@modules/village";

import { createState, test } from "../../../utils";

test("should empower rune with soul", {
initState: createState(({ village }) => [
village({ stash: { resource: { soul: 5 }, items: [{ id: "rune", itemType: ItemType.Rune, soul: 2 }] } }),
]),
commands: [
{
command: RuneWorkshopCommand.DismantleRune,
args: {
runeId: "rune",
},
},
],
expectedState: { village: { stash: { resource: { soul: 7 }, items: [] } } },
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ItemType } from "@models";
import { RuneWorkshopCommand } from "@modules/village";

import { createState, test } from "../../../utils";

test("should empower rune with soul", {
initState: createState(({ village }) => [
village({ stash: { resource: { soul: 5 }, items: [{ id: "rune", itemType: ItemType.Rune, soul: 1 }] } }),
]),
commands: [
{
command: RuneWorkshopCommand.EmpowerRune,
args: {
runeId: "rune",
soul: 1,
},
},
],
expectedState: {
village: { stash: { resource: { soul: 4 }, items: [{ id: "rune", itemType: ItemType.Rune, soul: 2 }] } },
},
});
Loading

0 comments on commit 21ba589

Please sign in to comment.