|
| 1 | +import * as glob from "glob"; |
| 2 | +import { FsFileSystem } from "../../packages/core/util/FileSystem"; |
| 3 | + |
| 4 | +describe("Unit - FsFileSystem", () => { |
| 5 | + let fileSystem: FsFileSystem; |
| 6 | + |
| 7 | + beforeEach(() => { |
| 8 | + fileSystem = new FsFileSystem(); |
| 9 | + }); |
| 10 | + |
| 11 | + describe("glob", () => { |
| 12 | + it("should pass a forward-slash pattern to glob even when dirPath uses backslashes", () => { |
| 13 | + spyOn(glob, "sync").and.returnValue([]); |
| 14 | + const windowsDirPath = "C:\\Work\\git\\project\\src"; |
| 15 | + fileSystem.glob(windowsDirPath, "**/*.ts"); |
| 16 | + expect(glob.sync).toHaveBeenCalledWith( |
| 17 | + "C:/Work/git/project/src/**/*.ts", |
| 18 | + jasmine.objectContaining({ nodir: true }) |
| 19 | + ); |
| 20 | + }); |
| 21 | + |
| 22 | + it("should pass a forward-slash pattern to glob even when pattern contains backslashes", () => { |
| 23 | + spyOn(glob, "sync").and.returnValue([]); |
| 24 | + fileSystem.glob("C:\\Work\\project", "sub\\**\\*.ts"); |
| 25 | + expect(glob.sync).toHaveBeenCalledWith( |
| 26 | + "C:/Work/project/sub/**/*.ts", |
| 27 | + jasmine.objectContaining({ nodir: true }) |
| 28 | + ); |
| 29 | + }); |
| 30 | + |
| 31 | + it("should work correctly with forward-slash paths (non-Windows)", () => { |
| 32 | + spyOn(glob, "sync").and.returnValue([ |
| 33 | + "/home/user/project/src/app.ts" |
| 34 | + ] as any); |
| 35 | + const result = fileSystem.glob("/home/user/project", "src/**/*.ts"); |
| 36 | + expect(glob.sync).toHaveBeenCalledWith( |
| 37 | + "/home/user/project/src/**/*.ts", |
| 38 | + jasmine.objectContaining({ nodir: true }) |
| 39 | + ); |
| 40 | + expect(result).toEqual(["/home/user/project/src/app.ts"]); |
| 41 | + }); |
| 42 | + }); |
| 43 | +}); |
0 commit comments