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

feat: support to run API Testing task via grpc #41

Merged
merged 5 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
52 changes: 51 additions & 1 deletion plugins/vscode/yaml-readme/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ const cp = require('child_process');
const fs = require('fs');
const cmd = require('./command');

const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const PROTO_PATH = __dirname +'/server.proto';
const packageDefinition = protoLoader.loadSync(
PROTO_PATH, {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
});

const serverProto = grpc.loadPackageDefinition(packageDefinition).server;

const apiConsole = vscode.window.createOutputChannel("API Testing")

function getFirstLine(filePath) {
const data = fs.readFileSync(filePath);
return data.toString().split('\n')[0];
Expand Down Expand Up @@ -49,8 +65,42 @@ function activate(context) {
vscode.window.showErrorMessage(message);
}
});
let atest = vscode.commands.registerCommand('atest', function() {
if(vscode.workspace.workspaceFolders !== undefined) {
let filename = vscode.window.activeTextEditor.document.fileName
const addr = vscode.workspace.getConfiguration().get('yaml-readme.server')
apiConsole.show()
let task

let editor = vscode.window.activeTextEditor
if (editor) {
let selection = editor.selection
let text = editor.document.getText(selection)
if (text !== undefined && text !== '') {
task = text
}
}

if (task === undefined || task === '') {
const data = fs.readFileSync(filename);
task = data.toString()
}

const client = new serverProto.Runner(addr, grpc.credentials.createInsecure());
client.run({
kind: "suite",
data: task
} , function(err, response) {
apiConsole.appendLine(response.message);
});
} else {
let message = "YOUR-EXTENSION: Working folder not found, open a folder an try again" ;

vscode.window.showErrorMessage(message);
}
})

context.subscriptions.push(disposable);
context.subscriptions.push(disposable,atest);
}

// this method is called when your extension is deactivated
Expand Down
Loading