Skip to content

Commit 9013807

Browse files
authored
generate mock sample (#10)
* generate mock sample * add mock sample cmd into the context menu --------- Co-authored-by: rick <[email protected]>
1 parent f3247a0 commit 9013807

File tree

4 files changed

+77
-5
lines changed

4 files changed

+77
-5
lines changed

dist/extension.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47079,13 +47079,22 @@ function activate(context) {
4707947079
}
4708047080
});
4708147081
});
47082+
let atestMockSample = vscode.commands.registerCommand("atest.sampleMock", function(args) {
47083+
const wsedit = new vscode.WorkspaceEdit();
47084+
const wsPath = vscode.workspace.workspaceFolders[0].uri.fsPath;
47085+
const filePath = vscode.Uri.file(wsPath + "/mock.yaml");
47086+
wsedit.createFile(filePath, { ignoreIfExists: true });
47087+
wsedit.insert(filePath, new vscode.Position(0, 0), mockSample);
47088+
vscode.workspace.applyEdit(wsedit);
47089+
vscode.workspace.openTextDocument(filePath);
47090+
});
4708247091
let startMockServerCommand = vscode.commands.registerCommand("atest.startMock", function(args) {
4708347092
if (vscode.workspace.workspaceFolders !== void 0) {
4708447093
let filename = vscode.window.activeTextEditor.document.fileName;
4708547094
atestCodeLenseMock.startMock(filename);
4708647095
}
4708747096
});
47088-
context.subscriptions.push(atest, atestRunWith, atestSample, startMockServerCommand);
47097+
context.subscriptions.push(atest, atestRunWith, atestSample, atestMockSample, startMockServerCommand);
4708947098
var which = require_lib4();
4709047099
which("atest", { nothrow: true }).then((p) => {
4709147100
if (p) {
@@ -47170,6 +47179,27 @@ function startAtestServer() {
4717047179
var defaultEnv = `- name: localhost
4717147180
env:
4717247181
SERVER: http://localhost:7070`;
47182+
var mockSample = `#!api-testing-mock
47183+
#!arg --prefix /
47184+
# yaml-language-server: $schema=https://linuxsuren.github.io/api-testing/api-testing-mock-schema.json
47185+
objects:
47186+
- name: reports
47187+
sample: |
47188+
{
47189+
"name": "api-testing",
47190+
"remark": "",
47191+
"taskID": "",
47192+
"failedCount": 1,
47193+
"color": "{{ randEnum "blue" "read" "pink" }}"
47194+
}
47195+
items:
47196+
- name: base64
47197+
request:
47198+
path: /v1/base64
47199+
response:
47200+
body: aGVsbG8=
47201+
encoder: base64
47202+
`;
4717347203
function deactivate() {
4717447204
}
4717547205
module.exports = {

extension.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,25 @@ function activate(context) {
187187
});
188188
})
189189

190+
let atestMockSample = vscode.commands.registerCommand('atest.sampleMock', function(args) {
191+
const wsedit = new vscode.WorkspaceEdit();
192+
const wsPath = vscode.workspace.workspaceFolders[0].uri.fsPath;
193+
const filePath = vscode.Uri.file(wsPath + '/mock.yaml');
194+
wsedit.createFile(filePath, { ignoreIfExists: true });
195+
wsedit.insert(filePath, new vscode.Position(0, 0), mockSample);
196+
vscode.workspace.applyEdit(wsedit);
197+
198+
vscode.workspace.openTextDocument(filePath);
199+
})
200+
190201
let startMockServerCommand = vscode.commands.registerCommand('atest.startMock', function(args) {
191202
if(vscode.workspace.workspaceFolders !== undefined) {
192203
let filename = vscode.window.activeTextEditor.document.fileName
193204
atestCodeLenseMock.startMock(filename)
194205
}
195206
})
196207

197-
context.subscriptions.push(atest, atestRunWith, atestSample, startMockServerCommand);
208+
context.subscriptions.push(atest, atestRunWith, atestSample, atestMockSample, startMockServerCommand);
198209

199210
var which = require('which')
200211
which('atest', { nothrow: true }).then((p) => {
@@ -289,6 +300,28 @@ const defaultEnv = `- name: localhost
289300
env:
290301
SERVER: http://localhost:7070`
291302

303+
const mockSample = `#!api-testing-mock
304+
#!arg --prefix /
305+
# yaml-language-server: $schema=https://linuxsuren.github.io/api-testing/api-testing-mock-schema.json
306+
objects:
307+
- name: reports
308+
sample: |
309+
{
310+
"name": "api-testing",
311+
"remark": "",
312+
"taskID": "",
313+
"failedCount": 1,
314+
"color": "{{ randEnum "blue" "read" "pink" }}"
315+
}
316+
items:
317+
- name: base64
318+
request:
319+
path: /v1/base64
320+
response:
321+
body: aGVsbG8=
322+
encoder: base64
323+
`
324+
292325
// this method is called when your extension is deactivated
293326
function deactivate() {}
294327

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "api-testing",
33
"displayName": "API Testing",
44
"description": "YAML based API Testing",
5-
"version": "0.0.16",
5+
"version": "0.0.18",
66
"repository": "https://github.com/linuxsuren/vscode-api-testing",
77
"engines": {
88
"vscode": "^1.68.0"
@@ -31,6 +31,11 @@
3131
"title": "API Testing Sample",
3232
"description": "Generate an API Testing sample YAML file."
3333
},
34+
{
35+
"command": "atest.sampleMock",
36+
"title": "API Testing Mock Sample",
37+
"description": "Generate a sample mock YAML file."
38+
},
3439
{
3540
"command": "atest.startMock",
3641
"title": "Start API Testing Mock Server"
@@ -68,6 +73,10 @@
6873
{
6974
"group": "1_run",
7075
"command": "atest.sample"
76+
},
77+
{
78+
"group": "1_run",
79+
"command": "atest.sampleMock"
7180
}
7281
],
7382
"editor/context": [

0 commit comments

Comments
 (0)