Skip to content

Commit 67eeeeb

Browse files
committed
fix: improve path handling in tests on windows
1 parent 9516d54 commit 67eeeeb

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

packages/plugins/swr/tests/swr.test.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,13 @@ ${sharedModel}
106106
const { name: projectDir } = tmp.dirSync();
107107
fs.writeFileSync(path.join(projectDir, 'swr'), 'hello');
108108

109+
const swrPath = normalizePath(path.join(__dirname, '..', 'dist'));
110+
109111
await expect(
110112
loadSchema(
111113
`
112114
plugin swr {
113-
provider = '${normalizePath(path.resolve(__dirname, '../dist'))}'
115+
provider = '${swrPath}'
114116
output = '$projectRoot/swr'
115117
}
116118
@@ -122,7 +124,7 @@ ${sharedModel}
122124
password String @omit
123125
}
124126
`,
125-
{ pushDb: false, projectDir, extraDependencies: [`${normalizePath(path.join(__dirname, '../dist'))}`] }
127+
{ pushDb: false, projectDir, extraDependencies: [`${swrPath}`] }
126128
)
127129
).rejects.toThrow('already exists and is not a directory');
128130
});

packages/testtools/src/schema.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,14 @@ export function installPackage(pkg: string, dev = false) {
6161
run(`npm install ${dev ? '-D' : ''} --no-audit --no-fund ${pkg}`);
6262
}
6363

64+
/**
65+
* Normalizes a path for use within zenstack model files, that is: replaces the default path separators for the OS with POSIX path separators.
66+
*
67+
* @param p A filesystem path
68+
* @returns The filesystem path adjusted to posix path separators (`/`)
69+
*/
6470
export function normalizePath(p: string) {
65-
return path.normalize(p);
71+
return p ? p.split(path.sep).join(path.posix.sep) : p;
6672
}
6773

6874
export function getWorkspaceRoot(start: string) {
@@ -163,7 +169,6 @@ export async function loadSchema(schema: string, options?: SchemaLoadOptions) {
163169
}
164170

165171
const workspaceRoot = getWorkspaceRoot(__dirname);
166-
167172
if (!workspaceRoot) {
168173
throw new Error('Could not find workspace root');
169174
}

0 commit comments

Comments
 (0)