-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TypeSpecValidation] bug fix: drive letter inconsistency for windows (#…
- Loading branch information
1 parent
620e2ab
commit 8c0a0df
Showing
4 changed files
with
101 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { NpmPrefixRule } from "../src/rules/npm-prefix.js"; | ||
import { IGitOperation, TsvTestHost } from "./tsv-test-host.js"; | ||
import { strict as assert } from "node:assert"; | ||
import path from "path"; | ||
|
||
describe("npm-prefix", function () { | ||
it("should succeed if node returns inconsistent drive letter capitalization", async function () { | ||
let host = new TsvTestHost(path.win32); | ||
host.runCmd = async (cmd: string, _cwd: string): Promise<[Error | null, string, string]> => { | ||
if (cmd.includes("npm prefix")) { | ||
return [null, `C:${path.sep}Git${path.sep}azure-rest-api-specs`, ""]; | ||
} else { | ||
return [null, "", ""]; | ||
} | ||
}; | ||
host.gitOperation = (_folder: string): IGitOperation => { | ||
return { | ||
status: () => { | ||
return Promise.resolve({ | ||
modified: [], | ||
isClean: () => true, | ||
}); | ||
}, | ||
diff: () => { | ||
return Promise.resolve(""); | ||
}, | ||
revparse: () => { | ||
return Promise.resolve("c:/Git/azure-rest-api-specs"); | ||
}, | ||
}; | ||
}; | ||
|
||
const result = await new NpmPrefixRule().execute(host, TsvTestHost.folder); | ||
|
||
assert(result.success); | ||
}); | ||
|
||
it("should fail if npm prefix mismatch", async function () { | ||
let host = new TsvTestHost(); | ||
host.runCmd = async (cmd: string, _cwd: string): Promise<[Error | null, string, string]> => { | ||
if (cmd.includes("npm prefix")) { | ||
return [null, "/Git/azure-rest-api-specs/specification/foo", ""]; | ||
} else { | ||
return [null, "", ""]; | ||
} | ||
}; | ||
host.gitOperation = (_folder: string): IGitOperation => { | ||
return { | ||
status: () => { | ||
return Promise.resolve({ | ||
modified: [], | ||
isClean: () => true, | ||
}); | ||
}, | ||
diff: () => { | ||
return Promise.resolve(""); | ||
}, | ||
revparse: () => { | ||
return Promise.resolve("/Git/azure-rest-api-specs"); | ||
}, | ||
}; | ||
}; | ||
|
||
const result = await new NpmPrefixRule().execute(host, TsvTestHost.folder); | ||
|
||
assert(!result.success); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,29 @@ | ||
import { TsvTestHost } from "./tsv-test-host.js"; | ||
import { normalizePath } from "../src/utils.js"; | ||
import { strict as assert } from "node:assert"; | ||
import process from "process"; | ||
import path from "path"; | ||
|
||
describe("normalize", function () { | ||
it("should succeed if normalized . and normalized cwd matches", async function () { | ||
let host = new TsvTestHost(); | ||
const dotResult = host.normalizePath("."); | ||
const cwdResult = host.normalizePath(process.cwd()); | ||
const dotResult = normalizePath("."); | ||
const cwdResult = normalizePath(process.cwd()); | ||
assert(dotResult === cwdResult); | ||
}); | ||
|
||
it("should succeed if /foo/bar/ is normalized", async function () { | ||
let host = new TsvTestHost(); | ||
const result = host.normalizePath("/foo/bar/").replace(/^[a-zA-Z]:/g, ""); | ||
assert(result === "/foo/bar"); | ||
const result = normalizePath("/foo/bar/", path.posix); | ||
assert.equal(result, "/foo/bar"); | ||
}); | ||
|
||
it("should succeed if /foo/bar is normalized", async function () { | ||
let host = new TsvTestHost(); | ||
const result = host.normalizePath("/foo/bar").replace(/^[a-zA-Z]:/g, ""); | ||
assert(result === "/foo/bar"); | ||
it("should normalize windows drive letter", async function () { | ||
const lowerResult = normalizePath("c:\\foo\\bar", path.win32); | ||
const upperResult = normalizePath("C:\\foo\\bar", path.win32); | ||
assert.equal(lowerResult, upperResult); | ||
}); | ||
|
||
it("should distinguish different windows drive letters", async function () { | ||
const lowerResult = normalizePath("c:\\foo\\bar", path.win32); | ||
const upperResult = normalizePath("d:\\foo\\bar", path.win32); | ||
assert.notEqual(lowerResult, upperResult); | ||
}); | ||
}); |