Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement ui tests with vscode-extension-tester #31

Merged
merged 36 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b8aa573
add basic test
tzAcee Mar 21, 2024
66225a5
implement activiation tests
tzAcee Mar 21, 2024
df3219a
define file-creation tests
tzAcee Mar 21, 2024
d5b606d
wait until file content not empty
tzAcee Mar 21, 2024
e107565
implement creation tests
tzAcee Mar 21, 2024
ac4fc0e
test
tzAcee Mar 21, 2024
f4b62b5
test
maxl-siemens Mar 22, 2024
37a23ac
add logs
maxl-siemens Mar 22, 2024
6a10841
comment all tests out
maxl-siemens Mar 22, 2024
f195de0
remove crhome driver
maxl-siemens Mar 22, 2024
86577d1
more logs
maxl-siemens Mar 22, 2024
2cdb3c1
test
maxl-siemens Mar 22, 2024
96415ad
test
maxl-siemens Mar 22, 2024
7210ec5
take screen
maxl-siemens Mar 22, 2024
0e6a61c
test
maxl-siemens Mar 22, 2024
d4a9314
test
maxl-siemens Mar 22, 2024
8d537ab
test
maxl-siemens Mar 22, 2024
5c5d671
remove console logs
maxl-siemens Mar 22, 2024
95836f0
enable all tests again
maxl-siemens Mar 22, 2024
ff73be0
define invalid test-cases
maxl-siemens Mar 22, 2024
80fd295
test
maxl-siemens Mar 22, 2024
386bef1
test
maxl-siemens Mar 22, 2024
1b6707a
test
maxl-siemens Mar 22, 2024
5c5d20c
test
maxl-siemens Mar 22, 2024
c9316e9
test again
maxl-siemens Mar 22, 2024
cb6baad
test
maxl-siemens Mar 22, 2024
16aca2f
define all missing test cases
maxl-siemens Mar 22, 2024
00790e3
try on build agent
tzAcee Mar 22, 2024
5d35c73
try on agent
tzAcee Mar 22, 2024
d9c2608
test with first test-case
tzAcee Mar 22, 2024
d45ead8
implement first test cases
tzAcee Mar 22, 2024
c7d0fd0
remove date commands from file-name presets
tzAcee Mar 23, 2024
e04246b
finish replacement tests
tzAcee Mar 23, 2024
a8df103
await notification
tzAcee Mar 23, 2024
54f2b87
check notifs before
tzAcee Mar 23, 2024
a7894e3
implement negative tests
tzAcee Mar 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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