Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross-Platform Compatibility for tests #75 #80

Merged
merged 4 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a watch script to auto-update the build

"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);
}
Loading