# Unit Tests API

Get the functions from the @rpgjs/testing package:

import { RpgPlayer } from '@rpgjs/server'
import { RpgClientEngine } from '@rpgjs/client'
import { testing, clear } from '@rpgjs/testing'
import modules from '../src/modules'

let player: RpgPlayer
let client: RpgClientEngine

beforeEach(async () => {
    const fixture = testing(modules, {
        basePath: __dirname + '/../'
    })
    const clientFixture = await fixture.createClient()
    client = clientFixture.client
    player = clientFixture.player
})

test('test player', () => {
    expect(player).toBeDefined()
})

test('test client', () => {
    expect(client).toBeDefined()
})

afterEach(() => {
    clear()
})

# Testing API


# Testing

  • Method: testing(modules,optionsServer?,optionsClient?)
  • Arguments:
    • {ModuleType[]} modules. (Optional: false)
    • {object} optionsServer. (Optional: true)
    • {object} optionsClient. (Optional: true)
  • Return: Promise
  • Usage:

Allows you to test modules


# Clear

  • Method: clear()
  • Return: void
  • Usage:

Clear caches. Use it after the end of each test

import { clear } from '@rpgjs/testing'

// with jest
afterEach(() => {
     clear()
})

# Next Tick

  • Method: nextTick(client,timestamp?)
  • Arguments:
    • { RpgClientEngine} client. (Optional: false)
    • {number} timestamp. A predefined timestamp (Optional: true)
  • Return: Promise
  • Usage:

Allows you to make a tick:

  1. on server
  2. server sends data to client
  3. Client retrieves data and performs inputs (move, etc.) and server reconciliation
  4. A tick is performed on the client
  5. A tick is performed on VueJS

# Fixture API


# Create Client

  • Method: createClient()
  • Return: Promise
  • Usage:

Allows you to create a client and get fixtures to manipulate it during tests


# Add Other Client In Map

  • Since: 3.2.0
  • Method: addOtherClientInMap(firstClient,mapId,position?)
  • Arguments:
    • { RpgClientEngine} firstClient. (Optional: false)
    • {string} mapId. (Optional: false)
    • {Position | string} position. (Optional: true)
  • Return: Promise
  • Usage:

Create another client, add it to the map and send the information to the first client


# server

Get server


# Change Map

  • Method: changeMap(client,mapId,position?)
  • Arguments:
    • { RpgClientEngine} client. (Optional: false)
    • {string} mapId. (Optional: false)
    • {Position | string} position. (Optional: true)
  • Return: Promise
  • Usage:

Allows you to change the map. This function on the tests also allows to render with PIXI on the client side