@rpgjs/testing 4.2.2 → 5.0.0-alpha.25
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/dist/index.d.ts +239 -0
- package/dist/index.js +315 -0
- package/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@signe_di@2.6.0/node_modules/@signe/di/dist/index.js +366 -0
- package/dist/node_modules/.pnpm/@signe_di@2.6.0/node_modules/@signe/di/dist/index.js.map +1 -0
- package/dist/setup.d.ts +0 -0
- package/dist/setup.js +32 -0
- package/dist/setup.js.map +1 -0
- package/package.json +22 -23
- package/src/index.ts +570 -220
- package/src/setup.ts +34 -0
- package/tsconfig.json +16 -24
- package/vite.config.ts +40 -0
- package/CHANGELOG.md +0 -166
- package/LICENSE +0 -19
- package/lib/index.d.ts +0 -144
- package/lib/index.js +0 -186
- package/lib/index.js.map +0 -1
package/src/setup.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import 'vitest-webgl-canvas-mock'
|
|
2
|
+
|
|
3
|
+
const LOAD_FAILURE_SRC = 'LOAD_FAILURE_SRC';
|
|
4
|
+
|
|
5
|
+
// mock image loading
|
|
6
|
+
Object.defineProperty(global.Image.prototype, 'src', {
|
|
7
|
+
set(src) {
|
|
8
|
+
if (src === LOAD_FAILURE_SRC) {
|
|
9
|
+
setTimeout(() => this.onerror(new Error('mocked error')));
|
|
10
|
+
} else if (src.startsWith('data')) {
|
|
11
|
+
setTimeout(() => this.dispatchEvent(new Event("load")));
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
Object.defineProperty(global.window.HTMLMediaElement.prototype, 'play', {
|
|
17
|
+
configurable: true,
|
|
18
|
+
get() {
|
|
19
|
+
setTimeout(() => (this.onloadeddata && this.onloadeddata()))
|
|
20
|
+
return () => { }
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
Object.defineProperty(global.window.HTMLMediaElement.prototype, 'load', {
|
|
25
|
+
configurable: true,
|
|
26
|
+
get() {
|
|
27
|
+
setTimeout(() => (this.onloadeddata && this.onloadeddata()))
|
|
28
|
+
return () => { }
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
window.document.body.innerHTML = `<div id="rpg"></div>`
|
|
33
|
+
|
|
34
|
+
console.error = () => {}
|
package/tsconfig.json
CHANGED
|
@@ -1,25 +1,17 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
"noImplicitReturns": false,
|
|
19
|
-
"declaration": true,
|
|
20
|
-
"stripInternal": true
|
|
21
|
-
},
|
|
22
|
-
"include": [
|
|
23
|
-
"src"
|
|
24
|
-
]
|
|
25
|
-
}
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"outDir": "dist",
|
|
8
|
+
"rootDir": "src",
|
|
9
|
+
"strict": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"forceConsistentCasingInFileNames": true,
|
|
13
|
+
"types": ["node"]
|
|
14
|
+
},
|
|
15
|
+
"include": ["src/**/*", "src/types/**/*"],
|
|
16
|
+
"exclude": ["node_modules", "dist"]
|
|
17
|
+
}
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { defineConfig } from 'vite'
|
|
2
|
+
import dts from 'vite-plugin-dts'
|
|
3
|
+
|
|
4
|
+
// List of Node.js built-in modules to mark as external
|
|
5
|
+
const nodeBuiltins = [
|
|
6
|
+
'fs', 'path', 'os', 'crypto', 'util', 'events', 'stream', 'buffer',
|
|
7
|
+
'url', 'querystring', 'http', 'https', 'net', 'tls', 'child_process',
|
|
8
|
+
'cluster', 'dgram', 'dns', 'domain', 'readline', 'repl', 'tty', 'vm',
|
|
9
|
+
'zlib', 'assert', 'constants', 'module', 'perf_hooks', 'process',
|
|
10
|
+
'punycode', 'string_decoder', 'timers', 'trace_events', 'v8', 'worker_threads'
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
export default defineConfig({
|
|
14
|
+
plugins: [
|
|
15
|
+
dts({
|
|
16
|
+
include: ['src/**/*.ts'],
|
|
17
|
+
outDir: 'dist'
|
|
18
|
+
})
|
|
19
|
+
],
|
|
20
|
+
build: {
|
|
21
|
+
target: 'esnext',
|
|
22
|
+
sourcemap: true,
|
|
23
|
+
minify: false,
|
|
24
|
+
lib: {
|
|
25
|
+
entry: {
|
|
26
|
+
index: 'src/index.ts',
|
|
27
|
+
setup: 'src/setup.ts'
|
|
28
|
+
},
|
|
29
|
+
formats: ['es'],
|
|
30
|
+
fileName: (format, entryName) => `${entryName}.js`
|
|
31
|
+
},
|
|
32
|
+
rollupOptions: {
|
|
33
|
+
external: [/@rpgjs/, 'esbuild', 'canvasengine', '@canvasengine/presets', 'rxjs', 'pixi.js', 'vitest-webgl-canvas-mock'],
|
|
34
|
+
output: {
|
|
35
|
+
preserveModules: true,
|
|
36
|
+
preserveModulesRoot: 'src'
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
})
|
package/CHANGELOG.md
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
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.2.2](https://github.com/RSamaium/RPG-JS/compare/v4.2.1...v4.2.2) (2024-01-15)
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package @rpgjs/testing
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
## [4.2.1](https://github.com/RSamaium/RPG-JS/compare/v4.2.0...v4.2.1) (2024-01-12)
|
|
15
|
-
|
|
16
|
-
**Note:** Version bump only for package @rpgjs/testing
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
# [4.2.0](https://github.com/RSamaium/RPG-JS/compare/v4.1.3...v4.2.0) (2023-12-09)
|
|
23
|
-
|
|
24
|
-
**Note:** Version bump only for package @rpgjs/testing
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
## [4.1.3](https://github.com/RSamaium/RPG-JS/compare/v4.1.2...v4.1.3) (2023-11-17)
|
|
31
|
-
|
|
32
|
-
**Note:** Version bump only for package @rpgjs/testing
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
## [4.1.2](https://github.com/RSamaium/RPG-JS/compare/v4.1.1...v4.1.2) (2023-10-30)
|
|
39
|
-
|
|
40
|
-
**Note:** Version bump only for package @rpgjs/testing
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
## [4.1.1](https://github.com/RSamaium/RPG-JS/compare/v4.1.0...v4.1.1) (2023-10-27)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
### Bug Fixes
|
|
50
|
-
|
|
51
|
-
* **scene:** click in scene map ([04d56d6](https://github.com/RSamaium/RPG-JS/commit/04d56d6e07c58e2c039732e35ae3b94fc6751fa5))
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
# [4.1.0](https://github.com/RSamaium/RPG-JS/compare/v4.0.5...v4.1.0) (2023-10-20)
|
|
58
|
-
|
|
59
|
-
**Note:** Version bump only for package @rpgjs/testing
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
## 4.0.5 (2023-10-18)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
### Bug Fixes
|
|
69
|
-
|
|
70
|
-
* flickering motion of an event as it moves ([b2b8832](https://github.com/RSamaium/RPG-JS/commit/b2b8832a1582933afb64c698f40d1b0e72021780))
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
## 4.0.4 (2023-10-13)
|
|
77
|
-
|
|
78
|
-
**Note:** Version bump only for package @rpgjs/testing
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
## 4.0.3 (2023-10-10)
|
|
85
|
-
|
|
86
|
-
**Note:** Version bump only for package @rpgjs/testing
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
## 4.0.2 (2023-10-03)
|
|
93
|
-
|
|
94
|
-
**Note:** Version bump only for package @rpgjs/testing
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
## 4.0.1 (2023-10-03)
|
|
101
|
-
|
|
102
|
-
**Note:** Version bump only for package @rpgjs/testing
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
# 4.0.0-rc.13 (2023-09-09)
|
|
109
|
-
|
|
110
|
-
**Note:** Version bump only for package @rpgjs/testing
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
# 4.0.0-rc.12 (2023-09-08)
|
|
117
|
-
|
|
118
|
-
**Note:** Version bump only for package @rpgjs/testing
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
# 4.0.0-rc.11 (2023-08-30)
|
|
125
|
-
|
|
126
|
-
**Note:** Version bump only for package @rpgjs/testing
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
# 4.0.0-rc.10 (2023-08-28)
|
|
133
|
-
|
|
134
|
-
**Note:** Version bump only for package @rpgjs/testing
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
# 4.0.0-rc.9 (2023-08-25)
|
|
141
|
-
|
|
142
|
-
**Note:** Version bump only for package @rpgjs/testing
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
# 4.0.0-rc.8 (2023-08-23)
|
|
149
|
-
|
|
150
|
-
**Note:** Version bump only for package @rpgjs/testing
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
# [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)
|
|
157
|
-
|
|
158
|
-
**Note:** Version bump only for package @rpgjs/testing
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
# [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)
|
|
165
|
-
|
|
166
|
-
**Note:** Version bump only for package @rpgjs/testing
|
package/LICENSE
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { ModuleType } from '@rpgjs/common';
|
|
2
|
-
import { RpgServerEngine, RpgPlayer } from '@rpgjs/server';
|
|
3
|
-
import { RpgClientEngine } from '@rpgjs/client';
|
|
4
|
-
import { ObjectFixtureList, Position } from '@rpgjs/types';
|
|
5
|
-
type ClientTesting = {
|
|
6
|
-
client: RpgClientEngine;
|
|
7
|
-
socket: any;
|
|
8
|
-
playerId: string;
|
|
9
|
-
player: RpgPlayer;
|
|
10
|
-
};
|
|
11
|
-
type PositionMap = string | Position;
|
|
12
|
-
interface Testing {
|
|
13
|
-
/**
|
|
14
|
-
* Allows you to create a client and get fixtures to manipulate it during tests
|
|
15
|
-
*
|
|
16
|
-
* Returns:
|
|
17
|
-
*
|
|
18
|
-
* ```ts
|
|
19
|
-
* {
|
|
20
|
-
* client: RpgClientEngine,
|
|
21
|
-
* socket: any,
|
|
22
|
-
* playerId: string
|
|
23
|
-
* player: RpgPlayer
|
|
24
|
-
* }
|
|
25
|
-
* ```
|
|
26
|
-
*
|
|
27
|
-
* @title Create Client
|
|
28
|
-
* @method createClient()
|
|
29
|
-
* @returns {Promise<ClientTesting>}
|
|
30
|
-
* @memberof FixtureTesting
|
|
31
|
-
*/
|
|
32
|
-
createClient(): Promise<ClientTesting>;
|
|
33
|
-
/**
|
|
34
|
-
* Create another client, add it to the map and send the information to the first client
|
|
35
|
-
*
|
|
36
|
-
* @title Add Other Client In Map
|
|
37
|
-
* @method addOtherClientInMap(firstClient,mapId,position?)
|
|
38
|
-
* @param {RpgClientEngine} firstClient
|
|
39
|
-
* @param {string} mapId
|
|
40
|
-
* @param {Position | string} [position]
|
|
41
|
-
* @returns {Promise<ClientTesting>}
|
|
42
|
-
* @since 3.2.0
|
|
43
|
-
* @memberof FixtureTesting
|
|
44
|
-
*/
|
|
45
|
-
addOtherClientInMap(firstClient: RpgClientEngine, mapId: string, position?: PositionMap): Promise<ClientTesting>;
|
|
46
|
-
/**
|
|
47
|
-
* Get server
|
|
48
|
-
*
|
|
49
|
-
* @prop {RpgServerEngine} server
|
|
50
|
-
* @memberof FixtureTesting
|
|
51
|
-
*/
|
|
52
|
-
server: RpgServerEngine;
|
|
53
|
-
/**
|
|
54
|
-
* Allows you to change the map. This function on the tests also allows to render with PIXI on the client side
|
|
55
|
-
*
|
|
56
|
-
* @title Change Map
|
|
57
|
-
* @method changeMap(client,mapId,position?)
|
|
58
|
-
* @param {RpgClientEngine} client
|
|
59
|
-
* @param {string} mapId
|
|
60
|
-
* @param {Position | string} [position]
|
|
61
|
-
* @returns {Promise<void>}
|
|
62
|
-
* @memberof FixtureTesting
|
|
63
|
-
*/
|
|
64
|
-
changeMap(client: RpgClientEngine, mapId: string, position?: PositionMap): Promise<void>;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Allows you to test modules
|
|
68
|
-
*
|
|
69
|
-
* @title Testing
|
|
70
|
-
* @method testing(modules,optionsServer?,optionsClient?)
|
|
71
|
-
* @param {ModuleType[]} modules
|
|
72
|
-
* @param {object} [optionsServer]
|
|
73
|
-
* @param {object} [optionsClient]
|
|
74
|
-
* @returns {Promise<FixtureTesting>}
|
|
75
|
-
* @example
|
|
76
|
-
*
|
|
77
|
-
* ```ts
|
|
78
|
-
* import { testing } from '@rpgjs/testing';
|
|
79
|
-
* import { beforeEach } from 'vitest';
|
|
80
|
-
*
|
|
81
|
-
* beforeEach(async () => {
|
|
82
|
-
* const fixture = await testing([
|
|
83
|
-
* {
|
|
84
|
-
* server: RpgServerModule
|
|
85
|
-
* },
|
|
86
|
-
* ]);
|
|
87
|
-
* const clientFixture = await fixture.createClient();
|
|
88
|
-
* currentPlayer = clientFixture.player;
|
|
89
|
-
* });
|
|
90
|
-
*
|
|
91
|
-
* @memberof Testing
|
|
92
|
-
*/
|
|
93
|
-
export declare function testing(modules: ModuleType[], optionsServer?: any, optionsClient?: any): Promise<Testing>;
|
|
94
|
-
/**
|
|
95
|
-
* Clear caches. Use it after the end of each test
|
|
96
|
-
*
|
|
97
|
-
* ```ts
|
|
98
|
-
* import { clear } from '@rpgjs/testing'
|
|
99
|
-
* import { afterEach } from 'vitest'
|
|
100
|
-
*
|
|
101
|
-
* afterEach(() => {
|
|
102
|
-
* clear()
|
|
103
|
-
* })
|
|
104
|
-
* ```
|
|
105
|
-
*
|
|
106
|
-
* @title Clear
|
|
107
|
-
* @method clear()
|
|
108
|
-
* @returns {void}
|
|
109
|
-
* @memberof Testing
|
|
110
|
-
*/
|
|
111
|
-
export declare function clear(): void;
|
|
112
|
-
/**
|
|
113
|
-
* Allows you to make a tick:
|
|
114
|
-
* 1. on server
|
|
115
|
-
* 2. server sends data to client
|
|
116
|
-
* 3. Client retrieves data and performs inputs (move, etc.) and server reconciliation
|
|
117
|
-
* 4. A tick is performed on the client
|
|
118
|
-
* 5. A tick is performed on VueJS
|
|
119
|
-
*
|
|
120
|
-
* @title Next Tick
|
|
121
|
-
* @method nextTick(client,timestamp?)
|
|
122
|
-
* @param {RpgClientEngine} client
|
|
123
|
-
* @param {number} [timestamp=0] A predefined timestamp
|
|
124
|
-
* @returns {Promise<ObjectFixtureList>}
|
|
125
|
-
* @memberof Testing
|
|
126
|
-
*/
|
|
127
|
-
export declare function nextTick(client: RpgClientEngine, timestamp?: number): Promise<ObjectFixtureList>;
|
|
128
|
-
/**
|
|
129
|
-
* @title Wait a moment
|
|
130
|
-
* @method waitUntil(promise)
|
|
131
|
-
* @param {Promise<any>} promise
|
|
132
|
-
* @returns {Promise<any>}
|
|
133
|
-
* @since 4.0.0
|
|
134
|
-
* @memberof Testing
|
|
135
|
-
* @example
|
|
136
|
-
*
|
|
137
|
-
* ```ts
|
|
138
|
-
* await waitUntil(
|
|
139
|
-
* player.moveRoutes([Move.right()])
|
|
140
|
-
* )
|
|
141
|
-
* ```
|
|
142
|
-
*/
|
|
143
|
-
export declare function waitUntil(promise: Promise<any>): Promise<any>;
|
|
144
|
-
export {};
|
package/lib/index.js
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { HookClient, RpgPlugin } from '@rpgjs/common';
|
|
2
|
-
import { entryPoint, RpgMap, RpgWorld } from '@rpgjs/server';
|
|
3
|
-
import { entryPoint as entryPointClient } from '@rpgjs/client';
|
|
4
|
-
import { MockSocketIo } from 'simple-room';
|
|
5
|
-
const { serverIo, ClientIo } = MockSocketIo;
|
|
6
|
-
let server;
|
|
7
|
-
let clients;
|
|
8
|
-
function changeMap(client, server, mapId, position) {
|
|
9
|
-
return new Promise(async (resolve) => {
|
|
10
|
-
let player = RpgWorld.getPlayer(client.playerId);
|
|
11
|
-
const beforeLoading = () => {
|
|
12
|
-
client.PIXI.utils.clearTextureCache();
|
|
13
|
-
};
|
|
14
|
-
const afterLoading = () => {
|
|
15
|
-
client.nextFrame(0);
|
|
16
|
-
RpgPlugin.off(HookClient.BeforeSceneLoading, beforeLoading);
|
|
17
|
-
RpgPlugin.off(HookClient.AfterSceneLoading, afterLoading);
|
|
18
|
-
resolve();
|
|
19
|
-
};
|
|
20
|
-
RpgPlugin.on(HookClient.BeforeSceneLoading, beforeLoading);
|
|
21
|
-
RpgPlugin.on(HookClient.AfterSceneLoading, afterLoading);
|
|
22
|
-
await player.changeMap(mapId, position);
|
|
23
|
-
});
|
|
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<FixtureTesting>}
|
|
34
|
-
* @example
|
|
35
|
-
*
|
|
36
|
-
* ```ts
|
|
37
|
-
* import { testing } from '@rpgjs/testing';
|
|
38
|
-
* import { beforeEach } from 'vitest';
|
|
39
|
-
*
|
|
40
|
-
* beforeEach(async () => {
|
|
41
|
-
* const fixture = await testing([
|
|
42
|
-
* {
|
|
43
|
-
* server: RpgServerModule
|
|
44
|
-
* },
|
|
45
|
-
* ]);
|
|
46
|
-
* const clientFixture = await fixture.createClient();
|
|
47
|
-
* currentPlayer = clientFixture.player;
|
|
48
|
-
* });
|
|
49
|
-
*
|
|
50
|
-
* @memberof Testing
|
|
51
|
-
*/
|
|
52
|
-
export async function testing(modules, optionsServer = {}, optionsClient = {}) {
|
|
53
|
-
RpgPlugin.clear();
|
|
54
|
-
const engine = await entryPoint(modules, {
|
|
55
|
-
io: serverIo,
|
|
56
|
-
standalone: true,
|
|
57
|
-
disableAuth: true,
|
|
58
|
-
...optionsServer
|
|
59
|
-
});
|
|
60
|
-
engine.start(null, false);
|
|
61
|
-
server = engine;
|
|
62
|
-
clients = [];
|
|
63
|
-
const createClient = async function createClient() {
|
|
64
|
-
const client = entryPointClient(modules, {
|
|
65
|
-
io: new ClientIo(),
|
|
66
|
-
standalone: true,
|
|
67
|
-
...optionsClient
|
|
68
|
-
});
|
|
69
|
-
await client.start({
|
|
70
|
-
renderLoop: false
|
|
71
|
-
});
|
|
72
|
-
clients.push(client);
|
|
73
|
-
client.renderer.transitionMode = 0;
|
|
74
|
-
const playerId = client.playerId;
|
|
75
|
-
return {
|
|
76
|
-
client,
|
|
77
|
-
socket: client.socket,
|
|
78
|
-
playerId,
|
|
79
|
-
player: RpgWorld.getPlayer(playerId)
|
|
80
|
-
};
|
|
81
|
-
};
|
|
82
|
-
const _changeMap = function (client, mapId, position) {
|
|
83
|
-
return changeMap(client, server, mapId, position);
|
|
84
|
-
};
|
|
85
|
-
return {
|
|
86
|
-
createClient,
|
|
87
|
-
async addOtherClientInMap(firstClient, mapId, position) {
|
|
88
|
-
const clientFixture = await createClient();
|
|
89
|
-
const client = clientFixture.client;
|
|
90
|
-
await _changeMap(client, mapId, position);
|
|
91
|
-
await nextTick(firstClient);
|
|
92
|
-
return clientFixture;
|
|
93
|
-
},
|
|
94
|
-
server: engine,
|
|
95
|
-
changeMap: _changeMap
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Clear caches. Use it after the end of each test
|
|
100
|
-
*
|
|
101
|
-
* ```ts
|
|
102
|
-
* import { clear } from '@rpgjs/testing'
|
|
103
|
-
* import { afterEach } from 'vitest'
|
|
104
|
-
*
|
|
105
|
-
* afterEach(() => {
|
|
106
|
-
* clear()
|
|
107
|
-
* })
|
|
108
|
-
* ```
|
|
109
|
-
*
|
|
110
|
-
* @title Clear
|
|
111
|
-
* @method clear()
|
|
112
|
-
* @returns {void}
|
|
113
|
-
* @memberof Testing
|
|
114
|
-
*/
|
|
115
|
-
export function clear() {
|
|
116
|
-
server?.world.clear();
|
|
117
|
-
clients?.forEach(client => client.reset());
|
|
118
|
-
RpgMap.buffer.clear();
|
|
119
|
-
RpgPlugin.clear();
|
|
120
|
-
serverIo.clear();
|
|
121
|
-
serverIo.events.clear();
|
|
122
|
-
window.document.body.innerHTML = `<div id="rpg"></div>`;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Allows you to make a tick:
|
|
126
|
-
* 1. on server
|
|
127
|
-
* 2. server sends data to client
|
|
128
|
-
* 3. Client retrieves data and performs inputs (move, etc.) and server reconciliation
|
|
129
|
-
* 4. A tick is performed on the client
|
|
130
|
-
* 5. A tick is performed on VueJS
|
|
131
|
-
*
|
|
132
|
-
* @title Next Tick
|
|
133
|
-
* @method nextTick(client,timestamp?)
|
|
134
|
-
* @param {RpgClientEngine} client
|
|
135
|
-
* @param {number} [timestamp=0] A predefined timestamp
|
|
136
|
-
* @returns {Promise<ObjectFixtureList>}
|
|
137
|
-
* @memberof Testing
|
|
138
|
-
*/
|
|
139
|
-
export async function nextTick(client, timestamp = 0) {
|
|
140
|
-
server.nextTick(timestamp);
|
|
141
|
-
await server.send();
|
|
142
|
-
return new Promise((resolve) => {
|
|
143
|
-
client.objects.subscribe(async (objects) => {
|
|
144
|
-
await client.processInput();
|
|
145
|
-
client.nextFrame(timestamp);
|
|
146
|
-
await client.vueInstance.$nextTick();
|
|
147
|
-
resolve(objects);
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* @title Wait a moment
|
|
153
|
-
* @method waitUntil(promise)
|
|
154
|
-
* @param {Promise<any>} promise
|
|
155
|
-
* @returns {Promise<any>}
|
|
156
|
-
* @since 4.0.0
|
|
157
|
-
* @memberof Testing
|
|
158
|
-
* @example
|
|
159
|
-
*
|
|
160
|
-
* ```ts
|
|
161
|
-
* await waitUntil(
|
|
162
|
-
* player.moveRoutes([Move.right()])
|
|
163
|
-
* )
|
|
164
|
-
* ```
|
|
165
|
-
*/
|
|
166
|
-
export function waitUntil(promise) {
|
|
167
|
-
let tick = 0;
|
|
168
|
-
let finish = false;
|
|
169
|
-
return new Promise((resolve, reject) => {
|
|
170
|
-
promise.then(() => {
|
|
171
|
-
finish = true;
|
|
172
|
-
resolve();
|
|
173
|
-
}).catch(reject);
|
|
174
|
-
const timeout = () => {
|
|
175
|
-
setTimeout(() => {
|
|
176
|
-
if (!finish) {
|
|
177
|
-
tick++;
|
|
178
|
-
server.nextTick(tick);
|
|
179
|
-
timeout();
|
|
180
|
-
}
|
|
181
|
-
}, 50);
|
|
182
|
-
};
|
|
183
|
-
timeout();
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAc,SAAS,EAAE,MAAM,eAAe,CAAA;AACjE,OAAO,EAAE,UAAU,EAAmB,MAAM,EAAE,QAAQ,EAAa,MAAM,eAAe,CAAA;AACxF,OAAO,EAAE,UAAU,IAAI,gBAAgB,EAAmB,MAAM,eAAe,CAAA;AAE/E,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,YAAY,CAAA;AAqE3C,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;QAEhD,MAAM,aAAa,GAAG,GAAG,EAAE;YACvB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,iBAAiB,EAAE,CAAA;QACzC,CAAC,CAAA;QAED,MAAM,YAAY,GAAG,GAAG,EAAE;YACtB,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;YACnB,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,kBAAkB,EAAE,aAAa,CAAC,CAAA;YAC3D,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,iBAAiB,EAAE,YAAY,CAAC,CAAA;YACzD,O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