Skip to content

Commit

Permalink
refactor: move test dir into src
Browse files Browse the repository at this point in the history
Fixes ts warnings due too root dir.
  • Loading branch information
aalemayhu committed Jan 8, 2024
1 parent 208fecd commit 0b81f3f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions src/test/helpers/createDatabaseFrom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {ZipHandler} from "../../ZipHandler";
import SQLHandler from "../../SQLHandler";

export async function createDatabaseFrom(zip: ZipHandler) {
const collectionFilename = "collection.anki21";
const collection = zip.files.find((f) => f.name === collectionFilename);
const contents = collection!.contents;
const db = new SQLHandler();
await db.load(contents);
return db;
}
11 changes: 11 additions & 0 deletions src/test/helpers/getInputFileAsZipHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import path from "path";
import fs from "fs";
import {ZipHandler} from "../../ZipHandler";

export async function getInputFileAsZipHandler(apkg: string) {
const filePath = path.join(__dirname, `artifacts/${apkg}`);
const data = fs.readFileSync(filePath);
const zip = new ZipHandler();
await zip.build(data);
return zip;
}
25 changes: 5 additions & 20 deletions test/lib.test.ts → src/test/lib.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import path from "path";
import fs from "fs";

import {beforeAll, test, expect} from "vitest";
import {beforeAll, expect, test} from "vitest";

import SQLHandler from "../src/SQLHandler";
import { ZipHandler } from "../src/ZipHandler";
import SQLHandler from "../SQLHandler";
import {ZipHandler} from "../ZipHandler";
import {getInputFileAsZipHandler} from "./helpers/getInputFileAsZipHandler";
import {createDatabaseFrom} from "./helpers/createDatabaseFrom";

let zip: ZipHandler;
let db: SQLHandler;
Expand Down Expand Up @@ -58,23 +60,6 @@ test("get deck name", async (t) => {
expect(expected).toStrictEqual(deck.name);
});

async function getInputFileAsZipHandler(apkg: string) {
const filePath = path.join(__dirname, `artifacts/${apkg}`);
const data = fs.readFileSync(filePath);
const zip = new ZipHandler();
await zip.build(data);
return zip;
}

async function createDatabaseFrom(zipHandler: ZipHandler) {
const collectionFilename = "collection.anki21";
const collection = zip.files.find((f) => f.name === collectionFilename);
const contents = collection!.contents;
db = new SQLHandler();
await db.load(contents);
return db;
}

test('get non-default deck name', async () => {
const zipHandler = await getInputFileAsZipHandler("Capitals.apkg");
const database = await createDatabaseFrom(zipHandler);
Expand Down

0 comments on commit 0b81f3f

Please sign in to comment.