VSCode Extension User Input Passward - input

I am trying to develop a VSCode Extension that requires user passward to run a command on the terminal. I have tried this but it throws an irrelevant error.
const readline = require('readline');
const reader = readline.createInterface({
input: process.stdin,
output: process.stdout
});
reader.question("Enter: ", passward=>{
reader.close();
});
Clearly, I am placing it wrong or something else because it runs fine in an individual node js file. I am placing it inside of registercommand

If by run a command in the Terminal you mean that some command should be displayed/added in VS Code terminal, then you should look at the Terminal API in VS Code.
There is a sample in https://github.com/microsoft/vscode-extension-samples/tree/main/terminal-sample, and it will probably help you better understand how to integrate with VS Code terminal.
Hope this helps

Related

Execute script which comes from vscode Extension

When developing a vscode Extension is it possible to have separate bash scripts inside the code of the Extension which can be executed in the vscode instance where the extension is installed?
Imagine i have .sh scripts beside my extension.ts. When Running the extension i want to be able to open a Terminal per script and execute the scripts.
I can‘t find a way to achieve this
Edit:
My folder structure in the extension repo looks like:
scripts/*.sh (multiple scripts)
extension.ts
The code I tried:
let startRuntime = vscode.commands.registerCommand('test.startRuntime', () => {
const scriptsPath = path.join(__filename, '..', 'scripts');
const scriptsDir = fs.readdirSync(scriptsPath);
scriptsDir.forEach((script) => {
const terminal = vscode.window.createTerminal(`${script}`);
terminal.show();
terminal.sendText(`./${script}`);
});
});
After running the extension a new VSCode instance starts and I want to execute the command. It actually starts as many terminals as i have scripts but in that instance on the terminals i get:
zsh: no such file or directory: ./test.sh
How do e.g other users who use the extension get access to those scripts.
Thank you in advance!

The system cannot find the path specified, but then displays result

I'm trying to learn about gherkin, cucumber, npm in vscode.
I'm getting the usual "The system cannot find the path specified" error message, but then the result is shown as normal underneath.
C:\projects\vscode1>npm --version
The system cannot find the path specified.
7.11.2
It also does not recognize paths with "." in them, so "C:\projects\vscode1>./node_modules/.bin/cucumber-js" shows a different error.
C:\projects\vscode1>./node_modules/.bin/cucumber-js
'.' is not recognized as an internal or external command,
operable program or batch file.
The folder definitely exists inside node_modules as .bin.
During npm installation the cmd for the extra components, where it installs chocolatey etc, would not complete so I'm not sure if this is related. I have done a repair on the installer but it did not fix the problem.
UPDATED
I can run it in CMD without this .bin problem, but there is no output. The code I'm trying to run is:
const { Given } = require("#cucumber/cucumber")
//const (Given) = require('cucumber')
Given('a user opens {string}', (url) => {
console.log(url)
})
vscode.feature
Feature: vscode feature
Feature Description
Scenario: Scenario name
Given a user opens "https://www.duckduckgo.com/"
The tutorial can be found at: https://www.youtube.com/watch?v=bsGr6xjZ0mY

node js cli STDOUT STDERR output exec and spawn commands

I am looking for a clear answer on how the stdout and stderr work when developing a npm cli module.
I would like to print out everything exactly as it is when I run command with child_process.spawn.
I managed to output the git clone command with the --progress options. Now I want to output the npm install command but it is printing only the final string.
Would be nice to have a clear answer on how this work in general and what are the best practices.
This works:
import * as cp from 'child_process';
const child = cp.spawn('git', ['clone', 'ssh://myrepo...', '--progress']);
child.stdout.setEncoding('utf8');
child.stdout.on('data', (chunk) => {
process.stdout.write(`${chunk}`);
});
child.stderr.setEncoding('utf8');
child.stderr.on('data', (chunk) => {
process.stdout.write(`${chunk}`);
});
// BTW why git is outputing in STDERR and not in STDOUT?
However this doesn't work
const child = cp.spawn('npm', ['i', 'mymodule']);
Is there a way to make this work for each command?
You can leave off the event handlers and encoding settings and tell spawn() to pass stdio through to the parent process.
const child = cp.spawn('npm', ['i', 'mymodule'], {stdio: 'inherit'});
Both of your commands work for me as long as the listeners are added as in your first example. Your second example only stops working for me if I leave out the event handlers. It would be interesting to know what platform you are running on, what versions of node and npm you are using, and a complete not-working example that can be cut and paste into a file for testing. (Also, what is the name of the file? Are you using .mjs extension or something else to make import work? Is this file in a module loaded elsewhere or in the base level script?)

Driving Nightwatch Tests through REPL

I currently have nightwatch.js setup using the vue automated setup. That template is located here.
https://github.com/vuejs-templates/webpack/tree/master/template/test/e2e
Is it possible to run nightwatch assertions through the command line in a REPL like fashion that is available in webdriver.io? Here is a reference to the webdriver feature https://twitter.com/webdriverio/status/806911722682544128
Update, we have moved to using Cypress.io It has made us pretty happy
You can use nightwatch-repl package available on NPM.
https://www.npmjs.com/package/nightwatch-repl
// nightwatch.conf.js
var repl = require('nightwatch-repl');
module.exports = (function (settings) {
repl.init(settings);
...
...
return settings;
})(require('./nightwatch.json'));
Once you run your tests and invoke browser.repl()
you should see the following in your console
Running: Login to dashboard
Type in a command (eg: browser.function()) or type "quit" to exit
repl>

I am getting a "Bad response from Chimp Server" in my console when trying to run a meteor app with velocity/cucumber testing on it

The error is not in my regular console, it's in my tail -f console. It won't run the tests at all. In my localhost:3000 velocity sidebar it also says chimp server error. I am not sure how to fix this, I am very new to velocity and cucumber so it could be a stupid mistake, but I couldn't find any information on this error anywhere.
could you provide us with the whole meteor log and also cucumber log? If possible - please do meteor reset first (be aware though that this will clean up your local mongodb, if you want to avoid that, at least clean the cucumber log - echo '' > filePath will work )
I ran into the same problem yesterday while trying to follow Josh Owen's now outdated cucumber tutorial. The error was coming from with the step definition file while not wrapping module.exports in a function like this:
(function() {
module.exports = function() {
// ...
}
});
It could also be that your test directory and files aren't structured correctly in your app.
It should look like this:
app/
tests/
cucumber/
features/
step_definitions/
my_steps.js
my_feature.feature
fixtures/
my_fixture.js
Let me know if that makes a difference. Also, this is a good place to start with velocity/cucumber: http://www.mhurwi.com/a-basic-cucumber-meteor-tutorial/
It's very basic but there isn't much out there for learning testing with Meteor.