@akashic/engine-files-reftest-helper 1.2.3 → 1.3.0-beta.1
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/README.md +9 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.js +52 -15
- 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 +1 -1
package/README.md
CHANGED
|
@@ -54,6 +54,15 @@ npm test
|
|
|
54
54
|
|
|
55
55
|
TODO: `globalThis.fetch`が無い環境でも動作できるようにする
|
|
56
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
|
+
|
|
57
66
|
## ライセンス
|
|
58
67
|
本リポジトリは MIT License の元で公開されています。
|
|
59
68
|
詳しくは [LICENSE](https://github.com/akashic-games/engine-files-reftest-helper/blob/main/LICENSE) をご覧ください。
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
import type { CustomWindow, ConsoleApiParameter, OutputType } from "./types";
|
|
1
2
|
/** engine-files-reftest側にスクリーンショットの保存を要求するためのメッセージ */
|
|
2
3
|
export declare const SCREENSHOT_NOTIFICATION_MESSAGE = "engine-files-reftest:image";
|
|
3
4
|
/** engine-files-reftest側にコンテンツ実行終了を要求するためのメッセージ */
|
|
4
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/index.js
CHANGED
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.END_NOTIFICATION_MESSAGE = exports.SCREENSHOT_NOTIFICATION_MESSAGE = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
exports.postConsole = postConsole;
|
|
5
|
+
exports.screenshot = screenshot;
|
|
6
|
+
exports.finish = finish;
|
|
7
|
+
exports.getImageDataUrlFromCanvas = getImageDataUrlFromCanvas;
|
|
8
|
+
exports.getCustomWindow = getCustomWindow;
|
|
9
|
+
exports.setPropsToCustomWindow = setPropsToCustomWindow;
|
|
6
10
|
// TODO 以下2つの定数は大規模化したら別リポジトリに切り出す
|
|
7
11
|
/** engine-files-reftest側にスクリーンショットの保存を要求するためのメッセージ */
|
|
8
12
|
exports.SCREENSHOT_NOTIFICATION_MESSAGE = "engine-files-reftest:image";
|
|
9
13
|
/** engine-files-reftest側にコンテンツ実行終了を要求するためのメッセージ */
|
|
10
14
|
exports.END_NOTIFICATION_MESSAGE = "engine-files-reftest:finish";
|
|
11
15
|
function postConsole(param) {
|
|
16
|
+
const windowAsCustom = getCustomWindow();
|
|
12
17
|
const headers = {
|
|
13
18
|
"Accept": "application/json",
|
|
14
19
|
"Content-Type": "application/json; charset=utf-8"
|
|
15
20
|
};
|
|
16
|
-
return fetch(consoleApiUrl, { method: "POST", headers, body: JSON.stringify(param) });
|
|
21
|
+
return fetch(windowAsCustom.consoleApiUrl, { method: "POST", headers, body: JSON.stringify(param) });
|
|
17
22
|
}
|
|
18
23
|
function screenshot(fileName, base64) {
|
|
19
|
-
|
|
24
|
+
const windowAsCustom = getCustomWindow();
|
|
25
|
+
switch (windowAsCustom.outputType) {
|
|
20
26
|
case "post":
|
|
21
27
|
return postConsole({ commandName: "screenshot", screenshotData: { fileName, base64 } });
|
|
22
28
|
case "console":
|
|
@@ -25,7 +31,8 @@ function screenshot(fileName, base64) {
|
|
|
25
31
|
}
|
|
26
32
|
}
|
|
27
33
|
function finish() {
|
|
28
|
-
|
|
34
|
+
const windowAsCustom = getCustomWindow();
|
|
35
|
+
switch (windowAsCustom.outputType) {
|
|
29
36
|
case "post":
|
|
30
37
|
return postConsole({ commandName: "finish" });
|
|
31
38
|
case "console":
|
|
@@ -33,6 +40,34 @@ function finish() {
|
|
|
33
40
|
return Promise.resolve();
|
|
34
41
|
}
|
|
35
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
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
setPropsToCustomWindow("console", "");
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
// window がない環境で必ずエラーになるので無視する
|
|
70
|
+
}
|
|
36
71
|
if (typeof g !== "undefined") {
|
|
37
72
|
const screenshotPromises = [];
|
|
38
73
|
const handleScenario = (msg) => {
|
|
@@ -42,18 +77,20 @@ if (typeof g !== "undefined") {
|
|
|
42
77
|
switch (eventData.command.name) {
|
|
43
78
|
case "init":
|
|
44
79
|
const option = eventData.command.options;
|
|
45
|
-
|
|
46
|
-
|
|
80
|
+
try {
|
|
81
|
+
setPropsToCustomWindow(option.outputType, option.outputUrl);
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
// window がない環境で必ずエラーになるので無視する
|
|
85
|
+
}
|
|
47
86
|
break;
|
|
48
87
|
case "screenshot":
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
screenshotPromises.push(screenshot(eventData.command.options.fileName, data[1]));
|
|
56
|
-
}
|
|
88
|
+
try {
|
|
89
|
+
const url = getImageDataUrlFromCanvas();
|
|
90
|
+
screenshotPromises.push(screenshot(eventData.command.options.fileName, url));
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
93
|
+
// window がない環境で必ずエラーになるので無視する
|
|
57
94
|
}
|
|
58
95
|
break;
|
|
59
96
|
case "finish":
|
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);
|