Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/dependencies-34c6fee321
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Jun 21, 2024
2 parents 8a4fe0a + 82c79be commit 602cc5c
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@
"package": "./tools/helper --package",
"preinstall": "",
"pretest": "yarn run compile",
"unit-tests": "nyc mocha --recursive test/units",
"unit-tests": "nyc mocha --recursive test/units/lightspeed",
"test-ui": "yarn run test-ui-current && yarn run test-ui-oldest",
"_test-ui": "extest get-vscode -c ${CODE_VERSION} -s out/test-resources && extest get-chromedriver -c ${CODE_VERSION} -s out/test-resources && extest install-vsix -f ansible-*.vsix -e out/ext -s out/test-resources && extest install-from-marketplace redhat.vscode-yaml ms-python.python -e out/ext -s out/test-resources && extest run-tests -s out/test-resources -e out/ext --code_settings test/testFixtures/settings.json out/client/test/ui-test/allTestsSuite.js",
"test-ui-current": "CODE_VERSION='max' yarn _test-ui",
Expand Down
95 changes: 95 additions & 0 deletions test/units/contentCreator/utilities.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { homedir } from "os";
import { assert } from "chai";
import {
expandPath,
getBinDetail,
runCommand,
} from "../../../src/features/contentCreator/utils";

const homeDir = homedir();

const getBinDetailTests = [
{
name: "valid binary (python)",
command: "python",
arg: "--version",
expected: "Python 3.",
},
{
name: "valid binary (ansible-lint)",
command: "ansible-lint",
arg: "--version",
expected: "ansible-lint",
},
{
name: "invalid binary (ansible-invalid)",
command: "ansible-invalid",
arg: "--version",
expected: "failed",
},
];

const runCommandTests = [
{
name: "successful command execution details",
command: "echo 'Hello, world'",
expected: {
output: "Hello, world",
status: "passed",
},
},
{
name: "unsuccessful command execution details",
command: "echos 'Hello, world'",
expected: {
output: "echos",
status: "failed",
},
},
];

const expandPathTests = [
{
name: "expand path for '~' operator",
pathUrl: "~/path/to/file",
expected: `${homeDir}/path/to/file`,
},
{
name: "expand path for '$HOME' env var",
pathUrl: "~/path/to/file2",
expected: `${homeDir}/path/to/file2`,
},
{
name: "not expand path for any other symbols/vars",
pathUrl: "*/path/to/file3",
expected: `*/path/to/file3`,
},
];

describe("'getBinDetail()' utility functions for the content creator", () => {
getBinDetailTests.forEach(({ name, command, arg, expected }) => {
it(`should provide details for ${name}`, async function () {
const result = (await getBinDetail(command, arg)).toString();
assert.include(result, expected);
});
});
});

describe("'runCommand()' utility functions for the content creator", () => {
runCommandTests.forEach(({ name, command, expected }) => {
it(`should provide details for ${name}`, async function () {
const result = await runCommand(command, process.env);
assert.include(result.output, expected.output);
assert.equal(result.status, expected.status);
});
});
});

describe("'expandPath()' utility functions for the content creator", () => {
expandPathTests.forEach(({ name, pathUrl, expected }) => {
it(`should provide details for ${name}`, function () {
const result = expandPath(pathUrl);
assert.equal(result, expected);
});
});
});

0 comments on commit 602cc5c

Please sign in to comment.