Skip to content

Commit

Permalink
Add unit tests for isWorkflowTestsDocument, isNativeWorkflowDocument,…
Browse files Browse the repository at this point in the history
… and isFormat2WorkflowDocument
  • Loading branch information
davelopez committed Jun 9, 2024
1 parent f226f95 commit 42d6114
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions client/tests/unit/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { it } from "@jest/globals"; // This is a workaround for type clashes between jest and mocha
import { URI } from "vscode-uri";
import { isFormat2WorkflowDocument, isNativeWorkflowDocument, isWorkflowTestsDocument } from "../../src/common/utils";

jest.mock(
"vscode",
() => ({
workspace: {
// Mock properties and methods of `workspace` as needed for your tests
},
// Add other vscode namespaces and members you need to mock
}),
{ virtual: true }
);

describe("Common Utils", () => {
describe("isWorkflowTestsDocument", () => {
it.each([
["-test.yml", true],
["-tests.yml", true],
["-test.yaml", true],
["-tests.yaml", true],
["test.txt", false],
["tests.txt", false],
["test.yml", false],
["tests.yml", false],
["whatever.test.yml", false],
["whatever.gxwf.test.yml", false],
["whatevertest.yml", false],
["whatever.gxwftest.yml", false],
])("given '%s' should return %s", (input: string, expected: boolean) => {
expect(isWorkflowTestsDocument(URI.parse(input))).toBe(expected);
});
});

describe("isNativeWorkflowDocument", () => {
it.each([
["test.ga", true],
["whatever.ga", true],
["asd.txt", false],
["test.yaml", false],
])("given '%s' should return %s", (input: string, expected: boolean) => {
expect(isNativeWorkflowDocument(URI.parse(input))).toBe(expected);
});
});

describe("isFormat2WorkflowDocument", () => {
it.each([
["test.gxwf.yaml", true],
["whatever.gxwf.yaml", true],
["test.gxwf.yml", true],
["whatever.gxwf.yml", true],
["asd.txt", false],
["-test.yaml", false],
["whatever-test.yaml", false],
["whatever.gxwf-test.yaml", false],
["whatever.gxwf.test.yaml", false],
])("given '%s' should return %s", (input: string, expected: boolean) => {
expect(isFormat2WorkflowDocument(URI.parse(input))).toBe(expected);
});
});
});

0 comments on commit 42d6114

Please sign in to comment.