Skip to content

Commit

Permalink
Update tests to pass in Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedsalem401 committed Nov 30, 2023
1 parent 2edbc7f commit a7d63f4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"pretest": "npm run build && node ./dist/src/bin/index.js ./__mocks__/content",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
"build": "tsc --p tsconfig.lib.json",
"watch": "tsc --p tsconfig.lib.json --watch",
"changeset": "changeset",
"prepublishOnly": "npm run build",
"release": "changeset publish"
Expand Down Expand Up @@ -68,4 +69,4 @@
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
}
}
}
20 changes: 13 additions & 7 deletions src/tests/markdowndb.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { MarkdownDB } from "../lib/markdowndb";
import { recursiveWalkDir } from "../lib/recursiveWalkDir";
import { File, MddbFile, Table } from "../lib/schema";
import path from "path";

/**
* @jest-environment node
Expand Down Expand Up @@ -73,7 +74,7 @@ describe("MarkdownDB - default config", () => {
`${pathToContentFixture}/blog/blog3.mdx`,
`${pathToContentFixture}/blog/blog2.mdx`,
`${pathToContentFixture}/blog0.mdx`,
];
].map(normalizePathSeparator);

expect(dbFilesPaths).toHaveLength(expectedPaths.length);
dbFilesPaths.forEach((p) => {
Expand All @@ -88,7 +89,7 @@ describe("MarkdownDB - default config", () => {
const expectedPaths = [
`${pathToContentFixture}/blog/blog3.mdx`,
`${pathToContentFixture}/blog/blog2.mdx`,
];
].map(normalizePathSeparator);

expect(dbFilesPaths).toHaveLength(expectedPaths.length);
dbFilesPaths.forEach((p) => {
Expand All @@ -102,7 +103,7 @@ describe("MarkdownDB - default config", () => {

const expectedPaths = [
`${pathToContentFixture}/assets/datopian-logo.png`,
];
].map(normalizePathSeparator);

expect(dbFilesPaths).toHaveLength(expectedPaths.length);
dbFilesPaths.forEach((p) => {
Expand All @@ -119,7 +120,7 @@ describe("MarkdownDB - default config", () => {
const expectedPaths = [
`${pathToContentFixture}/blog/blog1.mdx`,
`${pathToContentFixture}/blog/blog2.mdx`,
];
].map(normalizePathSeparator);

expect(dbFilesPaths).toHaveLength(expectedPaths.length);
dbFilesPaths.forEach((p) => {
Expand All @@ -133,7 +134,7 @@ describe("MarkdownDB - default config", () => {
});
const dbFilesPaths = dbFiles.map((f) => f.file_path);

const expectedPaths = [`${pathToContentFixture}/blog/blog1.mdx`];
const expectedPaths = [`${pathToContentFixture}/blog/blog1.mdx`].map(normalizePathSeparator);

expect(dbFilesPaths).toHaveLength(expectedPaths.length);
dbFilesPaths.forEach((p) => {
Expand All @@ -147,7 +148,7 @@ describe("MarkdownDB - default config", () => {
});
const dbFilesPaths = dbFiles.map((f) => f.file_path);

const expectedPaths = [`${pathToContentFixture}/blog/blog2.mdx`];
const expectedPaths = [`${pathToContentFixture}/blog/blog2.mdx`].map(normalizePathSeparator);

expect(dbFilesPaths).toHaveLength(expectedPaths.length);
dbFilesPaths.forEach((p) => {
Expand All @@ -162,7 +163,7 @@ describe("MarkdownDB - default config", () => {
extensions: ["md", "mdx"],
});
const dbFilesPaths = dbFiles.map((f) => f.file_path);
const expectedPaths = [`${pathToContentFixture}/news/news1.mdx`];
const expectedPaths = [`${pathToContentFixture}/news/news1.mdx`].map(normalizePathSeparator);

expect(dbFilesPaths).toHaveLength(expectedPaths.length);
dbFilesPaths.forEach((p) => {
Expand Down Expand Up @@ -324,3 +325,8 @@ describe("MarkdownDB - custom config", () => {
});
});
});

function normalizePathSeparator(filePath: string): string {
// Use path.sep to dynamically determine the path separator based on the OS
return filePath.split("/").join(path.sep);
}
8 changes: 7 additions & 1 deletion src/tests/recursiveWalkDir.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { recursiveWalkDir } from "../lib/recursiveWalkDir";
import path from "path";

describe("recursiveWalkDir", () => {
const contentFixturePath = "__mocks__/content/blog";
Expand All @@ -12,7 +13,7 @@ describe("recursiveWalkDir", () => {
`${contentFixturePath}/blog3.mdx`,
`${contentFixturePath}/blog2.mdx`,
`${contentFixturePath}/blog1.mdx`,
];
].map(normalizePathSeparator);

test("should return all files in a directory", async () => {
const paths = recursiveWalkDir(contentFixturePath);
Expand All @@ -23,3 +24,8 @@ describe("recursiveWalkDir", () => {
});
});
});

function normalizePathSeparator(filePath: string): string {
// Use path.sep to dynamically determine the path separator based on the OS
return filePath.split("/").join(path.sep);
}

0 comments on commit a7d63f4

Please sign in to comment.