2.0.0 • Published 3 months ago
@cardsgame/server-testing v2.0.0
@cardsgame/server-testing
Helps you test your server-side game logic.
- prepares game state and game entities according to your scenario
- helps mimic and test events sent by players
- executes your Actions so you can test the outcome
Usage
One test file per Action you wanna test (example using Jest)
import { type ServerPlayerMessage } from "@cardsgame/server"
import { setupServerTesting } from "@cardsgame/server-testing"
// ...
let state: MyGameStateClass
let deckEvent: ServerPlayerMessage
// Initiate testing lib
const { reset, populateState, makeInteraction, testEvent } = setupServerTesting(
{ action: DrawCards }
)
beforeEach(() => {
// Always reset state first.
// Testing lib internally relies on updated references to the state object
state = myOwnStateSetup()
reset(state)
// Create object to behave as "player touched deck of cards"
deckEvent = makeInteraction({ type: "deck" })
})
test("drawing a card from deck", () => {
// Populate state with some additional entities
populateState([
{ type: "deck" },
childrenNamed(["SA", "SK", "SQ", "SJ", "S10"]),
])
// Test if your `DrawCards` action has proper conditions in place
state.isGameStarted = true
expect(testEvent(deckEvent)).toBe(true)
state.isGameStarted = false
expect(testEvent(deckEvent)).toBe(false)
})
2.0.0
3 months ago
1.7.5
3 months ago
1.7.3
7 months ago
1.7.2
7 months ago
1.7.4
6 months ago
1.7.1
11 months ago
1.7.0
11 months ago
1.5.2
1 year ago
1.6.0
11 months ago
1.5.1
1 year ago
1.5.0
1 year ago
1.4.1
1 year ago
1.4.0
1 year ago
1.2.0
2 years ago
1.1.1
2 years ago
1.1.0
2 years ago
1.3.1
1 year ago
1.3.0
1 year ago
1.1.2
2 years ago
0.22.1
2 years ago
0.21.3
2 years ago
0.22.0
2 years ago
0.21.0
2 years ago
0.20.1
2 years ago
0.20.0
2 years ago
0.19.2
2 years ago
0.19.3
2 years ago
0.21.2
2 years ago
0.20.3
2 years ago
0.21.1
2 years ago
0.20.2
2 years ago
0.19.0
2 years ago
0.18.1
2 years ago
0.19.1
2 years ago
0.18.2
2 years ago
0.18.0
2 years ago
0.17.1
2 years ago
0.17.0
2 years ago
0.16.0
2 years ago
0.15.0
2 years ago
0.14.1
2 years ago
0.14.0
2 years ago
0.13.1
2 years ago