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() { private async createQlPackYaml() {
const qlPackFilePath = join(this.folderUri.path, this.qlpackFileName); const qlPackFilePath = join(this.folderUri.fsPath, this.qlpackFileName);
const qlPackYml = { const qlPackYml = {
name: this.qlpackName, name: this.qlpackName,
@@ -78,7 +78,7 @@ export class QlPackGenerator {
} }
private async createExampleQlFile() { private async createExampleQlFile() {
const exampleQlFilePath = join(this.folderUri.path, "example.ql"); const exampleQlFilePath = join(this.folderUri.fsPath, "example.ql");
const exampleQl = ` const exampleQl = `
/** /**
@@ -98,6 +98,6 @@ select "Hello, world!"
} }
private async createCodeqlPackLockYaml() { 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 { existsSync } from "fs";
import { QlPackGenerator, QueryLanguage } from "../../../src/qlpack-generator"; import { QlPackGenerator, QueryLanguage } from "../../../src/qlpack-generator";
import { CodeQLCliServer } from "../../../src/cli"; import { CodeQLCliServer } from "../../../src/cli";
import { isFolderAlreadyInWorkspace } from "../../../src/helpers"; import { Uri, workspace } from "vscode";
import { workspace } from "vscode";
import { getErrorMessage } from "../../../src/pure/helpers-pure"; import { getErrorMessage } from "../../../src/pure/helpers-pure";
import * as tmp from "tmp"; import * as tmp from "tmp";
@@ -22,7 +21,7 @@ describe("QlPackGenerator", () => {
language = "ruby"; language = "ruby";
packFolderName = `test-ql-pack-${language}`; packFolderName = `test-ql-pack-${language}`;
packFolderPath = join(dir.name, packFolderName); packFolderPath = Uri.file(join(dir.name, packFolderName)).fsPath;
qlPackYamlFilePath = join(packFolderPath, "qlpack.yml"); qlPackYamlFilePath = join(packFolderPath, "qlpack.yml");
exampleQlFilePath = join(packFolderPath, "example.ql"); exampleQlFilePath = join(packFolderPath, "example.ql");
@@ -60,15 +59,16 @@ describe("QlPackGenerator", () => {
}); });
it("should generate a QL pack", async () => { it("should generate a QL pack", async () => {
expect(isFolderAlreadyInWorkspace(packFolderName)).toBe(false); expect(existsSync(packFolderPath)).toBe(false);
expect(existsSync(qlPackYamlFilePath)).toBe(false); expect(existsSync(qlPackYamlFilePath)).toBe(false);
expect(existsSync(exampleQlFilePath)).toBe(false); expect(existsSync(exampleQlFilePath)).toBe(false);
await generator.generate(); await generator.generate();
expect(isFolderAlreadyInWorkspace(packFolderName)).toBe(true); expect(existsSync(packFolderPath)).toBe(true);
expect(existsSync(qlPackYamlFilePath)).toBe(true); expect(existsSync(qlPackYamlFilePath)).toBe(true);
expect(existsSync(exampleQlFilePath)).toBe(true); expect(existsSync(exampleQlFilePath)).toBe(true);
expect(packAddSpy).toHaveBeenCalledWith(packFolderPath, language); expect(packAddSpy).toHaveBeenCalledWith(packFolderPath, language);
}); });
}); });