Merge pull request #3643 from github/robertbrignull/re-enable-short-paths

Re-enable windows 8.3 paths in tests
This commit is contained in:
Robert
2024-06-19 10:20:24 +01:00
committed by GitHub
2 changed files with 109 additions and 0 deletions

View File

@@ -144,6 +144,19 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest]
steps:
# Enable 8.3 filename creation. This is not required to run the extension but it is required for the unit tests to pass.
# This feature is currently enabled by default in Windows 11 for the C: drive and therefore we must maintain support for it.
# This setting needs to be enabled before files are created, i.e. before we checkout the repository.
- name: Enable 8.3 filenames
shell: pwsh
if: ${{ matrix.os == 'windows-latest' }}
run: |
$shortNameEnableProcess = Start-Process -FilePath fsutil.exe -ArgumentList ('8dot3name', 'set', '0') -Wait -PassThru
$shortNameEnableExitCode = $shortNameEnableProcess.ExitCode
if ($shortNameEnableExitCode -ne 0) {
exit $shortNameEnableExitCode
}
- name: Checkout
uses: actions/checkout@v4
with:

View File

@@ -0,0 +1,96 @@
import { platform } from "os";
import type { BaseLogger } from "../../../src/common/logging";
import { expandShortPaths } from "../../../src/common/short-paths";
import { join } from "path";
describe("expandShortPaths", () => {
let logger: BaseLogger;
beforeEach(() => {
logger = {
log: jest.fn(),
};
});
describe("on POSIX", () => {
if (platform() === "win32") {
console.log(`Skipping test on Windows`);
return;
}
it("should return the same path for non-Windows platforms", async () => {
const path = "/home/user/some~path";
const result = await expandShortPaths(path, logger);
expect(logger.log).not.toHaveBeenCalled();
expect(result).toBe(path);
});
});
describe("on Windows", () => {
if (platform() !== "win32") {
console.log(`Skipping test on non-Windows`);
return;
}
it("should return the same path if no short components", async () => {
const path = "C:\\Program Files\\Some Folder";
const result = await expandShortPaths(path, logger);
expect(logger.log).toHaveBeenCalledWith(
`Expanding short paths in: ${path}`,
);
expect(logger.log).toHaveBeenCalledWith(
"Skipping due to no short components",
);
expect(result).toBe(path);
});
it("should not attempt to expand long paths with '~' in the name", async () => {
const testDir = join(__dirname, "../data/short-paths");
const path = join(testDir, "textfile-with~tilde.txt");
const result = await expandShortPaths(path, logger);
expect(logger.log).toHaveBeenCalledWith(
`Expanding short paths in: ${path}`,
);
expect(logger.log).toHaveBeenCalledWith(
`Expanding short path component: textfile-with~tilde.txt`,
);
expect(logger.log).toHaveBeenCalledWith(`Component is not a short name`);
expect(result).toBe(join(testDir, "textfile-with~tilde.txt"));
});
it("should expand a short path", async () => {
const path = "C:\\PROGRA~1\\Some Folder";
const result = await expandShortPaths(path, logger);
expect(logger.log).toHaveBeenCalledWith(
`Expanding short paths in: ${path}`,
);
expect(logger.log).toHaveBeenCalledWith(
`Expanding short path component: PROGRA~1`,
);
expect(result).toBe("C:\\Program Files\\Some Folder");
});
it("should expand multiple short paths", async () => {
const testDir = join(__dirname, "../data/short-paths");
const path = join(testDir, "FOLDER~1", "TEXTFI~1.TXT");
const result = await expandShortPaths(path, logger);
expect(logger.log).toHaveBeenCalledWith(
`Expanding short paths in: ${path}`,
);
expect(logger.log).toHaveBeenCalledWith(
`Expanding short path component: FOLDER~1`,
);
expect(logger.log).toHaveBeenCalledWith(
`Expanding short path component: TEXTFI~1.TXT`,
);
expect(result).toBe(
join(testDir, "folder with space", ".textfile+extra.characters.txt"),
);
});
});
});