From 1d48319c757a3ca2cfbffe489e0cc9e93d51b088 Mon Sep 17 00:00:00 2001 From: Hiroshiba Kazuyuki Date: Tue, 21 Jan 2025 19:48:45 +0900 Subject: [PATCH 1/9] =?UTF-8?q?refactor!:=20extractVvpp=E5=91=A8=E3=82=8A?= =?UTF-8?q?=E3=81=AETODO=E3=82=92=E8=A7=A3=E6=B1=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/electron/helper.ts | 6 ++++ src/backend/electron/manager/vvppManager.ts | 3 +- src/backend/electron/vvppFile.ts | 36 +++++++++---------- .../backend/electron/vvppFile.node.spec.ts | 21 +++++++---- 4 files changed, 39 insertions(+), 27 deletions(-) create mode 100644 src/backend/electron/helper.ts diff --git a/src/backend/electron/helper.ts b/src/backend/electron/helper.ts new file mode 100644 index 0000000000..f5176b4643 --- /dev/null +++ b/src/backend/electron/helper.ts @@ -0,0 +1,6 @@ +import path from "node:path"; +import { app } from "electron"; + +export function getElectronSevenZipPath(sevenZipPath: string): string { + return path.join(path.dirname(app.getPath("exe")), sevenZipPath); +} diff --git a/src/backend/electron/manager/vvppManager.ts b/src/backend/electron/manager/vvppManager.ts index bb76c9ceeb..9489514998 100644 --- a/src/backend/electron/manager/vvppManager.ts +++ b/src/backend/electron/manager/vvppManager.ts @@ -114,8 +114,7 @@ export class VvppManager { callbacks?: { onProgress?: ProgressCallback }, ) { const { outputDir, manifest } = await extractVvpp( - vvppPath, - this.vvppEngineDir, + { vvppLikeFilePath: vvppPath, vvppEngineDir: this.vvppEngineDir }, callbacks, ); diff --git a/src/backend/electron/vvppFile.ts b/src/backend/electron/vvppFile.ts index d4d3568adc..c8b7790bba 100644 --- a/src/backend/electron/vvppFile.ts +++ b/src/backend/electron/vvppFile.ts @@ -7,7 +7,7 @@ import path from "node:path"; import { spawn } from "node:child_process"; import MultiStream from "multistream"; import { glob } from "glob"; -import { app } from "electron"; +import { getElectronSevenZipPath } from "./helper"; import { minimumEngineManifestSchema, MinimumEngineManifestType, @@ -61,21 +61,14 @@ async function getArchiveFileParts( /** 分割されているVVPPファイルを連結して返す */ async function concatenateVvppFiles( - format: "zip" | "7z", archiveFileParts: string[], + outputFile: string, ) { - // -siオプションでの7z解凍はサポートされていないため、 - // ファイルを連結した一次ファイルを作成し、それを7zで解凍する。 log.info(`Concatenating ${archiveFileParts.length} files...`); - const tmpConcatenatedFile = path.join( - app.getPath("temp"), // TODO: archiveFilePartsと同じディレクトリにしてappの依存をなくす - `vvpp-${new Date().getTime()}.${format}`, - ); - log.info("Temporary file:", tmpConcatenatedFile); + await new Promise((resolve, reject) => { - if (!tmpConcatenatedFile) throw new Error("tmpFile is undefined"); const inputStreams = archiveFileParts.map((f) => fs.createReadStream(f)); - const outputStream = fs.createWriteStream(tmpConcatenatedFile); + const outputStream = fs.createWriteStream(outputFile); new MultiStream(inputStreams) .pipe(outputStream) .on("close", () => { @@ -85,7 +78,6 @@ async function concatenateVvppFiles( .on("error", reject); }); log.info("Concatenated"); - return tmpConcatenatedFile; } /** 7zでファイルを解凍する */ @@ -112,7 +104,7 @@ async function unarchive( throw new Error("7z path is not defined"); } if (import.meta.env.PROD) { - sevenZipPath = path.join(path.dirname(app.getPath("exe")), sevenZipPath); // TODO: helperに移動してappの依存をなくす + sevenZipPath = getElectronSevenZipPath(sevenZipPath); } log.info("Spawning 7z:", sevenZipPath, args.join(" ")); await new Promise((resolve, reject) => { @@ -155,10 +147,10 @@ async function unarchive( } export async function extractVvpp( - vvppLikeFilePath: string, - vvppEngineDir: string, // TODO: payload objectに変える + payload: { vvppLikeFilePath: string; vvppEngineDir: string }, callbacks?: { onProgress?: ProgressCallback }, ): Promise<{ outputDir: string; manifest: MinimumEngineManifestType }> { + const { vvppLikeFilePath, vvppEngineDir } = payload; callbacks?.onProgress?.({ progress: 0 }); const nonce = new Date().getTime().toString(); @@ -177,10 +169,12 @@ export async function extractVvpp( let archiveFile: string; try { if (archiveFileParts.length > 1) { - tmpConcatenatedFile = await concatenateVvppFiles( - format, - archiveFileParts, - ); + // -siオプションでの7z解凍はサポートされていないため、 + // ファイルを連結した一次ファイルを作成し、それを7zで解凍する。 + tmpConcatenatedFile = createTempConcatenatedFilePath(); + log.info("Temporary file:", tmpConcatenatedFile); + + await concatenateVvppFiles(archiveFileParts, tmpConcatenatedFile); archiveFile = tmpConcatenatedFile; } else { archiveFile = archiveFileParts[0]; @@ -214,6 +208,10 @@ export async function extractVvpp( } throw e; } + + function createTempConcatenatedFilePath(): string { + return path.join(outputDir, `.tmp-vvpp-${new Date().getTime()}.${format}`); + } } async function detectFileFormat( diff --git a/tests/unit/backend/electron/vvppFile.node.spec.ts b/tests/unit/backend/electron/vvppFile.node.spec.ts index bc4d071c1a..4a880c1f06 100644 --- a/tests/unit/backend/electron/vvppFile.node.spec.ts +++ b/tests/unit/backend/electron/vvppFile.node.spec.ts @@ -20,7 +20,10 @@ test("正しいVVPPファイルからエンジンを切り出せる", async () = const sourceDir = path.join(__dirname, "vvpps", targetName); const outputFilePath = path.join(tmpDir, uuid4() + targetName); await createZipFile(sourceDir, outputFilePath); - await extractVvpp(outputFilePath, tmpDir); + await extractVvpp({ + vvppLikeFilePath: outputFilePath, + vvppEngineDir: tmpDir, + }); }); test.fails("分割されたVVPPファイルからエンジンを切り出せる", async () => { @@ -33,7 +36,10 @@ test.fails("分割されたVVPPファイルからエンジンを切り出せる" const outputFilePath1 = outputFilePath + ".1.vvppp"; const outputFilePath2 = outputFilePath + ".2.vvppp"; splitFile(outputFilePath, outputFilePath1, outputFilePath2); - await extractVvpp(outputFilePath1, tmpDir); + await extractVvpp({ + vvppLikeFilePath: outputFilePath1, + vvppEngineDir: tmpDir, + }); }); test.each([ @@ -46,16 +52,19 @@ test.each([ const sourceDir = path.join(__dirname, "vvpps", targetName); const outputFilePath = path.join(tmpDir, uuid4() + targetName); await createZipFile(sourceDir, outputFilePath); - await expect(extractVvpp(outputFilePath, tmpDir)).rejects.toThrow( - expectedError, - ); + await expect( + extractVvpp({ + vvppLikeFilePath: outputFilePath, + vvppEngineDir: tmpDir, + }), + ).rejects.toThrow(expectedError); }, ); /** 7zを使って指定したフォルダからzipファイルを作成する */ async function createZipFile(sourceDir: string, outputFilePath: string) { const zipBin = import.meta.env.VITE_7Z_BIN_NAME; - const command = `"${zipBin}" a -tzip "${outputFilePath}" "${sourceDir}\\*"`; + const command = `"${zipBin}" a -tzip "${outputFilePath}" "${path.join(sourceDir, "*")}"`; await promisify(exec)(command); } From 58acd6ac5e65e02a3ea2b81e5a298e97e7158bc0 Mon Sep 17 00:00:00 2001 From: Hiroshiba Kazuyuki Date: Tue, 21 Jan 2025 19:54:47 +0900 Subject: [PATCH 2/9] =?UTF-8?q?refactor:=20helper=E3=81=AF=E8=A6=81?= =?UTF-8?q?=E3=82=89=E3=81=AA=E3=81=9D=E3=81=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/electron/helper.ts | 6 ------ src/backend/electron/vvppFile.ts | 35 ++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 21 deletions(-) delete mode 100644 src/backend/electron/helper.ts diff --git a/src/backend/electron/helper.ts b/src/backend/electron/helper.ts deleted file mode 100644 index f5176b4643..0000000000 --- a/src/backend/electron/helper.ts +++ /dev/null @@ -1,6 +0,0 @@ -import path from "node:path"; -import { app } from "electron"; - -export function getElectronSevenZipPath(sevenZipPath: string): string { - return path.join(path.dirname(app.getPath("exe")), sevenZipPath); -} diff --git a/src/backend/electron/vvppFile.ts b/src/backend/electron/vvppFile.ts index c8b7790bba..aecc9e9b4c 100644 --- a/src/backend/electron/vvppFile.ts +++ b/src/backend/electron/vvppFile.ts @@ -7,7 +7,7 @@ import path from "node:path"; import { spawn } from "node:child_process"; import MultiStream from "multistream"; import { glob } from "glob"; -import { getElectronSevenZipPath } from "./helper"; +import { app } from "electron"; import { minimumEngineManifestSchema, MinimumEngineManifestType, @@ -17,13 +17,6 @@ import { createLogger } from "@/helpers/log"; const log = createLogger("vvppFile"); -// https://www.garykessler.net/library/file_sigs.html#:~:text=7-zip%20compressed%20file -const SEVEN_ZIP_MAGIC_NUMBER = Buffer.from([ - 0x37, 0x7a, 0xbc, 0xaf, 0x27, 0x1c, -]); - -const ZIP_MAGIC_NUMBER = Buffer.from([0x50, 0x4b, 0x03, 0x04]); - /** VVPPファイルが分割されている場合、それらのファイルを取得する */ async function getArchiveFileParts( vvppLikeFilePath: string, @@ -99,13 +92,7 @@ async function unarchive( "-bsp1", // 進捗出力 ]; - let sevenZipPath = import.meta.env.VITE_7Z_BIN_NAME; - if (!sevenZipPath) { - throw new Error("7z path is not defined"); - } - if (import.meta.env.PROD) { - sevenZipPath = getElectronSevenZipPath(sevenZipPath); - } + const sevenZipPath = getSevenZipPath(); log.info("Spawning 7z:", sevenZipPath, args.join(" ")); await new Promise((resolve, reject) => { const child = spawn(sevenZipPath, args, { @@ -144,6 +131,17 @@ async function unarchive( // FIXME: rejectが2回呼ばれることがある child.on("error", reject); }); + + function getSevenZipPath() { + let sevenZipPath = import.meta.env.VITE_7Z_BIN_NAME; + if (!sevenZipPath) { + throw new Error("7z path is not defined"); + } + if (import.meta.env.PROD) { + sevenZipPath = path.join(path.dirname(app.getPath("exe")), sevenZipPath); + } + return sevenZipPath; + } } export async function extractVvpp( @@ -223,6 +221,13 @@ async function detectFileFormat( await file.read(buffer, 0, 8, 0); await file.close(); + // https://www.garykessler.net/library/file_sigs.html#:~:text=7-zip%20compressed%20file + const SEVEN_ZIP_MAGIC_NUMBER = Buffer.from([ + 0x37, 0x7a, 0xbc, 0xaf, 0x27, 0x1c, + ]); + + const ZIP_MAGIC_NUMBER = Buffer.from([0x50, 0x4b, 0x03, 0x04]); + if (buffer.compare(SEVEN_ZIP_MAGIC_NUMBER, 0, 6, 0, 6) === 0) { return "7z"; } else if (buffer.compare(ZIP_MAGIC_NUMBER, 0, 4, 0, 4) === 0) { From 76225fad6a80e6fe70d96791c284b59ff54ded1b Mon Sep 17 00:00:00 2001 From: Hiroshiba Kazuyuki Date: Tue, 21 Jan 2025 20:08:43 +0900 Subject: [PATCH 3/9] =?UTF-8?q?fix:=20=E3=82=84=E3=81=A3=E3=81=B1=E3=82=8A?= =?UTF-8?q?vvppp=E3=81=8C=E3=81=82=E3=82=8B=E3=81=A8=E3=81=93=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/electron/vvppFile.ts | 5 ++++- tests/unit/backend/electron/vvppFile.node.spec.ts | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/backend/electron/vvppFile.ts b/src/backend/electron/vvppFile.ts index aecc9e9b4c..119c4a81aa 100644 --- a/src/backend/electron/vvppFile.ts +++ b/src/backend/electron/vvppFile.ts @@ -208,7 +208,10 @@ export async function extractVvpp( } function createTempConcatenatedFilePath(): string { - return path.join(outputDir, `.tmp-vvpp-${new Date().getTime()}.${format}`); + return path.join( + path.dirname(vvppLikeFilePath), + `.tmp-vvpp-${new Date().getTime()}.${format}`, + ); } } diff --git a/tests/unit/backend/electron/vvppFile.node.spec.ts b/tests/unit/backend/electron/vvppFile.node.spec.ts index 4a880c1f06..578e3b33a0 100644 --- a/tests/unit/backend/electron/vvppFile.node.spec.ts +++ b/tests/unit/backend/electron/vvppFile.node.spec.ts @@ -26,8 +26,7 @@ test("正しいVVPPファイルからエンジンを切り出せる", async () = }); }); -test.fails("分割されたVVPPファイルからエンジンを切り出せる", async () => { - // TODO: electronのappに依存しているのでテストが通らない。依存がなくなり次第.failsを失くす +test("分割されたVVPPファイルからエンジンを切り出せる", async () => { const targetName = "perfect.vvpp"; const sourceDir = path.join(__dirname, "vvpps", targetName); const outputFilePath = path.join(tmpDir, uuid4() + targetName); From 35a0511c67909caa1216e734a0561e19b8481eea Mon Sep 17 00:00:00 2001 From: Hiroshiba Kazuyuki Date: Tue, 21 Jan 2025 20:12:07 +0900 Subject: [PATCH 4/9] =?UTF-8?q?=E3=82=84=E3=81=A3=E3=81=B1=E3=82=8AtmpDir?= =?UTF-8?q?=E3=82=92=E6=B8=A1=E3=81=99=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/electron/manager/vvppManager.ts | 8 ++++++-- src/backend/electron/vvppFile.ts | 9 +++------ tests/unit/backend/electron/vvppFile.node.spec.ts | 3 +++ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/backend/electron/manager/vvppManager.ts b/src/backend/electron/manager/vvppManager.ts index 9489514998..0f8d3fa008 100644 --- a/src/backend/electron/manager/vvppManager.ts +++ b/src/backend/electron/manager/vvppManager.ts @@ -1,7 +1,7 @@ import fs from "node:fs"; import path from "node:path"; import { moveFile } from "move-file"; -import { dialog } from "electron"; +import { app, dialog } from "electron"; import AsyncLock from "async-lock"; import { EngineId, @@ -114,7 +114,11 @@ export class VvppManager { callbacks?: { onProgress?: ProgressCallback }, ) { const { outputDir, manifest } = await extractVvpp( - { vvppLikeFilePath: vvppPath, vvppEngineDir: this.vvppEngineDir }, + { + vvppLikeFilePath: vvppPath, + vvppEngineDir: this.vvppEngineDir, + tmpDir: app.getPath("temp"), + }, callbacks, ); diff --git a/src/backend/electron/vvppFile.ts b/src/backend/electron/vvppFile.ts index 119c4a81aa..39d6bf98e9 100644 --- a/src/backend/electron/vvppFile.ts +++ b/src/backend/electron/vvppFile.ts @@ -145,10 +145,10 @@ async function unarchive( } export async function extractVvpp( - payload: { vvppLikeFilePath: string; vvppEngineDir: string }, + payload: { vvppLikeFilePath: string; vvppEngineDir: string; tmpDir: string }, callbacks?: { onProgress?: ProgressCallback }, ): Promise<{ outputDir: string; manifest: MinimumEngineManifestType }> { - const { vvppLikeFilePath, vvppEngineDir } = payload; + const { vvppLikeFilePath, vvppEngineDir, tmpDir } = payload; callbacks?.onProgress?.({ progress: 0 }); const nonce = new Date().getTime().toString(); @@ -208,10 +208,7 @@ export async function extractVvpp( } function createTempConcatenatedFilePath(): string { - return path.join( - path.dirname(vvppLikeFilePath), - `.tmp-vvpp-${new Date().getTime()}.${format}`, - ); + return path.join(tmpDir, `.tmp-vvpp-${new Date().getTime()}.${format}`); } } diff --git a/tests/unit/backend/electron/vvppFile.node.spec.ts b/tests/unit/backend/electron/vvppFile.node.spec.ts index 578e3b33a0..ad5ca4aef5 100644 --- a/tests/unit/backend/electron/vvppFile.node.spec.ts +++ b/tests/unit/backend/electron/vvppFile.node.spec.ts @@ -23,6 +23,7 @@ test("正しいVVPPファイルからエンジンを切り出せる", async () = await extractVvpp({ vvppLikeFilePath: outputFilePath, vvppEngineDir: tmpDir, + tmpDir, }); }); @@ -38,6 +39,7 @@ test("分割されたVVPPファイルからエンジンを切り出せる", asyn await extractVvpp({ vvppLikeFilePath: outputFilePath1, vvppEngineDir: tmpDir, + tmpDir, }); }); @@ -55,6 +57,7 @@ test.each([ extractVvpp({ vvppLikeFilePath: outputFilePath, vvppEngineDir: tmpDir, + tmpDir, }), ).rejects.toThrow(expectedError); }, From 194c6fb954fc83d1b82bce154a4c7c355a24a350 Mon Sep 17 00:00:00 2001 From: Hiroshiba Kazuyuki Date: Tue, 21 Jan 2025 20:18:36 +0900 Subject: [PATCH 5/9] =?UTF-8?q?chore:=20=E6=88=BB=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/electron/vvppFile.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/electron/vvppFile.ts b/src/backend/electron/vvppFile.ts index 39d6bf98e9..d49973b37f 100644 --- a/src/backend/electron/vvppFile.ts +++ b/src/backend/electron/vvppFile.ts @@ -208,7 +208,7 @@ export async function extractVvpp( } function createTempConcatenatedFilePath(): string { - return path.join(tmpDir, `.tmp-vvpp-${new Date().getTime()}.${format}`); + return path.join(tmpDir, `vvpp-${new Date().getTime()}.${format}`); } } From 2d8dd226d9a6c20945e6a4e2aaaa2740c840e425 Mon Sep 17 00:00:00 2001 From: Hiroshiba Kazuyuki Date: Tue, 21 Jan 2025 20:21:32 +0900 Subject: [PATCH 6/9] chore: temp -> tmp --- src/backend/electron/vvppFile.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/electron/vvppFile.ts b/src/backend/electron/vvppFile.ts index d49973b37f..8f0e7029ee 100644 --- a/src/backend/electron/vvppFile.ts +++ b/src/backend/electron/vvppFile.ts @@ -169,7 +169,7 @@ export async function extractVvpp( if (archiveFileParts.length > 1) { // -siオプションでの7z解凍はサポートされていないため、 // ファイルを連結した一次ファイルを作成し、それを7zで解凍する。 - tmpConcatenatedFile = createTempConcatenatedFilePath(); + tmpConcatenatedFile = createTmpConcatenatedFilePath(); log.info("Temporary file:", tmpConcatenatedFile); await concatenateVvppFiles(archiveFileParts, tmpConcatenatedFile); @@ -207,7 +207,7 @@ export async function extractVvpp( throw e; } - function createTempConcatenatedFilePath(): string { + function createTmpConcatenatedFilePath(): string { return path.join(tmpDir, `vvpp-${new Date().getTime()}.${format}`); } } From 30ed3b708e6f1159255a80e9708656579c57fbd5 Mon Sep 17 00:00:00 2001 From: Hiroshiba Kazuyuki Date: Tue, 21 Jan 2025 20:24:48 +0900 Subject: [PATCH 7/9] =?UTF-8?q?fix:=20=E5=87=BA=E5=8A=9B=E3=83=95=E3=82=A1?= =?UTF-8?q?=E3=82=A4=E3=83=AB=E3=81=AE=E3=83=91=E3=82=B9=E3=82=92outputFil?= =?UTF-8?q?ePath=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/electron/vvppFile.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/electron/vvppFile.ts b/src/backend/electron/vvppFile.ts index 8f0e7029ee..94a1898488 100644 --- a/src/backend/electron/vvppFile.ts +++ b/src/backend/electron/vvppFile.ts @@ -55,13 +55,13 @@ async function getArchiveFileParts( /** 分割されているVVPPファイルを連結して返す */ async function concatenateVvppFiles( archiveFileParts: string[], - outputFile: string, + outputFilePath: string, ) { log.info(`Concatenating ${archiveFileParts.length} files...`); await new Promise((resolve, reject) => { const inputStreams = archiveFileParts.map((f) => fs.createReadStream(f)); - const outputStream = fs.createWriteStream(outputFile); + const outputStream = fs.createWriteStream(outputFilePath); new MultiStream(inputStreams) .pipe(outputStream) .on("close", () => { From d573603fc11df9c002c370798796060eeb6f80aa Mon Sep 17 00:00:00 2001 From: Hiroshiba Date: Wed, 22 Jan 2025 00:46:34 +0900 Subject: [PATCH 8/9] =?UTF-8?q?refactor:=20createZipFile=E9=96=A2=E6=95=B0?= =?UTF-8?q?=E5=86=85=E3=81=AE=E5=A4=89=E6=95=B0=E5=90=8D=E3=82=92sevenZipB?= =?UTF-8?q?in=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/unit/backend/electron/vvppFile.node.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/backend/electron/vvppFile.node.spec.ts b/tests/unit/backend/electron/vvppFile.node.spec.ts index ad5ca4aef5..ed7d0284e8 100644 --- a/tests/unit/backend/electron/vvppFile.node.spec.ts +++ b/tests/unit/backend/electron/vvppFile.node.spec.ts @@ -65,8 +65,8 @@ test.each([ /** 7zを使って指定したフォルダからzipファイルを作成する */ async function createZipFile(sourceDir: string, outputFilePath: string) { - const zipBin = import.meta.env.VITE_7Z_BIN_NAME; - const command = `"${zipBin}" a -tzip "${outputFilePath}" "${path.join(sourceDir, "*")}"`; + const sevenZipBin = import.meta.env.VITE_7Z_BIN_NAME; + const command = `"${sevenZipBin}" a -tzip "${outputFilePath}" "${path.join(sourceDir, "*")}"`; await promisify(exec)(command); } From 9ee5f334a0b5dbf74c339a434acba879dcc1b57e Mon Sep 17 00:00:00 2001 From: Hiroshiba Date: Wed, 22 Jan 2025 01:08:13 +0900 Subject: [PATCH 9/9] =?UTF-8?q?test:=20=E3=83=9E=E3=83=8B=E3=83=95?= =?UTF-8?q?=E3=82=A7=E3=82=B9=E3=83=88=E5=AD=98=E5=9C=A8=E7=A2=BA=E8=AA=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/electron/vvppFile.node.spec.ts | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/tests/unit/backend/electron/vvppFile.node.spec.ts b/tests/unit/backend/electron/vvppFile.node.spec.ts index ed7d0284e8..3dd04933f2 100644 --- a/tests/unit/backend/electron/vvppFile.node.spec.ts +++ b/tests/unit/backend/electron/vvppFile.node.spec.ts @@ -20,11 +20,14 @@ test("正しいVVPPファイルからエンジンを切り出せる", async () = const sourceDir = path.join(__dirname, "vvpps", targetName); const outputFilePath = path.join(tmpDir, uuid4() + targetName); await createZipFile(sourceDir, outputFilePath); + + const vvppEngineDir = createVvppEngineDir(); await extractVvpp({ vvppLikeFilePath: outputFilePath, - vvppEngineDir: tmpDir, + vvppEngineDir, tmpDir, }); + expectManifestExists(vvppEngineDir); }); test("分割されたVVPPファイルからエンジンを切り出せる", async () => { @@ -36,11 +39,14 @@ test("分割されたVVPPファイルからエンジンを切り出せる", asyn const outputFilePath1 = outputFilePath + ".1.vvppp"; const outputFilePath2 = outputFilePath + ".2.vvppp"; splitFile(outputFilePath, outputFilePath1, outputFilePath2); + + const vvppEngineDir = createVvppEngineDir(); await extractVvpp({ vvppLikeFilePath: outputFilePath1, - vvppEngineDir: tmpDir, + vvppEngineDir, tmpDir, }); + expectManifestExists(vvppEngineDir); }); test.each([ @@ -70,6 +76,21 @@ async function createZipFile(sourceDir: string, outputFilePath: string) { await promisify(exec)(command); } +function createVvppEngineDir() { + const dir = path.join(tmpDir, uuid4()); + fs.mkdirSync(dir); + return dir; +} + +function expectManifestExists(vvppEngineDir: string) { + const files = fs.readdirSync(vvppEngineDir, { recursive: true }); + const manifestExists = files.some( + (file) => + typeof file === "string" && path.basename(file) == "engine_manifest.json", + ); + expect(manifestExists).toBe(true); +} + /** ファイルを2つに分割する */ function splitFile( inputFilePath: string,