Skip to content

Commit

Permalink
Fix the tests under Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
illright committed Jun 16, 2024
1 parent b3354de commit e24ed06
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
5 changes: 3 additions & 2 deletions src/specs/fsd-aware-traverse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { test, expect } from "vitest";

import { getAllSlices, getSlices, type Folder } from "../index.js";
import { parseIntoFolder } from "./prepare-test.js";
import { join } from "node:path";

test("getSlices", () => {
const rootFolder = parseIntoFolder(`
Expand Down Expand Up @@ -37,10 +38,10 @@ test("getSlices", () => {
});
expect(getSlices(rootFolder.children[2] as Folder)).toEqual({
editor: (rootFolder.children[2] as Folder).children[0],
"settings/notifications": (
[join("settings", "notifications")]: (
(rootFolder.children[2] as Folder).children[1] as Folder
).children[0],
"settings/profile": (
[join("settings", "profile")]: (
(rootFolder.children[2] as Folder).children[1] as Folder
).children[1],
});
Expand Down
30 changes: 17 additions & 13 deletions src/specs/prepare-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ export function parseIntoFolder(fsMarkup: string): Folder {
.map((line, _i, lines) => line.slice(lines[0].search(/\S/)))
.filter(Boolean);

return parseFolder(lines, "/");
return parseFolder(lines, joinFromRoot());
}

export function joinFromRoot(...segments: Array<string>) {
return join("/", ...segments);
}

if (import.meta.vitest) {
Expand All @@ -61,59 +65,59 @@ if (import.meta.vitest) {

expect(root).toEqual({
type: "folder",
path: "/",
path: joinFromRoot(),
children: [
{
type: "folder",
path: "/entities",
path: joinFromRoot('entities'),
children: [
{
type: "folder",
path: "/entities/users",
path: joinFromRoot('entities', 'users'),
children: [
{
type: "folder",
path: "/entities/users/ui",
path: joinFromRoot('entities', 'users', 'ui'),
children: [],
},
{
type: "file",
path: "/entities/users/index.ts",
path: joinFromRoot('entities', 'users', 'index.ts'),
},
],
},
{
type: "folder",
path: "/entities/posts",
path: joinFromRoot('entities', 'posts'),
children: [
{
type: "folder",
path: "/entities/posts/ui",
path: joinFromRoot('entities', 'posts', 'ui'),
children: [],
},
{
type: "file",
path: "/entities/posts/index.ts",
path: joinFromRoot('entities', 'posts', 'index.ts'),
},
],
},
],
},
{
type: "folder",
path: "/shared",
path: joinFromRoot('shared'),
children: [
{
type: "folder",
path: "/shared/ui",
path: joinFromRoot('shared', 'ui'),
children: [
{
type: "file",
path: "/shared/ui/index.ts",
path: joinFromRoot('shared', 'ui', 'index.ts'),
},
{
type: "file",
path: "/shared/ui/Button.tsx",
path: joinFromRoot('shared', 'ui', 'Button.tsx'),
},
],
},
Expand Down

0 comments on commit e24ed06

Please sign in to comment.