Use file system path

On windows, the `Uri.path` will return an extra folder, as we can see in the tests:

```
ENOENT: no such file or directory, open 'D:\C:\Users\RUNNER~1\AppData\Local\Temp\tmp-4784XPDQPb5jM6IW\test-ql-pack-ruby\qlpack.yml'
```

Let's use `Uri.fsPath` instead.
This commit is contained in:
Elena Tanasoiu
2023-02-14 18:36:25 +00:00
parent 3e87a2d53c
commit 086df15357
2 changed files with 8 additions and 8 deletions

View File

@@ -64,7 +64,7 @@ export class QlPackGenerator {
}
private async createQlPackYaml() {
const qlPackFilePath = join(this.folderUri.path, this.qlpackFileName);
const qlPackFilePath = join(this.folderUri.fsPath, this.qlpackFileName);
const qlPackYml = {
name: this.qlpackName,
@@ -78,7 +78,7 @@ export class QlPackGenerator {
}
private async createExampleQlFile() {
const exampleQlFilePath = join(this.folderUri.path, "example.ql");
const exampleQlFilePath = join(this.folderUri.fsPath, "example.ql");
const exampleQl = `
/**
@@ -98,6 +98,6 @@ select "Hello, world!"
}
private async createCodeqlPackLockYaml() {
await this.cliServer.packAdd(this.folderUri.path, this.queryLanguage);
await this.cliServer.packAdd(this.folderUri.fsPath, this.queryLanguage);
}
}

View File

@@ -2,8 +2,7 @@ import { join } from "path";
import { existsSync } from "fs";
import { QlPackGenerator, QueryLanguage } from "../../../src/qlpack-generator";
import { CodeQLCliServer } from "../../../src/cli";
import { isFolderAlreadyInWorkspace } from "../../../src/helpers";
import { workspace } from "vscode";
import { Uri, workspace } from "vscode";
import { getErrorMessage } from "../../../src/pure/helpers-pure";
import * as tmp from "tmp";
@@ -22,7 +21,7 @@ describe("QlPackGenerator", () => {
language = "ruby";
packFolderName = `test-ql-pack-${language}`;
packFolderPath = join(dir.name, packFolderName);
packFolderPath = Uri.file(join(dir.name, packFolderName)).fsPath;
qlPackYamlFilePath = join(packFolderPath, "qlpack.yml");
exampleQlFilePath = join(packFolderPath, "example.ql");
@@ -60,15 +59,16 @@ describe("QlPackGenerator", () => {
});
it("should generate a QL pack", async () => {
expect(isFolderAlreadyInWorkspace(packFolderName)).toBe(false);
expect(existsSync(packFolderPath)).toBe(false);
expect(existsSync(qlPackYamlFilePath)).toBe(false);
expect(existsSync(exampleQlFilePath)).toBe(false);
await generator.generate();
expect(isFolderAlreadyInWorkspace(packFolderName)).toBe(true);
expect(existsSync(packFolderPath)).toBe(true);
expect(existsSync(qlPackYamlFilePath)).toBe(true);
expect(existsSync(exampleQlFilePath)).toBe(true);
expect(packAddSpy).toHaveBeenCalledWith(packFolderPath, language);
});
});