@rpgjs/testing 4.0.0-beta.8 → 4.0.0-rc.10
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/CHANGELOG.md +40 -0
- package/lib/index.js +19 -26
- package/lib/index.js.map +1 -1
- package/package.json +8 -10
- package/src/index.ts +216 -0
- package/tsconfig.json +25 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
# 4.0.0-rc.10 (2023-08-28)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @rpgjs/testing
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# 4.0.0-rc.9 (2023-08-25)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @rpgjs/testing
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# 4.0.0-rc.8 (2023-08-23)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @rpgjs/testing
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# [4.0.0-rc.6](https://github.com/RSamaium/RPG-JS/compare/v4.0.0-rc.5...v4.0.0-rc.6) (2023-08-20)
|
|
31
|
+
|
|
32
|
+
**Note:** Version bump only for package @rpgjs/testing
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# [4.0.0-rc.5](https://github.com/RSamaium/RPG-JS/compare/v4.0.0-rc.4...v4.0.0-rc.5) (2023-08-16)
|
|
39
|
+
|
|
40
|
+
**Note:** Version bump only for package @rpgjs/testing
|
package/lib/index.js
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const server_1 = require("@rpgjs/server");
|
|
6
|
-
const client_1 = require("@rpgjs/client");
|
|
7
|
-
const { serverIo, ClientIo } = common_1.MockIo;
|
|
1
|
+
import { HookClient, MockIo, RpgPlugin } from '@rpgjs/common';
|
|
2
|
+
import { entryPoint, RpgMap, RpgWorld } from '@rpgjs/server';
|
|
3
|
+
import { entryPoint as entryPointClient } from '@rpgjs/client';
|
|
4
|
+
const { serverIo, ClientIo } = MockIo;
|
|
8
5
|
let server;
|
|
9
6
|
let clients;
|
|
10
7
|
function changeMap(client, server, mapId, position) {
|
|
11
8
|
return new Promise(async (resolve) => {
|
|
12
|
-
let player =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
let player = RpgWorld.getPlayer(client.playerId);
|
|
10
|
+
RpgPlugin.off(HookClient.BeforeSceneLoading);
|
|
11
|
+
RpgPlugin.off(HookClient.AfterSceneLoading);
|
|
12
|
+
RpgPlugin.on(HookClient.BeforeSceneLoading, () => {
|
|
16
13
|
client.PIXI.utils.clearTextureCache();
|
|
17
14
|
});
|
|
18
|
-
|
|
15
|
+
RpgPlugin.on(HookClient.AfterSceneLoading, () => {
|
|
19
16
|
client.nextFrame(0); // render scene
|
|
20
17
|
resolve();
|
|
21
18
|
});
|
|
@@ -33,9 +30,9 @@ function changeMap(client, server, mapId, position) {
|
|
|
33
30
|
* @returns {Promise<Testing>}
|
|
34
31
|
* @memberof Testing
|
|
35
32
|
*/
|
|
36
|
-
async function testing(modules, optionsServer = {}, optionsClient = {}) {
|
|
37
|
-
|
|
38
|
-
const engine = await
|
|
33
|
+
export async function testing(modules, optionsServer = {}, optionsClient = {}) {
|
|
34
|
+
RpgPlugin.clear();
|
|
35
|
+
const engine = await entryPoint(modules, {
|
|
39
36
|
io: serverIo,
|
|
40
37
|
standalone: true,
|
|
41
38
|
...optionsServer
|
|
@@ -44,7 +41,7 @@ async function testing(modules, optionsServer = {}, optionsClient = {}) {
|
|
|
44
41
|
server = engine;
|
|
45
42
|
clients = [];
|
|
46
43
|
const createClient = async function createClient() {
|
|
47
|
-
const client = (
|
|
44
|
+
const client = entryPointClient(modules, {
|
|
48
45
|
io: new ClientIo(),
|
|
49
46
|
standalone: true,
|
|
50
47
|
...optionsClient
|
|
@@ -59,7 +56,7 @@ async function testing(modules, optionsServer = {}, optionsClient = {}) {
|
|
|
59
56
|
client,
|
|
60
57
|
socket: client.socket,
|
|
61
58
|
playerId,
|
|
62
|
-
player:
|
|
59
|
+
player: RpgWorld.getPlayer(playerId)
|
|
63
60
|
};
|
|
64
61
|
};
|
|
65
62
|
const _changeMap = function (client, mapId, position) {
|
|
@@ -78,7 +75,6 @@ async function testing(modules, optionsServer = {}, optionsClient = {}) {
|
|
|
78
75
|
changeMap: _changeMap
|
|
79
76
|
};
|
|
80
77
|
}
|
|
81
|
-
exports.testing = testing;
|
|
82
78
|
/**
|
|
83
79
|
* Clear caches. Use it after the end of each test
|
|
84
80
|
*
|
|
@@ -96,15 +92,14 @@ exports.testing = testing;
|
|
|
96
92
|
* @returns {void}
|
|
97
93
|
* @memberof Testing
|
|
98
94
|
*/
|
|
99
|
-
function clear() {
|
|
95
|
+
export function clear() {
|
|
100
96
|
server.world.clear();
|
|
101
97
|
clients.forEach(client => client.reset());
|
|
102
|
-
|
|
103
|
-
|
|
98
|
+
RpgMap.buffer.clear();
|
|
99
|
+
RpgPlugin.clear();
|
|
104
100
|
serverIo.clear();
|
|
105
101
|
window.document.body.innerHTML = `<div id="rpg"></div>`;
|
|
106
102
|
}
|
|
107
|
-
exports.clear = clear;
|
|
108
103
|
/**
|
|
109
104
|
* Allows you to make a tick:
|
|
110
105
|
* 1. on server
|
|
@@ -120,7 +115,7 @@ exports.clear = clear;
|
|
|
120
115
|
* @returns {Promise<ObjectFixtureList>}
|
|
121
116
|
* @memberof Testing
|
|
122
117
|
*/
|
|
123
|
-
function nextTick(client, timestamp = 0) {
|
|
118
|
+
export function nextTick(client, timestamp = 0) {
|
|
124
119
|
server.nextTick(timestamp);
|
|
125
120
|
server.send();
|
|
126
121
|
return new Promise((resolve) => {
|
|
@@ -132,8 +127,7 @@ function nextTick(client, timestamp = 0) {
|
|
|
132
127
|
});
|
|
133
128
|
});
|
|
134
129
|
}
|
|
135
|
-
|
|
136
|
-
function waitUntil(promise) {
|
|
130
|
+
export function waitUntil(promise) {
|
|
137
131
|
let tick = 0;
|
|
138
132
|
let finish = false;
|
|
139
133
|
return new Promise((resolve, reject) => {
|
|
@@ -153,5 +147,4 @@ function waitUntil(promise) {
|
|
|
153
147
|
timeout();
|
|
154
148
|
});
|
|
155
149
|
}
|
|
156
|
-
exports.waitUntil = waitUntil;
|
|
157
150
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAc,MAAM,EAAc,SAAS,EAAE,MAAM,eAAe,CAAA;AACrF,OAAO,EAAE,UAAU,EAAmB,MAAM,EAAE,QAAQ,EAAa,MAAM,eAAe,CAAA;AACxF,OAAO,EAAE,UAAU,IAAI,gBAAgB,EAAmB,MAAM,eAAe,CAAA;AAG/E,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAA;AA0DrC,IAAI,MAAuB,CAAA;AAC3B,IAAI,OAA0B,CAAA;AAE9B,SAAS,SAAS,CAAC,MAAuB,EAAE,MAAuB,EAAE,KAAa,EAAE,QAAsB;IACtG,OAAO,IAAI,OAAO,CAAC,KAAK,EAAE,OAAY,EAAE,EAAE;QACtC,IAAI,MAAM,GAAG,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;QAChD,SAA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CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rpgjs/testing",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-rc.10",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -10,21 +10,19 @@
|
|
|
10
10
|
"watch": "tsc -w",
|
|
11
11
|
"build": "tsc"
|
|
12
12
|
},
|
|
13
|
-
"files": [
|
|
14
|
-
"lib"
|
|
15
|
-
],
|
|
16
13
|
"keywords": [],
|
|
17
14
|
"author": "Samuel Ronce",
|
|
18
15
|
"license": "MIT",
|
|
19
16
|
"dependencies": {
|
|
20
|
-
"@rpgjs/client": "^4.0.0-
|
|
21
|
-
"@rpgjs/common": "^4.0.0-
|
|
22
|
-
"@rpgjs/server": "^4.0.0-
|
|
23
|
-
"@rpgjs/types": "^4.0.0-
|
|
17
|
+
"@rpgjs/client": "^4.0.0-rc.10",
|
|
18
|
+
"@rpgjs/common": "^4.0.0-rc.10",
|
|
19
|
+
"@rpgjs/server": "^4.0.0-rc.10",
|
|
20
|
+
"@rpgjs/types": "^4.0.0-rc.10"
|
|
24
21
|
},
|
|
25
|
-
"gitHead": "
|
|
22
|
+
"gitHead": "880ba73ce6aac31d2d04b9a8261b86ff44424079",
|
|
26
23
|
"devDependencies": {
|
|
27
24
|
"@types/css-font-loading-module": "^0.0.8",
|
|
28
25
|
"typescript": "^5.0.2"
|
|
29
|
-
}
|
|
26
|
+
},
|
|
27
|
+
"type": "module"
|
|
30
28
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { HookClient, HookServer, MockIo, ModuleType, RpgPlugin } from '@rpgjs/common'
|
|
2
|
+
import { entryPoint, RpgServerEngine, RpgMap, RpgWorld, RpgPlayer } from '@rpgjs/server'
|
|
3
|
+
import { entryPoint as entryPointClient, RpgClientEngine } from '@rpgjs/client'
|
|
4
|
+
import { ObjectFixtureList, Position } from '@rpgjs/types'
|
|
5
|
+
|
|
6
|
+
const { serverIo, ClientIo } = MockIo
|
|
7
|
+
|
|
8
|
+
type ClientTesting = {
|
|
9
|
+
client: RpgClientEngine,
|
|
10
|
+
socket: any,
|
|
11
|
+
playerId: string
|
|
12
|
+
player: RpgPlayer
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type PositionMap = string | Position
|
|
16
|
+
|
|
17
|
+
interface Testing {
|
|
18
|
+
/**
|
|
19
|
+
* Allows you to create a client and get fixtures to manipulate it during tests
|
|
20
|
+
*
|
|
21
|
+
* @title Create Client
|
|
22
|
+
* @method createClient()
|
|
23
|
+
* @returns {Promise<ClientTesting>}
|
|
24
|
+
* @memberof FixtureTesting
|
|
25
|
+
*/
|
|
26
|
+
createClient(): Promise<ClientTesting>,
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Create another client, add it to the map and send the information to the first client
|
|
30
|
+
*
|
|
31
|
+
* @title Add Other Client In Map
|
|
32
|
+
* @method addOtherClientInMap(firstClient,mapId,position?)
|
|
33
|
+
* @param {RpgClientEngine} firstClient
|
|
34
|
+
* @param {string} mapId
|
|
35
|
+
* @param {Position | string} [position]
|
|
36
|
+
* @returns {Promise<ClientTesting>}
|
|
37
|
+
* @since 3.2.0
|
|
38
|
+
* @memberof FixtureTesting
|
|
39
|
+
*/
|
|
40
|
+
addOtherClientInMap(firstClient: RpgClientEngine, mapId: string, position?: PositionMap): Promise<ClientTesting>
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Get server
|
|
44
|
+
*
|
|
45
|
+
* @prop {RpgServerEngine} server
|
|
46
|
+
* @memberof FixtureTesting
|
|
47
|
+
*/
|
|
48
|
+
server: RpgServerEngine
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Allows you to change the map. This function on the tests also allows to render with PIXI on the client side
|
|
52
|
+
*
|
|
53
|
+
* @title Change Map
|
|
54
|
+
* @method changeMap(client,mapId,position?)
|
|
55
|
+
* @param {RpgClientEngine} client
|
|
56
|
+
* @param {string} mapId
|
|
57
|
+
* @param {Position | string} [position]
|
|
58
|
+
* @returns {Promise<void>}
|
|
59
|
+
* @memberof FixtureTesting
|
|
60
|
+
*/
|
|
61
|
+
changeMap(client: RpgClientEngine, mapId: string, position?: PositionMap): Promise<void>
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let server: RpgServerEngine
|
|
65
|
+
let clients: RpgClientEngine[]
|
|
66
|
+
|
|
67
|
+
function changeMap(client: RpgClientEngine, server: RpgServerEngine, mapId: string, position?: PositionMap): Promise<void> {
|
|
68
|
+
return new Promise(async (resolve: any) => {
|
|
69
|
+
let player = RpgWorld.getPlayer(client.playerId)
|
|
70
|
+
RpgPlugin.off(HookClient.BeforeSceneLoading)
|
|
71
|
+
RpgPlugin.off(HookClient.AfterSceneLoading)
|
|
72
|
+
RpgPlugin.on(HookClient.BeforeSceneLoading, () => {
|
|
73
|
+
client.PIXI.utils.clearTextureCache()
|
|
74
|
+
})
|
|
75
|
+
RpgPlugin.on(HookClient.AfterSceneLoading, () => {
|
|
76
|
+
client.nextFrame(0) // render scene
|
|
77
|
+
resolve()
|
|
78
|
+
})
|
|
79
|
+
await player.changeMap(mapId, position)
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Allows you to test modules
|
|
85
|
+
*
|
|
86
|
+
* @title Testing
|
|
87
|
+
* @method testing(modules,optionsServer?,optionsClient?)
|
|
88
|
+
* @param {ModuleType[]} modules
|
|
89
|
+
* @param {object} [optionsServer]
|
|
90
|
+
* @param {object} [optionsClient]
|
|
91
|
+
* @returns {Promise<Testing>}
|
|
92
|
+
* @memberof Testing
|
|
93
|
+
*/
|
|
94
|
+
export async function testing(modules: ModuleType[], optionsServer: any = {}, optionsClient: any = {}): Promise<Testing> {
|
|
95
|
+
RpgPlugin.clear()
|
|
96
|
+
const engine = await entryPoint(modules, {
|
|
97
|
+
io: serverIo,
|
|
98
|
+
standalone: true,
|
|
99
|
+
...optionsServer
|
|
100
|
+
})
|
|
101
|
+
engine.start(null, false)
|
|
102
|
+
server = engine
|
|
103
|
+
clients = []
|
|
104
|
+
|
|
105
|
+
const createClient = async function createClient() {
|
|
106
|
+
const client = entryPointClient(modules, {
|
|
107
|
+
io: new ClientIo(),
|
|
108
|
+
standalone: true,
|
|
109
|
+
...optionsClient
|
|
110
|
+
})
|
|
111
|
+
await client.start({
|
|
112
|
+
renderLoop: false
|
|
113
|
+
})
|
|
114
|
+
clients.push(client)
|
|
115
|
+
client.renderer.transitionMode = 0
|
|
116
|
+
const playerId = client['gameEngine'].playerId
|
|
117
|
+
return {
|
|
118
|
+
client,
|
|
119
|
+
socket: client.socket,
|
|
120
|
+
playerId,
|
|
121
|
+
player: RpgWorld.getPlayer(playerId)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const _changeMap = function (client: RpgClientEngine, mapId: string, position?: PositionMap) {
|
|
126
|
+
return changeMap(client, server, mapId, position)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return {
|
|
130
|
+
createClient,
|
|
131
|
+
async addOtherClientInMap(firstClient: RpgClientEngine, mapId: string, position?: PositionMap) {
|
|
132
|
+
const clientFixture = await createClient()
|
|
133
|
+
const client = clientFixture.client
|
|
134
|
+
await _changeMap(client, mapId, position)
|
|
135
|
+
await nextTick(firstClient)
|
|
136
|
+
return clientFixture
|
|
137
|
+
},
|
|
138
|
+
server: engine,
|
|
139
|
+
changeMap: _changeMap
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Clear caches. Use it after the end of each test
|
|
145
|
+
*
|
|
146
|
+
* ```ts
|
|
147
|
+
* import { clear } from '@rpgjs/testing'
|
|
148
|
+
*
|
|
149
|
+
* // with jest
|
|
150
|
+
* afterEach(() => {
|
|
151
|
+
* clear()
|
|
152
|
+
* })
|
|
153
|
+
* ```
|
|
154
|
+
*
|
|
155
|
+
* @title Clear
|
|
156
|
+
* @method clear()
|
|
157
|
+
* @returns {void}
|
|
158
|
+
* @memberof Testing
|
|
159
|
+
*/
|
|
160
|
+
export function clear(): void {
|
|
161
|
+
server.world.clear()
|
|
162
|
+
clients.forEach(client => client.reset())
|
|
163
|
+
RpgMap.buffer.clear()
|
|
164
|
+
RpgPlugin.clear()
|
|
165
|
+
serverIo.clear()
|
|
166
|
+
window.document.body.innerHTML = `<div id="rpg"></div>`
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Allows you to make a tick:
|
|
171
|
+
* 1. on server
|
|
172
|
+
* 2. server sends data to client
|
|
173
|
+
* 3. Client retrieves data and performs inputs (move, etc.) and server reconciliation
|
|
174
|
+
* 4. A tick is performed on the client
|
|
175
|
+
* 5. A tick is performed on VueJS
|
|
176
|
+
*
|
|
177
|
+
* @title Next Tick
|
|
178
|
+
* @method nextTick(client,timestamp?)
|
|
179
|
+
* @param {RpgClientEngine} client
|
|
180
|
+
* @param {number} [timestamp=0] A predefined timestamp
|
|
181
|
+
* @returns {Promise<ObjectFixtureList>}
|
|
182
|
+
* @memberof Testing
|
|
183
|
+
*/
|
|
184
|
+
export function nextTick(client: RpgClientEngine, timestamp = 0): Promise<ObjectFixtureList> {
|
|
185
|
+
server.nextTick(timestamp)
|
|
186
|
+
server.send()
|
|
187
|
+
return new Promise((resolve: any) => {
|
|
188
|
+
client.objects.subscribe(async (objects) => {
|
|
189
|
+
await client.processInput()
|
|
190
|
+
client.nextFrame(timestamp)
|
|
191
|
+
await client.vueInstance.$nextTick()
|
|
192
|
+
resolve(objects)
|
|
193
|
+
})
|
|
194
|
+
})
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export function waitUntil(promise: Promise<any>): Promise<any> {
|
|
198
|
+
let tick = 0
|
|
199
|
+
let finish = false
|
|
200
|
+
return new Promise((resolve: any, reject: any) => {
|
|
201
|
+
promise.then(() => {
|
|
202
|
+
finish = true
|
|
203
|
+
resolve()
|
|
204
|
+
}).catch(reject)
|
|
205
|
+
const timeout = () => {
|
|
206
|
+
setTimeout(() => {
|
|
207
|
+
if (!finish) {
|
|
208
|
+
tick++
|
|
209
|
+
server.nextTick(tick)
|
|
210
|
+
timeout()
|
|
211
|
+
}
|
|
212
|
+
}, 10)
|
|
213
|
+
}
|
|
214
|
+
timeout()
|
|
215
|
+
})
|
|
216
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "ES2020",
|
|
5
|
+
"outDir": "./lib",
|
|
6
|
+
"rootDir": "./src",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"sourceMap": true,
|
|
9
|
+
"strictNullChecks": true,
|
|
10
|
+
"strictPropertyInitialization": false,
|
|
11
|
+
"moduleResolution": "node",
|
|
12
|
+
"esModuleInterop": true,
|
|
13
|
+
"removeComments": false,
|
|
14
|
+
"noUnusedParameters": false,
|
|
15
|
+
"noUnusedLocals": false,
|
|
16
|
+
"noImplicitThis": false,
|
|
17
|
+
"noImplicitAny": false,
|
|
18
|
+
"noImplicitReturns": false,
|
|
19
|
+
"declaration": true,
|
|
20
|
+
"stripInternal": true
|
|
21
|
+
},
|
|
22
|
+
"include": [
|
|
23
|
+
"src"
|
|
24
|
+
]
|
|
25
|
+
}
|