Skip to content

Commit

Permalink
test: 🚨 fixed tests for Win32
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Mar 4, 2020
1 parent 39e1394 commit 8813609
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
20 changes: 12 additions & 8 deletions __tests__/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ import path from "path"

const workspaceRoot = path.resolve(__dirname, "workspace")

function f(file: string) {
return file.replace(/\//gu, "\\")
function f(files: Record<string, unknown>) {
return files
? Object.fromEntries(
Object.entries(files).map(([k, v]) => [k.replace(/\\/gu, "/"), v])
)
: files
}

test("parseGitFiles", () => {
Expand All @@ -31,11 +35,11 @@ H 100644 afcd42dfe13cb03ac1cdf0f7843188bdb6cbdb66 0 package.json`
})

test("getGitFiles", async () => {
const files = await getGitFiles(path.resolve(workspaceRoot, "apps"))
expect(files[f("__tests__/workspace/apps/app1/package.json")]).toMatch(
const files = f(await getGitFiles(path.resolve(workspaceRoot, "apps")))
expect(files["__tests__/workspace/apps/app1/package.json"]).toMatch(
/^[a-z0-9]*$/u
)
expect(files[f("__tests__/workspace/apps/app2/package.json")]).toMatch(
expect(files["__tests__/workspace/apps/app2/package.json"]).toMatch(
/^[a-z0-9]*$/u
)
expect(files[""]).toMatch(/^\d+\.\d+$/u)
Expand All @@ -44,9 +48,9 @@ test("getGitFiles", async () => {
})

test("cache", async () => {
const files = await cache.getFiles(path.resolve(workspaceRoot, "apps"))
expect(files[f("app1/package.json")]).toMatch(/^[a-z0-9]*$/u)
expect(files[f("app2/package.json")]).toMatch(/^[a-z0-9]*$/u)
const files = f(await cache.getFiles(path.resolve(workspaceRoot, "apps")))
expect(files["app1/package.json"]).toMatch(/^[a-z0-9]*$/u)
expect(files["app2/package.json"]).toMatch(/^[a-z0-9]*$/u)
expect(Object.keys(files)).toHaveLength(2)
expect(cache.cache.size).not.toBe(0)
await cache.getFiles(path.resolve(workspaceRoot, "apps"))
Expand Down
13 changes: 9 additions & 4 deletions __tests__/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { findPackages, findUp, getPackage } from "../src/package"
import path from "path"

function fa(files: string[]) {
return files.map(f => f.replace(/\//gu, "\\"))
return files.map(f => f.replace(/\\/gu, "/"))
}

test("findPackages without options ", async () => {
Expand All @@ -14,9 +14,14 @@ test("findPackages without options ", async () => {
)
.map(p => path.relative(root, p))
.sort()
expect(packages).toStrictEqual(
fa(["", "apps/app1", "apps/app2", "libs/lib1", "libs/lib2", "libs/lib3"])
)
expect(fa(packages)).toStrictEqual([
"",
"apps/app1",
"apps/app2",
"libs/lib1",
"libs/lib2",
"libs/lib3",
])
})

test("findUp", () => {
Expand Down

0 comments on commit 8813609

Please sign in to comment.