@akashic/engine-files-reftest-helper 0.1.4 → 1.3.0-beta.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 +1 -1
- package/README.md +23 -5
- package/lib/command.d.ts +11 -0
- package/lib/command.js +64 -0
- package/lib/index.d.ts +1 -4
- package/lib/index.js +22 -45
- package/lib/types/CustomWindow.d.ts +5 -0
- package/lib/types/CustomWindow.js +2 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +1 -0
- package/package.json +6 -7
package/LICENSE
CHANGED
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
# engine-files-reftest-helper
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
|
-
<img src="https://github.com/akashic-games/engine-files-reftest-helper/blob/
|
|
4
|
+
<img src="https://github.com/akashic-games/engine-files-reftest-helper/blob/main/img/akashic.png"/>
|
|
5
5
|
</p>
|
|
6
6
|
|
|
7
7
|
**engine-files-reftest-helper**は、engine-files-reftestでコンテンツを自動実行させるための補助ツールです。
|
|
8
8
|
このツールでできることは以下の通りです。
|
|
9
9
|
* playlogのうち、MessageEventを受け取って`data.type` が `scenario` の時、`msg.data.command.name` の値に応じて処理を実行します。
|
|
10
|
-
* `msg.data.command.name` が `screenshot` の時、スクリーンショットをBASE64
|
|
10
|
+
* `msg.data.command.name` が `screenshot` の時、スクリーンショットをBASE64でエンコードした文字列を指定された形式で出力します。
|
|
11
11
|
* engine-files-reftest側で、その文字列をデコードして `msg.data.command.options.fileName` で指定されたファイル名でその画像を保存します。
|
|
12
|
-
* `msg.data.command.name` が `finish` の時、engine-files-reftest
|
|
12
|
+
* `msg.data.command.name` が `finish` の時、engine-files-reftest側にスクリーンショット取得処理の要求を意味する文字列を指定された形式で出力します。
|
|
13
|
+
* `msg.data.command.name` が `init` の時に、以下のように出力形式を指定することができます。
|
|
14
|
+
* `msg.data.command.options.outputType`: `console`でコンソール出力して、`post`で任意の HTTP エンドポイントに POST リクエストを送信します。出力形式はデフォルトではコンソール出力になっています。
|
|
15
|
+
* `msg.data.command.options.outputUrl`:`post`の時の送信先URLを指定します。
|
|
13
16
|
|
|
14
17
|
## 使い方
|
|
15
18
|
engine-files-reftestのテスト対象コンテンツのディレクトリで以下のコマンドを実行します。
|
|
16
19
|
|
|
17
20
|
```sh
|
|
18
|
-
akashic install @akashic/engine-files-reftest-helper
|
|
21
|
+
akashic install @akashic/engine-files-reftest-helper
|
|
19
22
|
```
|
|
20
23
|
|
|
21
24
|
そのコンテンツのエントリーポイントで以下のコードを追記します
|
|
@@ -45,9 +48,24 @@ npm run build
|
|
|
45
48
|
```sh
|
|
46
49
|
npm test
|
|
47
50
|
```
|
|
51
|
+
|
|
52
|
+
## 注意事項
|
|
53
|
+
本ライブラリはブラウザ上で使うことを想定していますが、IE11等`globalThis.fetch`が無い環境では正しく動作しませんので、`globalThis.fetch`が存在する環境で本ライブラリを使用してください。
|
|
54
|
+
|
|
55
|
+
TODO: `globalThis.fetch`が無い環境でも動作できるようにする
|
|
56
|
+
|
|
57
|
+
## 開発者向け
|
|
58
|
+
|
|
59
|
+
### 本ツールの publish について
|
|
60
|
+
* 以下の手順を踏むことで publish が行われます。
|
|
61
|
+
1. package.json の version を更新したコミットを作成
|
|
62
|
+
2. 1 のコミットで master ブランチを更新する
|
|
63
|
+
3. GitHub Actions のリリースワークフローが実行される
|
|
64
|
+
* package-lock.json が原因で publish に失敗した場合は、`npm i --before <実行時の7日前の日付(yyyy-mm-dd)>` を実行して package-lock.json を更新し、再度 publish 処理を行なってください。
|
|
65
|
+
|
|
48
66
|
## ライセンス
|
|
49
67
|
本リポジトリは MIT License の元で公開されています。
|
|
50
|
-
詳しくは [LICENSE](https://github.com/akashic-games/engine-files-reftest-helper/blob/
|
|
68
|
+
詳しくは [LICENSE](https://github.com/akashic-games/engine-files-reftest-helper/blob/main/LICENSE) をご覧ください。
|
|
51
69
|
|
|
52
70
|
ただし、画像ファイルおよび音声ファイルは
|
|
53
71
|
[CC BY 2.1 JP](https://creativecommons.org/licenses/by/2.1/jp/) の元で公開されています。
|
package/lib/command.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ConsoleApiParameter, CustomWindow, OutputType } from "./types";
|
|
2
|
+
/** engine-files-reftest側にスクリーンショットの保存を要求するためのメッセージ */
|
|
3
|
+
export declare const SCREENSHOT_NOTIFICATION_MESSAGE = "engine-files-reftest:image";
|
|
4
|
+
/** engine-files-reftest側にコンテンツ実行終了を要求するためのメッセージ */
|
|
5
|
+
export declare const END_NOTIFICATION_MESSAGE = "engine-files-reftest:finish";
|
|
6
|
+
export declare function postConsole(param: ConsoleApiParameter): Promise<Response>;
|
|
7
|
+
export declare function screenshot(fileName: string, base64: string): Promise<Response | void>;
|
|
8
|
+
export declare function finish(): Promise<Response | void>;
|
|
9
|
+
export declare function getImageDataUrlFromCanvas(): string;
|
|
10
|
+
export declare function getCustomWindow(): CustomWindow;
|
|
11
|
+
export declare function setPropsToCustomWindow(outputType: OutputType, consoleApiUrl: string): void;
|
package/lib/command.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.END_NOTIFICATION_MESSAGE = exports.SCREENSHOT_NOTIFICATION_MESSAGE = void 0;
|
|
4
|
+
exports.postConsole = postConsole;
|
|
5
|
+
exports.screenshot = screenshot;
|
|
6
|
+
exports.finish = finish;
|
|
7
|
+
exports.getImageDataUrlFromCanvas = getImageDataUrlFromCanvas;
|
|
8
|
+
exports.getCustomWindow = getCustomWindow;
|
|
9
|
+
exports.setPropsToCustomWindow = setPropsToCustomWindow;
|
|
10
|
+
// TODO 以下2つの定数は大規模化したら別リポジトリに切り出す
|
|
11
|
+
/** engine-files-reftest側にスクリーンショットの保存を要求するためのメッセージ */
|
|
12
|
+
exports.SCREENSHOT_NOTIFICATION_MESSAGE = "engine-files-reftest:image";
|
|
13
|
+
/** engine-files-reftest側にコンテンツ実行終了を要求するためのメッセージ */
|
|
14
|
+
exports.END_NOTIFICATION_MESSAGE = "engine-files-reftest:finish";
|
|
15
|
+
function postConsole(param) {
|
|
16
|
+
const windowAsCustom = getCustomWindow();
|
|
17
|
+
const headers = {
|
|
18
|
+
"Accept": "application/json",
|
|
19
|
+
"Content-Type": "application/json; charset=utf-8"
|
|
20
|
+
};
|
|
21
|
+
return fetch(windowAsCustom.consoleApiUrl, { method: "POST", headers, body: JSON.stringify(param) });
|
|
22
|
+
}
|
|
23
|
+
function screenshot(fileName, base64) {
|
|
24
|
+
const windowAsCustom = getCustomWindow();
|
|
25
|
+
switch (windowAsCustom.outputType) {
|
|
26
|
+
case "post":
|
|
27
|
+
return postConsole({ commandName: "screenshot", screenshotData: { fileName, base64 } });
|
|
28
|
+
case "console":
|
|
29
|
+
console.log(exports.SCREENSHOT_NOTIFICATION_MESSAGE, fileName, base64);
|
|
30
|
+
return Promise.resolve();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function finish() {
|
|
34
|
+
const windowAsCustom = getCustomWindow();
|
|
35
|
+
switch (windowAsCustom.outputType) {
|
|
36
|
+
case "post":
|
|
37
|
+
return postConsole({ commandName: "finish" });
|
|
38
|
+
case "console":
|
|
39
|
+
console.log(exports.END_NOTIFICATION_MESSAGE);
|
|
40
|
+
return Promise.resolve();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function getImageDataUrlFromCanvas() {
|
|
44
|
+
getCustomWindow(); // window の存在確認 のために呼び出す
|
|
45
|
+
g.game.render(); // 描画がスキップされてしまうことがあるので、スクリーンショット取得前に現フレームでの描画を行う
|
|
46
|
+
const canvasElements = window.document.getElementsByTagName("canvas");
|
|
47
|
+
const imageUrl = canvasElements[0].toDataURL("image/png");
|
|
48
|
+
const data = imageUrl.match(/^data:image\/png;base64,(.+)$/);
|
|
49
|
+
if (!data) {
|
|
50
|
+
throw new Error("Invalid image data URL");
|
|
51
|
+
}
|
|
52
|
+
return data[1];
|
|
53
|
+
}
|
|
54
|
+
function getCustomWindow() {
|
|
55
|
+
if (typeof window === "undefined") {
|
|
56
|
+
throw new Error("window is undefined");
|
|
57
|
+
}
|
|
58
|
+
return window;
|
|
59
|
+
}
|
|
60
|
+
function setPropsToCustomWindow(outputType, consoleApiUrl) {
|
|
61
|
+
const windowAsCustom = getCustomWindow();
|
|
62
|
+
windowAsCustom.outputType = outputType;
|
|
63
|
+
windowAsCustom.consoleApiUrl = consoleApiUrl;
|
|
64
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const SCREENSHOT_NOTIFICATION_MESSAGE = "engine-files-reftest:image";
|
|
3
|
-
/** engine-files-reftest側にコンテンツ実行終了を要求するためのメッセージ */
|
|
4
|
-
export declare const END_NOTIFICATION_MESSAGE = "engine-files-reftest:finish";
|
|
1
|
+
export {};
|
package/lib/index.js
CHANGED
|
@@ -1,37 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
// TODO 以下2つの定数は大規模化したら別リポジトリに切り出す
|
|
7
|
-
/** engine-files-reftest側にスクリーンショットの保存を要求するためのメッセージ */
|
|
8
|
-
exports.SCREENSHOT_NOTIFICATION_MESSAGE = "engine-files-reftest:image";
|
|
9
|
-
/** engine-files-reftest側にコンテンツ実行終了を要求するためのメッセージ */
|
|
10
|
-
exports.END_NOTIFICATION_MESSAGE = "engine-files-reftest:finish";
|
|
11
|
-
function postConsole(param) {
|
|
12
|
-
const headers = {
|
|
13
|
-
"Accept": "application/json",
|
|
14
|
-
"Content-Type": "application/json; charset=utf-8"
|
|
15
|
-
};
|
|
16
|
-
return fetch(consoleApiUrl, { method: "POST", headers, body: JSON.stringify(param) });
|
|
17
|
-
}
|
|
18
|
-
function screenshot(fileName, base64) {
|
|
19
|
-
switch (outputType) {
|
|
20
|
-
case "post":
|
|
21
|
-
return postConsole({ commandName: "screenshot", screenshotData: { fileName, base64 } });
|
|
22
|
-
case "console":
|
|
23
|
-
console.log(exports.SCREENSHOT_NOTIFICATION_MESSAGE, fileName, base64);
|
|
24
|
-
return Promise.resolve();
|
|
25
|
-
}
|
|
3
|
+
const command_1 = require("./command");
|
|
4
|
+
try {
|
|
5
|
+
(0, command_1.setPropsToCustomWindow)("console", "");
|
|
26
6
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
case "post":
|
|
30
|
-
return postConsole({ commandName: "finish" });
|
|
31
|
-
case "console":
|
|
32
|
-
console.log(exports.END_NOTIFICATION_MESSAGE);
|
|
33
|
-
return Promise.resolve();
|
|
34
|
-
}
|
|
7
|
+
catch (e) {
|
|
8
|
+
// window がない環境で必ずエラーになるので無視する
|
|
35
9
|
}
|
|
36
10
|
if (typeof g !== "undefined") {
|
|
37
11
|
const screenshotPromises = [];
|
|
@@ -42,32 +16,35 @@ if (typeof g !== "undefined") {
|
|
|
42
16
|
switch (eventData.command.name) {
|
|
43
17
|
case "init":
|
|
44
18
|
const option = eventData.command.options;
|
|
45
|
-
|
|
46
|
-
|
|
19
|
+
try {
|
|
20
|
+
(0, command_1.setPropsToCustomWindow)(option.outputType, option.outputUrl);
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
// window がない環境で必ずエラーになるので無視する
|
|
24
|
+
}
|
|
47
25
|
break;
|
|
48
26
|
case "screenshot":
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
screenshotPromises.push(screenshot(eventData.command.options.fileName, data[1]));
|
|
56
|
-
}
|
|
27
|
+
try {
|
|
28
|
+
const url = (0, command_1.getImageDataUrlFromCanvas)();
|
|
29
|
+
screenshotPromises.push((0, command_1.screenshot)(eventData.command.options.fileName, url));
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
// window がない環境で必ずエラーになるので無視する
|
|
57
33
|
}
|
|
58
34
|
break;
|
|
59
35
|
case "finish":
|
|
60
36
|
// スクリーンショット送信よりも finish() の通知が先に完了してしまうと、実行が中断されてスクリーンショットが取れない場合がある。それを避けるために完了を待ってから finish() する
|
|
61
|
-
Promise.all(screenshotPromises).then(() => finish());
|
|
37
|
+
Promise.all(screenshotPromises).then(() => (0, command_1.finish)());
|
|
62
38
|
break;
|
|
63
39
|
default:
|
|
64
40
|
throw new Error(`${eventData.command.name} is undefined.`);
|
|
65
41
|
}
|
|
66
42
|
}
|
|
67
43
|
};
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
44
|
+
const handlerName = "reftest-helper";
|
|
45
|
+
g.game._sceneChanged.add((scene) => {
|
|
46
|
+
if (!scene.message.contains({ name: handlerName })) {
|
|
47
|
+
scene.message.add({ func: handleScenario, name: handlerName });
|
|
71
48
|
}
|
|
72
49
|
});
|
|
73
50
|
}
|
package/lib/types/index.d.ts
CHANGED
package/lib/types/index.js
CHANGED
|
@@ -19,3 +19,4 @@ __exportStar(require("./ConsoleApiParameter"), exports);
|
|
|
19
19
|
__exportStar(require("./InitCommandOption"), exports);
|
|
20
20
|
__exportStar(require("./OutputType"), exports);
|
|
21
21
|
__exportStar(require("./ScreenshotData"), exports);
|
|
22
|
+
__exportStar(require("./CustomWindow"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akashic/engine-files-reftest-helper",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.3.0-beta.0",
|
|
4
4
|
"description": "engine-files-reftestでコンテンツを自動実行するためのライブラリ",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"author": "DWANGO Co., Ltd.",
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@akashic/akashic-engine": "~
|
|
17
|
+
"@akashic/akashic-engine": "~2.6.7",
|
|
18
18
|
"@akashic/remark-preset-lint": "^0.1.2",
|
|
19
19
|
"remark-cli": "^12.0.0",
|
|
20
20
|
"tslint": "^5.20.1",
|
|
@@ -25,13 +25,12 @@
|
|
|
25
25
|
"package.json",
|
|
26
26
|
"README.md"
|
|
27
27
|
],
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"@akashic:registry": "https://registry.npmjs.org/",
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
28
32
|
"repository": {
|
|
29
33
|
"type": "git",
|
|
30
34
|
"url": "akashic-games/engine-files-reftest-helper.git"
|
|
31
|
-
},
|
|
32
|
-
"publishConfig": {
|
|
33
|
-
"@akashic:registry": "https://registry.npmjs.org/",
|
|
34
|
-
"access": "public",
|
|
35
|
-
"tag": "for_ae1x"
|
|
36
35
|
}
|
|
37
36
|
}
|