From d9ca76872750b97a1dcabbef800e0dc382151c9e Mon Sep 17 00:00:00 2001 From: Jerem Date: Mon, 7 Oct 2024 21:22:27 +0200 Subject: [PATCH] fix: fix tests --- generate/rss_parser_test.ts | 3 ++- gui/gui.ts | 2 +- serialize/converter.ts | 24 +++++++++++++----------- serialize/converter_test.ts | 12 ++++++------ test_data/test_data.ts | 6 ++++++ 5 files changed, 28 insertions(+), 19 deletions(-) diff --git a/generate/rss_parser_test.ts b/generate/rss_parser_test.ts index d7ff84e..eb1b240 100644 --- a/generate/rss_parser_test.ts +++ b/generate/rss_parser_test.ts @@ -1,3 +1,4 @@ +import type { ModOptions } from "../types.ts"; import { fixUrl, getItemFileName } from "./rss_parser.ts"; import { assert, assertEquals } from "@std/assert"; @@ -7,7 +8,7 @@ Deno.test("getItemFileName", () => { pubDate: "0", title: 'a\\z/e:r*t?y"uo|p', enclosure: { "@url": "" }, - }).endsWith(" - a z e r t y u i o p."), + }, {} as ModOptions).endsWith(" - a z e r t y u i o p."), ); }); diff --git a/gui/gui.ts b/gui/gui.ts index b206607..2e46438 100755 --- a/gui/gui.ts +++ b/gui/gui.ts @@ -43,7 +43,7 @@ export function openGui(opt: ModOptions) { async function getPack(opt: ModOptions) { const folder = await fsToFolder(opt.storyPath, false); const metadata: Metadata = await getMetadata(opt.storyPath, opt); - return folderToPack(folder, metadata); + return await folderToPack(folder, metadata); } async function runSpg(opt: ModOptions) { diff --git a/serialize/converter.ts b/serialize/converter.ts index 3614ced..8852a48 100644 --- a/serialize/converter.ts +++ b/serialize/converter.ts @@ -145,16 +145,18 @@ export async function fileToStoryItem( const audio = getFileAudioItem(file, parent); const image = getFileImageItem(file, parent); let name = cleanStageName(file.name); - const metadataPath = join( - parent.path!, - getNameWithoutExt(file.name) + "-metadata.json", - ); - if (await exists(metadataPath)) { - try { - const metadata = JSON.parse(await Deno.readTextFile(metadataPath)); - name = metadata?.title ?? name; - } catch (error) { - console.error(`error reading json metadata: ${metadataPath}`, error); + if (parent.path) { + const metadataPath = join( + parent.path!, + getNameWithoutExt(file.name) + "-metadata.json", + ); + if (await exists(metadataPath)) { + try { + const metadata = JSON.parse(await Deno.readTextFile(metadataPath)); + name = metadata?.title ?? name; + } catch (error) { + console.error(`error reading json metadata: ${metadataPath}`, error); + } } } const res: StoryItem = { @@ -175,7 +177,7 @@ export async function fileToStoryItem( { class: "StageNode-Story", audio: getFileAudioStory(file)?.assetName ?? null, - duration: (await duration(file.path!)), + duration: file.path ? (await duration(file.path)) : undefined, image: null, name, okTransition: null, diff --git a/serialize/converter_test.ts b/serialize/converter_test.ts index 9ca4a4c..8d24184 100644 --- a/serialize/converter_test.ts +++ b/serialize/converter_test.ts @@ -10,18 +10,18 @@ import { } from "../test_data/test_data.ts"; import { getExtension } from "../utils/utils.ts"; -Deno.test("folderToPack-min", () => { - const pack = folderToPack(minFs); +Deno.test("folderToPack-min", async () => { + const pack = await folderToPack(minFs); assertEquals(pack, expectedMinPack); }); -Deno.test("folderToPack-moy", () => { - const pack = folderToPack(moyFs); +Deno.test("folderToPack-moy", async () => { + const pack = await folderToPack(moyFs); assertEquals(pack, expectedMoyPack); }); -Deno.test("folderToPack-full", () => { - const pack = folderToPack(fullFs); +Deno.test("folderToPack-full", async () => { + const pack = await folderToPack(fullFs); assertEquals(pack, expectedFullPack); }); diff --git a/test_data/test_data.ts b/test_data/test_data.ts index f9166c5..e5ffcbd 100644 --- a/test_data/test_data.ts +++ b/test_data/test_data.ts @@ -260,6 +260,7 @@ export const expectedMoyPack: Pack = { { class: "StageNode-Story", audio: "46fe70d98b9763ab70b7e7cea4627e4f8b7c585a.ogg", + duration: undefined, image: null, name: "city", okTransition: null, @@ -286,6 +287,7 @@ export const expectedMoyPack: Pack = { class: "StageNode-Story", name: "alice-jungle", audio: "f493d4e986a1278ca7db3f7c65bf8ee32535b2e4.ogg", + duration: undefined, image: null, okTransition: null, }, @@ -903,6 +905,7 @@ export const expectedFullPack: Pack = { class: "StageNode-Story", audio: "46fe70d98b9763ab70b7e7cea4627e4f8b7c585a.ogg", + duration: undefined, image: null, name: "city", okTransition: null, @@ -933,6 +936,7 @@ export const expectedFullPack: Pack = { class: "StageNode-Story", audio: "f493d4e986a1278ca7db3f7c65bf8ee32535b2e4.ogg", + duration: undefined, image: null, name: "alice-jungle", okTransition: null, @@ -999,6 +1003,7 @@ export const expectedFullPack: Pack = { class: "StageNode-Story", audio: "90304af3b9d81fb1590ad367df796e791ea78750.ogg", + duration: undefined, image: null, name: "bob-city", okTransition: null, @@ -1028,6 +1033,7 @@ export const expectedFullPack: Pack = { audio: "084c25abd45f62e50aed566e74ae3317bf844d6c.ogg", image: null, + duration: undefined, name: "jungle", okTransition: null, },