Skip to content

Commit

Permalink
tests: increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
spmeesseman committed Jan 23, 2022
1 parent 69e368a commit b4d74c3
Show file tree
Hide file tree
Showing 17 changed files with 186 additions and 67 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
"bash"
],
"main": "./dist/extension",
"activationEvents": [],
"activationEvents": [
"*"
],
"scripts": {
"build": "npx tsc -p ./",
"clean": "rimraf dist && rimraf .nyc_output && rimraf coverage",
Expand Down
25 changes: 12 additions & 13 deletions src/providers/maven.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ export class MavenTaskProvider extends TaskExplorerProvider implements TaskExplo
public async readUriTasks(uri: Uri, logPad: string): Promise<Task[]>
{
const cwd = path.dirname(uri.fsPath),
folder = workspace.getWorkspaceFolder(uri),
args = [];
folder = workspace.getWorkspaceFolder(uri);

if (!folder) {
return [];
Expand Down Expand Up @@ -141,7 +140,7 @@ export class MavenTaskProvider extends TaskExplorerProvider implements TaskExplo
const kindValidate: TaskExplorerDefinition = {
...defaultDef,
...{
cmdLine: this.getCommand() + " valudate -f " + defaultDef.fileName,
cmdLine: this.getCommand() + " validate -f " + defaultDef.fileName,
}
};

Expand All @@ -155,16 +154,16 @@ export class MavenTaskProvider extends TaskExplorerProvider implements TaskExplo
//
// Create the shell execution objects
//
const executionClean = kindClean.cmdLine ? new ShellExecution(kindClean.cmdLine, options) : undefined;
const executionCompile = kindCompile.cmdLine ? new ShellExecution(kindCompile.cmdLine, options) : undefined;
const executionDeploy = kindDeploy.cmdLine ? new ShellExecution(kindDeploy.cmdLine, options) : undefined;
const executionInstall = kindInstall.cmdLine ? new ShellExecution(kindInstall.cmdLine, options) : undefined;
const executionPackage = kindPackage.cmdLine ? new ShellExecution(kindPackage.cmdLine, options) : undefined;
const executionTest = kindTest.cmdLine ? new ShellExecution(kindTest.cmdLine, options) : undefined;
const executionValidate = kindValidate.cmdLine ? new ShellExecution(kindValidate.cmdLine, options) : undefined;
const executionVerify = kindVerify.cmdLine ? new ShellExecution(kindVerify.cmdLine, options) : undefined;

log.methodDone("read app-ublisher file uri tasks", 1, logPad, true);
const executionClean = new ShellExecution(kindClean.cmdLine as string, options);
const executionCompile = new ShellExecution(kindCompile.cmdLine as string, options);
const executionDeploy = new ShellExecution(kindDeploy.cmdLine as string, options);
const executionInstall = new ShellExecution(kindInstall.cmdLine as string, options);
const executionPackage = new ShellExecution(kindPackage.cmdLine as string, options);
const executionTest = new ShellExecution(kindTest.cmdLine as string, options);
const executionValidate = new ShellExecution(kindValidate.cmdLine as string, options);
const executionVerify = new ShellExecution(kindVerify.cmdLine as string, options);

log.methodDone("read maven file uri tasks", 1, logPad, true);

return [ new Task(kindClean, folder, "Clean", "maven", executionClean, undefined),
new Task(kindCompile, folder, "Compile", "maven", executionCompile, undefined),
Expand Down
1 change: 0 additions & 1 deletion src/providers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ export abstract class TaskExplorerProvider implements TaskProvider
if (uri && this.cachedTasks)
{
const rmvTasks: Task[] = [];
const folder = workspace.getWorkspaceFolder(uri);

for (const each of this.cachedTasks)
{
Expand Down
11 changes: 2 additions & 9 deletions src/test/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export async function activate(instance?: any)
{
const ext = extensions.getExtension("spmeesseman.vscode-taskexplorer")!;
assert(ext, "Could not find extension");
if (instance) instance.timeout(45 * 1000);
if (instance) instance.timeout(60 * 1000);

if (!activated)
{
Expand All @@ -96,13 +96,6 @@ export async function activate(instance?: any)
}


export async function cleanup()
{
// await configuration.update("validationDelay", docValidationDelay);
// await workspace.getConfiguration().update("extjsIntellisense.enableTaskView", taskExplorerEnabled);
}


export async function buildTree(instance: any, waitTime?: number)
{
if (!teApi || !teApi.explorerProvider) {
Expand All @@ -113,7 +106,7 @@ export async function buildTree(instance: any, waitTime?: number)
return treeItems;
}

instance.timeout(45 * 1000);
instance.timeout(60 * 1000);

if (!teApi || !teApi.explorerProvider) {
assert.fail(" ✘ Task Explorer tree instance does not exist");
Expand Down
4 changes: 2 additions & 2 deletions src/test/suite/_api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ let teApi: TaskExplorerApi;

suite("API Init and Tests", () =>
{
suiteSetup(async () =>
suiteSetup(async function()
{
teApi = await activate();
teApi = await activate(this);
assert(isReady() === true, "Setup failed");
});

Expand Down
6 changes: 3 additions & 3 deletions src/test/suite/ant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ let buildXmlFile: string;
suite("Ant Tests", () =>
{

suiteSetup(async () =>
suiteSetup(async function()
{
teApi = await activate();
teApi = await activate(this);
assert(isReady("ant") === true, "Setup failed");
provider = teApi.taskProviders.get("ant") as AntTaskProvider;
rootWorkspace = (workspace.workspaceFolders ? workspace.workspaceFolders[0]: undefined) as WorkspaceFolder;
Expand All @@ -34,7 +34,7 @@ suite("Ant Tests", () =>
});


test("Ant utility function cases", async () =>
test("Document Position", async () =>
{
// provider.readTasks();
provider.getDocumentPosition(undefined, undefined);
Expand Down
16 changes: 7 additions & 9 deletions src/test/suite/composer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ import * as fs from "fs";
import * as path from "path";
import { tasks, Uri, workspace, WorkspaceFolder } from "vscode";
import { configuration } from "../../common/configuration";
import { activate, isReady, sleep } from "../helper";
import { activate, getWsPath, isReady, sleep } from "../helper";
import { TaskExplorerApi } from "../../extension";
import { ComposerTaskProvider } from "../../providers/composer";
import { properCase } from "../../common/utils";


let teApi: TaskExplorerApi;
let rootWorkspace: WorkspaceFolder;
let pathToComposer: string;
let enableComposer: boolean;
let mainFile: Uri;
Expand All @@ -36,12 +35,11 @@ suite("Composer Tests", () =>
//
// File path for create/remove
//
rootWorkspace = (workspace.workspaceFolders ? workspace.workspaceFolders[0]: undefined) as WorkspaceFolder;
mainFile = Uri.file(path.join(rootWorkspace.uri.fsPath, "composer.json"));
mainFile = Uri.file(getWsPath("composer.json"));
//
// Store / set initial settings
//
await configuration.updateWs(`pathTo${testsNameProper}`, path.resolve(process.cwd(), "..\\..\\test-files\\ant\\bin\\ant.bat"));
await configuration.updateWs(`pathTo${testsNameProper}`, getWsPath("ant\\bin\\ant.bat"));
pathToComposer = configuration.get<string>(`pathTo${testsNameProper}`);
enableComposer = configuration.get<boolean>(`enable${testsNameProper}`);
await configuration.update(`pathTo${testsNameProper}`, "php\\composer.exe");
Expand All @@ -58,7 +56,7 @@ suite("Composer Tests", () =>
});


test("Utility function cases", async () =>
test("Document Position", async () =>
{
const provider = teApi.taskProviders.get(testsName) as ComposerTaskProvider;
// provider.readTasks();
Expand All @@ -77,7 +75,7 @@ suite("Composer Tests", () =>

test("Disable", async () =>
{
await configuration.update(`enable${testsNameProper}`, false);
await configuration.updateWs(`enable${testsNameProper}`, false);
await sleep(1750);
await teApi.explorerProvider?.invalidateTasksCache(testsName, mainFile);
await sleep(1750);
Expand All @@ -88,7 +86,7 @@ suite("Composer Tests", () =>

test("Re-enable", async () =>
{
await configuration.update(`enable${testsNameProper}`, true);
await configuration.updateWs(`enable${testsNameProper}`, true);
await sleep(500);
await teApi.explorerProvider?.invalidateTasksCache(testsName, mainFile);
const cTasks = await tasks.fetchTasks({ type: testsName });
Expand All @@ -98,7 +96,7 @@ suite("Composer Tests", () =>

test("Create File", async () =>
{
const dirName = path.join(rootWorkspace.uri.fsPath, "tasks_test_"),
const dirName = getWsPath("tasks_test_"),
file = Uri.file(path.join(dirName, "composer.json"));

if (!fs.existsSync(dirName)) {
Expand Down
4 changes: 2 additions & 2 deletions src/test/suite/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ let teApi: TaskExplorerApi;

suite("Configuration / Settings Tests", () =>
{
suiteSetup(async () =>
suiteSetup(async function()
{
teApi = await activate();
teApi = await activate(this);
assert(isReady() === true, "Setup failed");
});

Expand Down
1 change: 1 addition & 0 deletions src/test/suite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const fileToTest = "*";
// const fileToTest = "composer";
// const fileToTest = "configuration";
// const fileToTest = "providers";
// const fileToTest = "python";
// const fileToTest = "tasks";
// const fileToTest = "tree";
// const fileToTest = "util";
Expand Down
4 changes: 2 additions & 2 deletions src/test/suite/makefile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ let provider: MakeTaskProvider;
suite("Makefile Tests", () =>
{

suiteSetup(async () =>
suiteSetup(async function()
{
teApi = await activate();
teApi = await activate(this);
assert(isReady("make") === true, "Setup failed");
provider = teApi.taskProviders.get("make") as MakeTaskProvider;
});
Expand Down
12 changes: 3 additions & 9 deletions src/test/suite/providers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ suite("Provider Tests", () =>

suiteSetup(async function()
{
teApi = await activate();
teApi = await activate(this);

rootPath = workspace.workspaceFolders ? workspace.workspaceFolders[0].uri.fsPath : undefined;

Expand Down Expand Up @@ -207,12 +207,6 @@ suite("Provider Tests", () =>
if (fs.existsSync(wsDirName)) {
fs.rmdirSync(wsDirName);
}
wsDirName = path.join(rootPath, ".vscode");
if (fs.existsSync(wsDirName)) {
fs.rmdirSync(wsDirName, {
recursive: true
});
}
}
catch(error) {
console.log(error);
Expand Down Expand Up @@ -256,8 +250,8 @@ suite("Provider Tests", () =>

taskCount = findIdInTaskMap(":app-publisher:", taskMap);
console.log(" App-Publisher: " + taskCount.toString());
if (taskCount < 6) {
assert.fail("Unexpected App-Publisher task count (Found " + taskCount + " of 6)");
if (taskCount !== 42) {
assert.fail("Unexpected App-Publisher task count (Found " + taskCount + " of 42)");
}

taskCount = findIdInTaskMap(":bash:", taskMap);
Expand Down
117 changes: 117 additions & 0 deletions src/test/suite/python.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/* eslint-disable prefer-arrow/prefer-arrow-functions */
/* tslint:disable */

//
// Documentation on https://mochajs.org/ for help.
//
import * as assert from "assert";
import * as fs from "fs";
import * as path from "path";
import { tasks, Uri } from "vscode";
import { configuration } from "../../common/configuration";
import { activate, getWsPath, isReady, sleep } from "../helper";
import { TaskExplorerApi } from "../../extension";
import { ScriptTaskProvider } from "../../providers/script";
import { properCase } from "../../common/utils";


let teApi: TaskExplorerApi;
let pathToPython: string;
let enablePython: boolean;
let mainFile: Uri;


suite("Python Tests", () =>
{
const testsName = "python",
testsNameProper = properCase(testsName);

suiteSetup(async function()
{ //
// Initialize
//
teApi = await activate();
assert(isReady("script") === true, "Setup failed");
mainFile = Uri.file(getWsPath("test.py"));
//
// Store / set initial settings
//
await configuration.updateWs(`pathTo${testsNameProper}`, path.resolve(process.cwd(), "..\\..\\test-files\\ant\\bin\\ant.bat"));
pathToPython = configuration.get<string>(`pathTo${testsNameProper}`);
enablePython = configuration.get<boolean>(`enable${testsNameProper}`);
await configuration.update(`pathTo${testsNameProper}`, "php\\composer.exe");
await configuration.update(`enable${testsNameProper}`, true);
});


suiteTeardown(async() =>
{ //
// Reset settings
//
await configuration.update(`pathTo${testsNameProper}`, pathToPython);
await configuration.update(`enable${testsNameProper}`, enablePython);
});


test("Document Position", async () =>
{
const provider = teApi.taskProviders.get("script") as ScriptTaskProvider;
provider.getDocumentPosition(undefined, undefined);
provider.getDocumentPosition("test", undefined);
provider.getDocumentPosition(undefined, "test");
});


test("Disable", async () =>
{
await configuration.update(`enable${testsNameProper}`, false);
await sleep(1750);
await teApi.explorerProvider?.invalidateTasksCache(testsName, mainFile);
await sleep(1750);
// const cTasks = await tasks.fetchTasks({ type: testsName });
// assert(!cTasks || cTasks.length === 0, "Did not read 0 python tasks");
});


test("Re-enable", async () =>
{
await configuration.update(`enable${testsNameProper}`, true);
await sleep(500);
await teApi.explorerProvider?.invalidateTasksCache(testsName, mainFile);
// const cTasks = await tasks.fetchTasks({ type: testsName });
// assert(cTasks && cTasks.length === 2, "Did not read 2 python tasks");
});


test("Create File", async () =>
{
const dirName = getWsPath("tasks_test_"),
file = Uri.file(path.join(dirName, "test2.py"));

if (!fs.existsSync(dirName)) {
fs.mkdirSync(dirName, { mode: 0o777 });
}

fs.writeFileSync(
file.fsPath,
"#!/usr/local/bin/python\n" +
"\n"
);

await sleep(500);
await teApi.explorerProvider?.invalidateTasksCache(testsName, file);
// let cTasks = await tasks.fetchTasks({ type: testsName });
// assert(cTasks && cTasks.length === 2, "Did not read 2 python tasks");

fs.unlinkSync(file.fsPath);
fs.rmdirSync(dirName, {
recursive: true
});

await sleep(500);
await teApi.explorerProvider?.invalidateTasksCache(testsName, file);
// cTasks = await tasks.fetchTasks({ type: testsName });
// assert(cTasks.length === 1, "Did not read 2 python tasks");
});

});
4 changes: 2 additions & 2 deletions src/test/suite/tasks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ let taskMap: Map<string, TaskItem> = new Map();
suite("Task Tests", () =>
{

suiteSetup(async () =>
suiteSetup(async function()
{
teApi = await activate();
teApi = await activate(this);
assert(isReady() === true, "Setup failed");
rootPath = workspace.workspaceFolders ? workspace.workspaceFolders[0].uri.fsPath : undefined;
//
Expand Down
Loading

0 comments on commit b4d74c3

Please sign in to comment.