forked from finalcut/vscode-mxunitrunner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.js
85 lines (64 loc) · 2.58 KB
/
extension.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
let vscode = require('vscode');
let path = require('path');
let open = require('open');
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
function activate(context) {
let disposable = vscode.commands.registerCommand('extension.mxunit', function() {
let editor = vscode.window.activeTextEditor;
let config = vscode.workspace.getConfiguration('mxunit');
if(config){
if(!editor){
vscode.window.showWarningMessage('No Active MxUnit Test File!');
}
const ext = path.extname(editor.document.fileName);
const fullPath = editor.document.uri.fsPath;
if (/^\.(cfc)$/.test(ext)) {
let baseUrl = config.baseUrl;
let projectRoot = vscode.workspace.rootPath;
let relPath = replaceAll(fullPath,projectRoot,'/');
relPath = replaceAll(relPath,'\\','/');
let testName = getSelectedText(editor);
if(testName.length){
testName = '&testMethod=' + testName
}
let fullURL = baseUrl + relPath + '?method=runtestremote&output=html' + testName;
try {
open(decodeURIComponent(fullURL));
}
catch (error) {
vscode.window.showInformationMessage('Couldn\'t open test.');
console.error(error.stack);
}
} else {
vscode.window.showInformationMessage('Suppoorts cfc files only!');
}
} else {
vscode.window.showInformationMessage('Your Project needs to define mxunit settings!');
}
});
context.subscriptions.push(disposable);
}
exports.activate = activate;
// this method is called when your extension is deactivated
function deactivate() {
}
exports.deactivate = deactivate;
function getSelectedText(textEditor) {
return textEditor.document.getText(getSelectionRange(textEditor));
}
function getSelectionRange(textEditor) {
let
selection = textEditor.selection,
start = selection.start,
end = selection.end;
return new vscode.Range(start, end);
}
function escapeRegExp(str) {
return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
}
function replaceAll(str, find, replace) {
return str.replace(new RegExp(escapeRegExp(find), 'g'), replace);
}