Skip to content

Commit

Permalink
fix: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jersou committed Oct 7, 2024
1 parent e8a2d59 commit d9ca768
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
3 changes: 2 additions & 1 deletion generate/rss_parser_test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ModOptions } from "../types.ts";
import { fixUrl, getItemFileName } from "./rss_parser.ts";
import { assert, assertEquals } from "@std/assert";

Expand All @@ -7,7 +8,7 @@ Deno.test("getItemFileName", () => {
pubDate: "0",
title: 'a\\z/e:r*t?y"u<i>o|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."),
);
});

Expand Down
2 changes: 1 addition & 1 deletion gui/gui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
24 changes: 13 additions & 11 deletions serialize/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions serialize/converter_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
6 changes: 6 additions & 0 deletions test_data/test_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ export const expectedMoyPack: Pack = {
{
class: "StageNode-Story",
audio: "46fe70d98b9763ab70b7e7cea4627e4f8b7c585a.ogg",
duration: undefined,
image: null,
name: "city",
okTransition: null,
Expand All @@ -286,6 +287,7 @@ export const expectedMoyPack: Pack = {
class: "StageNode-Story",
name: "alice-jungle",
audio: "f493d4e986a1278ca7db3f7c65bf8ee32535b2e4.ogg",
duration: undefined,
image: null,
okTransition: null,
},
Expand Down Expand Up @@ -903,6 +905,7 @@ export const expectedFullPack: Pack = {
class: "StageNode-Story",
audio:
"46fe70d98b9763ab70b7e7cea4627e4f8b7c585a.ogg",
duration: undefined,
image: null,
name: "city",
okTransition: null,
Expand Down Expand Up @@ -933,6 +936,7 @@ export const expectedFullPack: Pack = {
class: "StageNode-Story",
audio:
"f493d4e986a1278ca7db3f7c65bf8ee32535b2e4.ogg",
duration: undefined,
image: null,
name: "alice-jungle",
okTransition: null,
Expand Down Expand Up @@ -999,6 +1003,7 @@ export const expectedFullPack: Pack = {
class: "StageNode-Story",
audio:
"90304af3b9d81fb1590ad367df796e791ea78750.ogg",
duration: undefined,
image: null,
name: "bob-city",
okTransition: null,
Expand Down Expand Up @@ -1028,6 +1033,7 @@ export const expectedFullPack: Pack = {
audio:
"084c25abd45f62e50aed566e74ae3317bf844d6c.ogg",
image: null,
duration: undefined,
name: "jungle",
okTransition: null,
},
Expand Down

0 comments on commit d9ca768

Please sign in to comment.