@akashic/engine-files-reftest-helper 0.1.4

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 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,53 @@
1
+ # engine-files-reftest-helper
2
+
3
+ <p align="center">
4
+ <img src="https://github.com/akashic-games/engine-files-reftest-helper/blob/ae1x-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でエンコードした文字列をconsole上に出力します。
11
+ * engine-files-reftest側で、その文字列をデコードして `msg.data.command.options.fileName` で指定されたファイル名でその画像を保存します。
12
+ * `msg.data.command.name` が `finish` の時、engine-files-reftest側にスクリーンショット取得処理の要求を意味する文字列をconsole上に出力します。
13
+
14
+ ## 使い方
15
+ engine-files-reftestのテスト対象コンテンツのディレクトリで以下のコマンドを実行します。
16
+
17
+ ```sh
18
+ akashic install @akashic/engine-files-reftest-helper@0
19
+ ```
20
+
21
+ そのコンテンツのエントリーポイントで以下のコードを追記します
22
+
23
+ ```javascript
24
+ require("@akashic/engine-files-reftest-helper");
25
+ ```
26
+
27
+ ## ビルド方法
28
+
29
+ **engine-files-reftest-helper** はTypeScriptで書かれたjsモジュールであるため、ビルドにはNode.jsが必要です。
30
+
31
+ `npm run build` によりビルドできます。
32
+
33
+ ```sh
34
+ npm install
35
+ npm run build
36
+ ```
37
+
38
+ ## テスト方法
39
+
40
+ 1. [TSLint](https://github.com/palantir/tslint "TSLint")を使ったTypeScriptファイルのLint
41
+ 2. [remark](https://remark.js.org/ "remark")を使ったMarkdownファイルのLint
42
+
43
+ がそれぞれ実行されます。
44
+
45
+ ```sh
46
+ npm test
47
+ ```
48
+ ## ライセンス
49
+ 本リポジトリは MIT License の元で公開されています。
50
+ 詳しくは [LICENSE](https://github.com/akashic-games/engine-files-reftest-helper/blob/ae1x-main/LICENSE) をご覧ください。
51
+
52
+ ただし、画像ファイルおよび音声ファイルは
53
+ [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,73 @@
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
+ g.game._sceneChanged.handle((scene) => {
69
+ if (!scene.message.isHandled(handleScenario)) {
70
+ scene.message.handle(handleScenario);
71
+ }
72
+ });
73
+ }
@@ -0,0 +1 @@
1
+ export type CommandName = "init" | "screenshot" | "finish";
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ import type { CommandName } from "./CommandName";
2
+ import type { ScreenshotData } from "./ScreenshotData";
3
+ export interface ConsoleApiParameter {
4
+ commandName: CommandName;
5
+ screenshotData?: ScreenshotData;
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ import type { OutputType } from "./OutputType";
2
+ export interface InitCommandOption {
3
+ outputType: OutputType;
4
+ outputUrl: string;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export type OutputType = "post" | "console";
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export interface ScreenshotData {
2
+ fileName: string;
3
+ base64: string;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ export * from "./CommandName";
2
+ export * from "./ConsoleApiParameter";
3
+ export * from "./InitCommandOption";
4
+ export * from "./OutputType";
5
+ export * from "./ScreenshotData";
@@ -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,37 @@
1
+ {
2
+ "name": "@akashic/engine-files-reftest-helper",
3
+ "version": "0.1.4",
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": "~1.14.0",
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
+ "repository": {
29
+ "type": "git",
30
+ "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
+ }
37
+ }