Is it possible run a plugin as a test? - javascript

I'm working with HTMLhint but it just run with the command line is a plugin, I want this action to run like a test. Is it possible do it and how? I was googling but I don't find a way to do that.

Do you mean you'd like it to run every time you push code? Or, would you like it to run locally in your editor every time you save/as you type?
Every time you push code: look into TravisCI or another type of continuous integration. These services can run items on your code, including linters, each time you push new commits.
Every time you save/as you type: this depends on what your editor requires to run the lint. For example, Sublime Text has Sublime Linter which can automatically run any type of linter after installation of the corresponding package.

Related

Can't seem to run selective chunk of Javascript code in VS code

So I am new to Javascript and trying to learn on VS Code. I can't seem to find a functionality to execute only a selected block of code. Every time I click F5 or (or Ctrl + F5), it runs the entire file.
Is it possible or do I need to install something extra to do this?

Kubernetes : Pause main script while keeping pod alive

I'm using Kubernete to run a node script in a permanent loop. When the pod is created, it runs "npm start" which start the script with default parameters in loop mode.
It works perfectly for that.
I also sometimes need to run some node commands in the pod.
(eg: node dist/index run --parameter=xyz)
For that I use kubectl :
kubectl exec -it PODNAME NAMESPACE --
/bin/ash
It allows me to run the script with other parameters as I wish BUT
I don't find a way to put the main process ('npm start') on hold while I run my others commands.
I want the loop to be paused while I execute those node commands (They can't run in parallel). I tried to kill the main processed which are shown by typing "ps -aef" but it doesn't work. It either restart automatically (restartPolicy: Always) or it make the pods go in error and I can't type my node commands.
Any idea on how to achieve this ?
What you could do is send a signal to the main process, SIGUSR2 is meant for this kind of purpose. You can catch the signal with an event handler and set a variable, then let your normal code check the variable at intervals or at set points in the code to judge wether it should do stuff.
On the CLI side of issuing the pause you can simply use the kill command to send the signal to the process.
See also:
https://nodejs.org/api/process.html#process_signal_events
http://man7.org/linux/man-pages/man7/signal.7.html
how to use kill SIGUSR2 in bash?
But, maybe you shouldn't try to pause a pod, simply gracefully let it shut down, and pick up remaining workloads later, in a new pod? Would probably be a cleaner way to go about it, but depends on what you're trying to achieve ofcourse.

How to implement centralised test execution control of NightWatch.js tests?

We are using Grunt to kick off NightWatch.js tests.
There are like 30-40 tests and this number will grow a lot more.
For now, I am aware of only two reasonable ways to choose which tests get run and they are both manual:
1. Remove all tests that shouldn't be run from source folder
2. Comment/UnComment the '#disabled': true, annotation
I was thinking that a properly structured way of choosing which tests get run would be to have a certain file, say, "testPlan.txt" like this:
test1 run
test2 not
test3 run
And then the test could have some code, instead of the current annotation, such as this (sorry, my JS is non-existent):
if (checkTestEnabled()) then ('#disabled': true) else (//'#disabled': true)
You can use tags to group your tests into categories and then pick and choose which tests to run based on the flag you pass in. For example, if I wanted to create a smoke test suite I would just add '#tags': ['smokeTests'] at the top of each file that would be included in that suite and then you can run them using the command:
nightwatch --tag smokeTests
You can also add multiple tags to each test if you need to group them in additional categories. '#tags': ['smokeTests', 'login']
You should be able to use this the same way you are doing it in your grunt tasks. Read here for more details.

using command line in javascript

I know there are lots of questions about this already, but i cant seem to find one that works for me.
I am trying to launch a local file from a local html using cmd to pass command to launch file but it does not seem to work.
This is what i used so far:
<script type="text/javascript" language="javascript">
function RunFile() {
window.open('C:/Windows/System32/cmd.exe /c START %temp%/file.cpl');
}
</script>
someone pls help with this.
Lets just asume i can do this on IE window.open('C:/Windows/System32/cmd.exe); and it will open cmd.
My question is how do i pass some extra argument to make the cmd open my file from another location e.g. window.open('C:/Windows/System32/cmd.exe /c START %temp%/file.cpl');
You cannot run a program using a browser. You might be confused with Windows Scripting JScript, check: https://en.wikipedia.org/wiki/JScript
You may run apps using that (in windows shell). Check this: https://stackoverflow.com/a/15351708/1082061
You could do this using server-side binary execution on Nodejs using child_process.
Pro: Easy to use, just need a simple AJAX call to trigger execution from client to Node server.
Cons: Need to use a server instead of a single HTML page.

A bash script that will start when the EC2 instance is turned on

I have a EC2 instance, and I would like to write a script (never done them before) so that every time I start my E2 instance in the AWS console, the following files are run automatically.
Lets say I have a file called example.js which contains this:
var test(){
console.log('hello world');
}
test()
And then I have a similar file called example2.js
Everytime I run my EC2 instance, I need to ssh into it and do node example.js and node example2.js in order to run the functions.
However, I would like to write a startup script so that when the EC2 instance state is turned to running (i.e. online), I would like the command node example.js and node example2.js executed by themselves.
Is this possible? If yes, where do I put this script?
I have a Centos image running on my EC2 instance, and the EC2 instance is turned off at night, and turned back on in the morning - hence the script will simplify things!
I read this link, however cannot quite figure it out in my case: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html
Any help will be appreciated. Thanks
use pm2. It's an excellent solution for managing node processes. Also can start the processes when you boot the machine.
ref: http://pm2.keymetrics.io/docs/usage/startup/
here is another good tutorials: https://futurestud.io/tutorials/pm2-restart-processes-after-system-reboot
Specific to EC2, you can use the 'User Data' option, available when you create your instance. It takes a script as input that will be executed at launch.
Here's how it looks like :
To add user data to your instance, wait until the night so you don't disrupt yor apps, then right click on it and do "Create Image".
Once the image is created, you can use it to spawn a "new" instance, with user data, and delete the old one without losing anything. Don't forget to reassign the elastic IP of the old instance :)
More information/documentation on aws.amazon.com

Categories