Skip to content

Commit

Permalink
Merge pull request #31 from tzAcee/test/init
Browse files Browse the repository at this point in the history
implement ui tests with vscode-extension-tester
  • Loading branch information
tzAcee authored Mar 23, 2024
2 parents b23458c + a7894e3 commit bbcf2ff
Show file tree
Hide file tree
Showing 21 changed files with 1,500 additions and 34 deletions.
13 changes: 5 additions & 8 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@
"preLaunchTask": "${defaultBuildTask}"
},
{
"name": "Extension Tests",
"type": "extensionHost",
"name": "Run Tests",
"type": "node",
"request": "launch",
"runtimeExecutable": "${execPath}",
"program": "${workspaceFolder}/node_modules/.bin/extest",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
],
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
"setup-and-run",
"out/test/ui-test/*.test.js -m ./mocharc.js"
],
"preLaunchTask": "${defaultBuildTask}"
}
Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ For file name presets:
- CLASSNAMELOWER - default classname to lower
- CLASSNAMECAPI - default classname with capitalized first letter
- CLASSNAME - default classname
- CURRENTDATETIME - current date and time
- CURRENTDATE - current date
- CURRENTTIME - current time

For file content presets:

Expand Down
5 changes: 5 additions & 0 deletions mocharc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";

module.exports = {
timeout: 60000,
};
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@
"cpp.creator.sourceFileNamePreset": {
"type": "string",
"default": "{{*CLASSNAME*}}.cpp",
"description": "Name of your source file. \nAvailable commands are:\n{{*CLASSNAME*}} - entered classname.\n{{*CLASSNAMEUPPER*}} - entered classname in upper-case letters.\n{{*CLASSNAMELOWER*}} - entered classname in lower-case letters.\n{{*CURRENTDATETIME*}} - current date and time.\n{{*CURRENTDATE*}} - current date.\n{{*CURRENTTIME*}} - current time."
"description": "Name of your source file. \nAvailable commands are:\n{{*CLASSNAME*}} - entered classname.\n{{*CLASSNAMEUPPER*}} - entered classname in upper-case letters.\n{{*CLASSNAMELOWER*}} - entered classname in lower-case letters."
},
"cpp.creator.headerFileNamePreset": {
"type": "string",
"default": "{{*CLASSNAME*}}.h",
"description": "Name of your header file. \nAvailable commands are:\n{{*CLASSNAME*}} - entered classname.\n{{*CLASSNAMEUPPER*}} - entered classname in upper-case letters.\n{{*CLASSNAMELOWER*}} - entered classname in lower-case letters.\n{{*CURRENTDATETIME*}} - current date and time.\n{{*CURRENTDATE*}} - current date.\n{{*CURRENTTIME*}} - current time."
"description": "Name of your header file. \nAvailable commands are:\n{{*CLASSNAME*}} - entered classname.\n{{*CLASSNAMEUPPER*}} - entered classname in upper-case letters.\n{{*CLASSNAMELOWER*}} - entered classname in lower-case letters."
},
"cpp.creator.createFolder": {
"type": "boolean",
Expand All @@ -98,7 +98,10 @@
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"pretest": "npm run compile",
"test": "extest setup-and-run out/test/ui-test/*.test.js"
"test": "extest setup-and-run out/test/ui-test/*.test.js -m ./mocharc.js",
"test:file-name-replacement": "extest setup-and-run out/test/ui-test/file-name-replacement.test.js -m ./mocharc.js",
"test:file-content-replacement": "extest setup-and-run out/test/ui-test/file-content-replacement.test.js -m ./mocharc.js",
"test:negative": "extest setup-and-run out/test/ui-test/negative.test.js -m ./mocharc.js"
},
"devDependencies": {
"@types/glob": "^7.1.1",
Expand Down
3 changes: 0 additions & 3 deletions src/class_creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ export class class_creator
{ reg_expression: lower_regex, replace_string: regex_commands.lower_case(this.class_name)},// CLASSNAMELOWER - default classname to lower
{ reg_expression: cap_regex, replace_string: regex_commands.capitalize(this.class_name)}, // CLASSNAMECAPI - default classname with capitalized first letter
{ reg_expression: default_regex, replace_string: regex_commands.default(this.class_name)}, // CLASSNAME - default classname
{ reg_expression: datetime_regex, replace_string: regex_commands.current_date_time()}, // CURRENTDATETIME - the current date and time
{ reg_expression: date_regex, replace_string: regex_commands.current_date()}, // CURRENTDATE - the current date
{ reg_expression: time_regex, replace_string: regex_commands.current_time()}, // CURRENTTIME - the current time
]

const content_cmds: Array<command_replace_model> = [
Expand Down
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ export async function activate(context: vscode.ExtensionContext) {
//Create the class there
if (out)
{
vscode.window.showInformationMessage('Your Class ' + res + ' has been created! \n(@'+dir_h.dir()+')');
vscode.window.showInformationMessage('Your class "' + res + '" has been created! \n(@'+dir_h.dir()+')');
}
else
{
vscode.window.showErrorMessage('Your Class ' + res + ' has been not created! \n(@'+dir_h.dir()+')');
vscode.window.showErrorMessage('Your class "' + res + '" has NOT been created! \n(@'+dir_h.dir()+')');
}
});
// Display a message box to the user
Expand Down
51 changes: 39 additions & 12 deletions src/test/ui-test/activation.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,49 @@
import { assert } from 'console';
import { VSBrowser, WebDriver } from 'vscode-extension-tester';
import { VSController } from './utils/vs-controller';
import { EditorView } from 'vscode-extension-tester';
import { CppCreatorExtHelper } from './utils/extension-helper';
import { ClassHelper } from './utils/class-helper';
import * as assert from "assert";
import * as fs from "fs";

describe('Activation test suite', () => {
let browser: VSBrowser;
let driver: WebDriver;
const workSpaceDir = "/tmp/cppWs";
let vsController = new VSController();
let cppCreatorExt = new CppCreatorExtHelper();

before(async () => {
browser = VSBrowser.instance;
driver = browser.driver;
await vsController.openWorkspace(workSpaceDir);
});

after(async ()=>{
})

it('Extension can be activated by "Alt+X"', async () => {
console.log("here2");
// Your test logic for Alt+X activation
});
await vsController.openNewEmptyEditor();

const className = "testClass";
await cppCreatorExt.openExtPromptByShortcut(className);

assert(await ClassHelper.fileExistsWithContent(className, workSpaceDir+"/"+className+".h", ClassHelper.defaultHeaderContent(className), true));
assert(await ClassHelper.fileExistsWithContent(className, workSpaceDir+"/"+className+".cpp", ClassHelper.defaultClassContent(className), true));

await new EditorView().closeAllEditors();
})

it('Extension can be activated by the context menu', async () => {
console.log("here");
// Your test logic for context menu activation
// test logic for context menu activ.

const className = "testClass";
await cppCreatorExt.openExtPromptByContextMenu(className, workSpaceDir);

assert(await ClassHelper.fileExistsWithContent(className, workSpaceDir+"/"+className+".h", ClassHelper.defaultHeaderContent(className), true));
assert(await ClassHelper.fileExistsWithContent(className, workSpaceDir+"/"+className+".cpp", ClassHelper.defaultClassContent(className), true));
})

it('Extension can be activated by the command pallette', async () => {
const className = "testClass";

await cppCreatorExt.openExtPromptByCmdPallette(className);
assert(await ClassHelper.fileExistsWithContent(className, workSpaceDir+"/"+className+".h", ClassHelper.defaultHeaderContent(className), true));
assert(await ClassHelper.fileExistsWithContent(className, workSpaceDir+"/"+className+".cpp", ClassHelper.defaultClassContent(className), true));
});
});
})
Loading

0 comments on commit bbcf2ff

Please sign in to comment.