@akashic/engine-files-reftest-helper 1.2.3
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 +21 -0
- package/README.md +62 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +74 -0
- package/lib/types/CommandName.d.ts +1 -0
- package/lib/types/CommandName.js +2 -0
- package/lib/types/ConsoleApiParameter.d.ts +6 -0
- package/lib/types/ConsoleApiParameter.js +2 -0
- package/lib/types/InitCommandOption.d.ts +5 -0
- package/lib/types/InitCommandOption.js +2 -0
- package/lib/types/OutputType.d.ts +1 -0
- package/lib/types/OutputType.js +2 -0
- package/lib/types/ScreenshotData.d.ts +4 -0
- package/lib/types/ScreenshotData.js +2 -0
- package/lib/types/index.d.ts +5 -0
- package/lib/types/index.js +21 -0
- package/package.json +36 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 DWANGO Co., Ltd.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# engine-files-reftest-helper
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="https://github.com/akashic-games/engine-files-reftest-helper/blob/main/img/akashic.png"/>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
**engine-files-reftest-helper**は、engine-files-reftestでコンテンツを自動実行させるための補助ツールです。
|
|
8
|
+
このツールでできることは以下の通りです。
|
|
9
|
+
* playlogのうち、MessageEventを受け取って`data.type` が `scenario` の時、`msg.data.command.name` の値に応じて処理を実行します。
|
|
10
|
+
* `msg.data.command.name` が `screenshot` の時、スクリーンショットをBASE64でエンコードした文字列を指定された形式で出力します。
|
|
11
|
+
* engine-files-reftest側で、その文字列をデコードして `msg.data.command.options.fileName` で指定されたファイル名でその画像を保存します。
|
|
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を指定します。
|
|
16
|
+
|
|
17
|
+
## 使い方
|
|
18
|
+
engine-files-reftestのテスト対象コンテンツのディレクトリで以下のコマンドを実行します。
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
akashic install @akashic/engine-files-reftest-helper
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
そのコンテンツのエントリーポイントで以下のコードを追記します
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
require("@akashic/engine-files-reftest-helper");
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## ビルド方法
|
|
31
|
+
|
|
32
|
+
**engine-files-reftest-helper** はTypeScriptで書かれたjsモジュールであるため、ビルドにはNode.jsが必要です。
|
|
33
|
+
|
|
34
|
+
`npm run build` によりビルドできます。
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
npm install
|
|
38
|
+
npm run build
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## テスト方法
|
|
42
|
+
|
|
43
|
+
1. [TSLint](https://github.com/palantir/tslint "TSLint")を使ったTypeScriptファイルのLint
|
|
44
|
+
2. [remark](https://remark.js.org/ "remark")を使ったMarkdownファイルのLint
|
|
45
|
+
|
|
46
|
+
がそれぞれ実行されます。
|
|
47
|
+
|
|
48
|
+
```sh
|
|
49
|
+
npm test
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## 注意事項
|
|
53
|
+
本ライブラリはブラウザ上で使うことを想定していますが、IE11等`globalThis.fetch`が無い環境では正しく動作しませんので、`globalThis.fetch`が存在する環境で本ライブラリを使用してください。
|
|
54
|
+
|
|
55
|
+
TODO: `globalThis.fetch`が無い環境でも動作できるようにする
|
|
56
|
+
|
|
57
|
+
## ライセンス
|
|
58
|
+
本リポジトリは MIT License の元で公開されています。
|
|
59
|
+
詳しくは [LICENSE](https://github.com/akashic-games/engine-files-reftest-helper/blob/main/LICENSE) をご覧ください。
|
|
60
|
+
|
|
61
|
+
ただし、画像ファイルおよび音声ファイルは
|
|
62
|
+
[CC BY 2.1 JP](https://creativecommons.org/licenses/by/2.1/jp/) の元で公開されています。
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** engine-files-reftest側にスクリーンショットの保存を要求するためのメッセージ */
|
|
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";
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.END_NOTIFICATION_MESSAGE = exports.SCREENSHOT_NOTIFICATION_MESSAGE = void 0;
|
|
4
|
+
let outputType = "console"; // デフォルトはコンソール出力とする
|
|
5
|
+
let consoleApiUrl = "";
|
|
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
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function finish() {
|
|
28
|
+
switch (outputType) {
|
|
29
|
+
case "post":
|
|
30
|
+
return postConsole({ commandName: "finish" });
|
|
31
|
+
case "console":
|
|
32
|
+
console.log(exports.END_NOTIFICATION_MESSAGE);
|
|
33
|
+
return Promise.resolve();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (typeof g !== "undefined") {
|
|
37
|
+
const screenshotPromises = [];
|
|
38
|
+
const handleScenario = (msg) => {
|
|
39
|
+
var _a;
|
|
40
|
+
if (((_a = msg.data) === null || _a === void 0 ? void 0 : _a.type) === "scenario" && msg.data.command) {
|
|
41
|
+
const eventData = msg.data;
|
|
42
|
+
switch (eventData.command.name) {
|
|
43
|
+
case "init":
|
|
44
|
+
const option = eventData.command.options;
|
|
45
|
+
outputType = option.outputType;
|
|
46
|
+
consoleApiUrl = option.outputUrl;
|
|
47
|
+
break;
|
|
48
|
+
case "screenshot":
|
|
49
|
+
if (typeof window !== "undefined") {
|
|
50
|
+
g.game.render(); // 描画がスキップされてしまうことがあるので、スクリーンショット取得前に現フレームでの描画を行う
|
|
51
|
+
const canvasElements = window.document.getElementsByTagName("canvas");
|
|
52
|
+
const imageUrl = canvasElements[0].toDataURL("image/png");
|
|
53
|
+
const data = imageUrl.match(/^data:image\/png;base64,(.+)$/);
|
|
54
|
+
if (data.length === 2) {
|
|
55
|
+
screenshotPromises.push(screenshot(eventData.command.options.fileName, data[1]));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
break;
|
|
59
|
+
case "finish":
|
|
60
|
+
// スクリーンショット送信よりも finish() の通知が先に完了してしまうと、実行が中断されてスクリーンショットが取れない場合がある。それを避けるために完了を待ってから finish() する
|
|
61
|
+
Promise.all(screenshotPromises).then(() => finish());
|
|
62
|
+
break;
|
|
63
|
+
default:
|
|
64
|
+
throw new Error(`${eventData.command.name} is undefined.`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const handlerName = "reftest-helper";
|
|
69
|
+
g.game._sceneChanged.add((scene) => {
|
|
70
|
+
if (!scene.message.contains({ name: handlerName })) {
|
|
71
|
+
scene.message.add({ func: handleScenario, name: handlerName });
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type CommandName = "init" | "screenshot" | "finish";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type OutputType = "post" | "console";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./CommandName"), exports);
|
|
18
|
+
__exportStar(require("./ConsoleApiParameter"), exports);
|
|
19
|
+
__exportStar(require("./InitCommandOption"), exports);
|
|
20
|
+
__exportStar(require("./OutputType"), exports);
|
|
21
|
+
__exportStar(require("./ScreenshotData"), exports);
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@akashic/engine-files-reftest-helper",
|
|
3
|
+
"version": "1.2.3",
|
|
4
|
+
"description": "engine-files-reftestでコンテンツを自動実行するためのライブラリ",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"typings": "lib/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"prepublish": "npm run build",
|
|
9
|
+
"build": "tsc -p .",
|
|
10
|
+
"test": "npm run lint:ts && npm run lint:md",
|
|
11
|
+
"lint:ts": "tslint -c tslint.json src/**/*.ts --project ./tsconfig.json",
|
|
12
|
+
"lint:md": "remark ./*.md --frail --no-stdout --quiet --rc-path ./.remarkrc"
|
|
13
|
+
},
|
|
14
|
+
"author": "DWANGO Co., Ltd.",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@akashic/akashic-engine": "~2.6.7",
|
|
18
|
+
"@akashic/remark-preset-lint": "^0.1.2",
|
|
19
|
+
"remark-cli": "^12.0.0",
|
|
20
|
+
"tslint": "^5.20.1",
|
|
21
|
+
"typescript": "^5.3.3"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"lib",
|
|
25
|
+
"package.json",
|
|
26
|
+
"README.md"
|
|
27
|
+
],
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"@akashic:registry": "https://registry.npmjs.org/",
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "akashic-games/engine-files-reftest-helper.git"
|
|
35
|
+
}
|
|
36
|
+
}
|