@rpgjs/testing 3.0.1 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +19 -0
- package/lib/index.d.ts +95 -9
- package/lib/index.js +73 -19
- package/lib/index.js.map +1 -1
- package/package.json +6 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (C) 2020 by Samuel Ronce
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
package/lib/index.d.ts
CHANGED
|
@@ -1,15 +1,101 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ModuleType } from '@rpgjs/common';
|
|
2
|
+
import { RpgServerEngine, RpgPlayer } from '@rpgjs/server';
|
|
2
3
|
import { RpgClientEngine } from '@rpgjs/client';
|
|
4
|
+
import { ObjectFixtureList, Position } from '@rpgjs/types';
|
|
5
|
+
declare type ClientTesting = {
|
|
6
|
+
client: RpgClientEngine;
|
|
7
|
+
socket: any;
|
|
8
|
+
playerId: string;
|
|
9
|
+
player: RpgPlayer;
|
|
10
|
+
};
|
|
11
|
+
declare type PositionMap = string | Position;
|
|
3
12
|
interface Testing {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Allows you to create a client and get fixtures to manipulate it during tests
|
|
15
|
+
*
|
|
16
|
+
* @title Create Client
|
|
17
|
+
* @method createClient()
|
|
18
|
+
* @returns {Promise<ClientTesting>}
|
|
19
|
+
* @memberof FixtureTesting
|
|
20
|
+
*/
|
|
21
|
+
createClient(): Promise<ClientTesting>;
|
|
22
|
+
/**
|
|
23
|
+
* Create another client, add it to the map and send the information to the first client
|
|
24
|
+
*
|
|
25
|
+
* @title Add Other Client In Map
|
|
26
|
+
* @method addOtherClientInMap(firstClient,mapId,position?)
|
|
27
|
+
* @param {RpgClientEngine} firstClient
|
|
28
|
+
* @param {string} mapId
|
|
29
|
+
* @param {Position | string} [position]
|
|
30
|
+
* @returns {Promise<ClientTesting>}
|
|
31
|
+
* @since 3.2.0
|
|
32
|
+
* @memberof FixtureTesting
|
|
33
|
+
*/
|
|
34
|
+
addOtherClientInMap(firstClient: RpgClientEngine, mapId: string, position?: PositionMap): Promise<ClientTesting>;
|
|
35
|
+
/**
|
|
36
|
+
* Get server
|
|
37
|
+
*
|
|
38
|
+
* @prop {RpgServerEngine} server
|
|
39
|
+
* @memberof FixtureTesting
|
|
40
|
+
*/
|
|
9
41
|
server: RpgServerEngine;
|
|
10
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Allows you to change the map. This function on the tests also allows to render with PIXI on the client side
|
|
44
|
+
*
|
|
45
|
+
* @title Change Map
|
|
46
|
+
* @method changeMap(client,mapId,position?)
|
|
47
|
+
* @param {RpgClientEngine} client
|
|
48
|
+
* @param {string} mapId
|
|
49
|
+
* @param {Position | string} [position]
|
|
50
|
+
* @returns {Promise<void>}
|
|
51
|
+
* @memberof FixtureTesting
|
|
52
|
+
*/
|
|
53
|
+
changeMap(client: RpgClientEngine, mapId: string, position?: PositionMap): Promise<void>;
|
|
11
54
|
}
|
|
12
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Allows you to test modules
|
|
57
|
+
*
|
|
58
|
+
* @title Testing
|
|
59
|
+
* @method testing(modules,optionsServer?,optionsClient?)
|
|
60
|
+
* @param {ModuleType[]} modules
|
|
61
|
+
* @param {object} [optionsServer]
|
|
62
|
+
* @param {object} [optionsClient]
|
|
63
|
+
* @returns {Promise<Testing>}
|
|
64
|
+
* @memberof Testing
|
|
65
|
+
*/
|
|
66
|
+
export declare function testing(modules: ModuleType[], optionsServer?: any, optionsClient?: any): Promise<Testing>;
|
|
67
|
+
/**
|
|
68
|
+
* Clear caches. Use it after the end of each test
|
|
69
|
+
*
|
|
70
|
+
* ```ts
|
|
71
|
+
* import { clear } from '@rpgjs/testing'
|
|
72
|
+
*
|
|
73
|
+
* // with jest
|
|
74
|
+
* afterEach(() => {
|
|
75
|
+
* clear()
|
|
76
|
+
* })
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* @title Clear
|
|
80
|
+
* @method clear()
|
|
81
|
+
* @returns {void}
|
|
82
|
+
* @memberof Testing
|
|
83
|
+
*/
|
|
13
84
|
export declare function clear(): void;
|
|
14
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Allows you to make a tick:
|
|
87
|
+
* 1. on server
|
|
88
|
+
* 2. server sends data to client
|
|
89
|
+
* 3. Client retrieves data and performs inputs (move, etc.) and server reconciliation
|
|
90
|
+
* 4. A tick is performed on the client
|
|
91
|
+
* 5. A tick is performed on VueJS
|
|
92
|
+
*
|
|
93
|
+
* @title Next Tick
|
|
94
|
+
* @method nextTick(client,timestamp?)
|
|
95
|
+
* @param {RpgClientEngine} client
|
|
96
|
+
* @param {number} [timestamp=0] A predefined timestamp
|
|
97
|
+
* @returns {Promise<ObjectFixtureList>}
|
|
98
|
+
* @memberof Testing
|
|
99
|
+
*/
|
|
100
|
+
export declare function nextTick(client: RpgClientEngine, timestamp?: number): Promise<ObjectFixtureList>;
|
|
15
101
|
export {};
|
package/lib/index.js
CHANGED
|
@@ -7,7 +7,7 @@ const client_1 = require("@rpgjs/client");
|
|
|
7
7
|
const { serverIo, ClientIo } = common_1.MockIo;
|
|
8
8
|
let server;
|
|
9
9
|
let clients;
|
|
10
|
-
function changeMap(client, server, mapId) {
|
|
10
|
+
function changeMap(client, server, mapId, position) {
|
|
11
11
|
return new Promise(async (resolve) => {
|
|
12
12
|
let player = server_1.RpgWorld.getPlayer(client.playerId);
|
|
13
13
|
common_1.RpgPlugin.off(common_1.HookClient.BeforeSceneLoading);
|
|
@@ -19,36 +19,75 @@ function changeMap(client, server, mapId) {
|
|
|
19
19
|
client.nextFrame(0); // render scene
|
|
20
20
|
resolve();
|
|
21
21
|
});
|
|
22
|
-
await player.changeMap(mapId);
|
|
22
|
+
await player.changeMap(mapId, position);
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Allows you to test modules
|
|
27
|
+
*
|
|
28
|
+
* @title Testing
|
|
29
|
+
* @method testing(modules,optionsServer?,optionsClient?)
|
|
30
|
+
* @param {ModuleType[]} modules
|
|
31
|
+
* @param {object} [optionsServer]
|
|
32
|
+
* @param {object} [optionsClient]
|
|
33
|
+
* @returns {Promise<Testing>}
|
|
34
|
+
* @memberof Testing
|
|
35
|
+
*/
|
|
25
36
|
async function testing(modules, optionsServer = {}, optionsClient = {}) {
|
|
26
37
|
common_1.RpgPlugin.clear();
|
|
27
38
|
const engine = await (0, server_1.entryPoint)(modules, Object.assign({ io: serverIo, standalone: true }, optionsServer));
|
|
28
39
|
engine.start(null, false);
|
|
29
40
|
server = engine;
|
|
30
41
|
clients = [];
|
|
42
|
+
const createClient = async function createClient() {
|
|
43
|
+
const client = (0, client_1.entryPoint)(modules, Object.assign({ io: new ClientIo(), standalone: true }, optionsClient));
|
|
44
|
+
await client.start({
|
|
45
|
+
renderLoop: false
|
|
46
|
+
});
|
|
47
|
+
clients.push(client);
|
|
48
|
+
client.renderer.transitionMode = 0;
|
|
49
|
+
const playerId = client['gameEngine'].playerId;
|
|
50
|
+
return {
|
|
51
|
+
client,
|
|
52
|
+
socket: client.socket,
|
|
53
|
+
playerId,
|
|
54
|
+
player: server_1.RpgWorld.getPlayer(playerId)
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
const _changeMap = function (client, mapId, position) {
|
|
58
|
+
return changeMap(client, server, mapId, position);
|
|
59
|
+
};
|
|
31
60
|
return {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
await
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
client,
|
|
41
|
-
socket: client.socket,
|
|
42
|
-
playerId: client['gameEngine'].playerId
|
|
43
|
-
};
|
|
61
|
+
createClient,
|
|
62
|
+
async addOtherClientInMap(firstClient, mapId, position) {
|
|
63
|
+
const clientFixture = await createClient();
|
|
64
|
+
const client = clientFixture.client;
|
|
65
|
+
await _changeMap(client, mapId, position);
|
|
66
|
+
await nextTick(firstClient);
|
|
67
|
+
return clientFixture;
|
|
44
68
|
},
|
|
45
69
|
server: engine,
|
|
46
|
-
changeMap
|
|
47
|
-
return changeMap(client, server, mapId);
|
|
48
|
-
}
|
|
70
|
+
changeMap: _changeMap
|
|
49
71
|
};
|
|
50
72
|
}
|
|
51
73
|
exports.testing = testing;
|
|
74
|
+
/**
|
|
75
|
+
* Clear caches. Use it after the end of each test
|
|
76
|
+
*
|
|
77
|
+
* ```ts
|
|
78
|
+
* import { clear } from '@rpgjs/testing'
|
|
79
|
+
*
|
|
80
|
+
* // with jest
|
|
81
|
+
* afterEach(() => {
|
|
82
|
+
* clear()
|
|
83
|
+
* })
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @title Clear
|
|
87
|
+
* @method clear()
|
|
88
|
+
* @returns {void}
|
|
89
|
+
* @memberof Testing
|
|
90
|
+
*/
|
|
52
91
|
function clear() {
|
|
53
92
|
server.world.clear();
|
|
54
93
|
clients.forEach(client => client.reset());
|
|
@@ -64,12 +103,27 @@ function clear() {
|
|
|
64
103
|
window.document.body.innerHTML = `<div id="rpg"></div>`;
|
|
65
104
|
}
|
|
66
105
|
exports.clear = clear;
|
|
106
|
+
/**
|
|
107
|
+
* Allows you to make a tick:
|
|
108
|
+
* 1. on server
|
|
109
|
+
* 2. server sends data to client
|
|
110
|
+
* 3. Client retrieves data and performs inputs (move, etc.) and server reconciliation
|
|
111
|
+
* 4. A tick is performed on the client
|
|
112
|
+
* 5. A tick is performed on VueJS
|
|
113
|
+
*
|
|
114
|
+
* @title Next Tick
|
|
115
|
+
* @method nextTick(client,timestamp?)
|
|
116
|
+
* @param {RpgClientEngine} client
|
|
117
|
+
* @param {number} [timestamp=0] A predefined timestamp
|
|
118
|
+
* @returns {Promise<ObjectFixtureList>}
|
|
119
|
+
* @memberof Testing
|
|
120
|
+
*/
|
|
67
121
|
function nextTick(client, timestamp = 0) {
|
|
68
|
-
server.
|
|
122
|
+
server.nextTick(timestamp);
|
|
69
123
|
server.send();
|
|
70
124
|
return new Promise((resolve) => {
|
|
71
125
|
client.objects.subscribe(async (objects) => {
|
|
72
|
-
client.processInput();
|
|
126
|
+
await client.processInput();
|
|
73
127
|
client.nextFrame(timestamp);
|
|
74
128
|
await client.vueInstance.$nextTick();
|
|
75
129
|
resolve(objects);
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;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AC;AAXD,4BAWC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rpgjs/testing",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -17,11 +17,12 @@
|
|
|
17
17
|
"author": "Samuel Ronce",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@rpgjs/client": "^3.
|
|
21
|
-
"@rpgjs/common": "^3.
|
|
22
|
-
"@rpgjs/server": "^3.
|
|
20
|
+
"@rpgjs/client": "^3.2.0",
|
|
21
|
+
"@rpgjs/common": "^3.2.0",
|
|
22
|
+
"@rpgjs/server": "^3.2.0",
|
|
23
|
+
"@rpgjs/types": "^3.2.0"
|
|
23
24
|
},
|
|
24
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "90bd3ad9ca9cbd823165c39c6c9b2c97399c7b10",
|
|
25
26
|
"devDependencies": {
|
|
26
27
|
"typescript": "^4.7.4"
|
|
27
28
|
}
|