-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi-testing-mock.js
42 lines (36 loc) · 1.01 KB
/
api-testing-mock.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
const vscode = require('vscode');
const fs = require('fs');
const codeLense = (document, token) => {
const range = new vscode.Range(0, 1, 10, 10)
const lens = new vscode.CodeLens(range, {
command: 'atest.startMock',
title: 'Start Mock Server'
})
return [lens]
}
const terminalName = 'atest mock'
const startMock = (filename) => {
let arg = ''
const data = fs.readFileSync(filename);
data.toString().split('\n').forEach(function(line) {
// find the argument line which start with #!arg and get the argument
if (line.startsWith("#!arg")) {
arg = line.substring(5)
return
}
});
let terminal
vscode.window.terminals.forEach(t => {
if (t.name === terminalName) {
terminal = t
}
})
if (!terminal) {
terminal = vscode.window.createTerminal({name:terminalName})
}
terminal.show()
terminal.sendText(`atest mock ${filename} ${arg}`)
}
module.exports = {
codeLense, startMock
};