How to bundle tests and start karma from watch task - node.js

Whenever the appropriate files change I would like to bundle my tests and start karma, showing any failed tests.
I currently have the watch task:
gulp.task('default', ['browserify', 'css','runTests'], function () {
gulp.watch('./src/js/**/*.js', ['browserify']);
gulp.watch('./src/js/**/*.js', ['runTests']);
});
Which starts up the runTests.js
var testFile = [
'./src/components/tests/suite.js'
];
// bundle tests
var cmd = child.spawn('browserify', ['-e', './src/components/tests/suite.js', '-t', 'reactify', '-t']);
cmd.on('close', function (code) {
//cmd finished start karma
gulp.src(testFiles)
.pipe(karma({
configFile: 'karma.conf.js',
action: 'run'
}))
.on('error', function(err) {
throw err;
});
});
my console currently errors here:
[17:04:27] Starting 'runTests'...
[17:04:27] Finished 'runTests' after 2.73 ms
events.js:85
throw er; // Unhandled 'error' event
^
Error: spawn browserify ENOENT
at exports._errnoException (util.js:746:11)
at Process.ChildProcess._handle.onexit (child_process.js:1053:32)
at child_process.js:1144:20
at process._tickCallback (node.js:355:11)
at Function.Module.runMain (module.js:503:11)
at startup (node.js:129:16)
at node.js:814:3
Process finished with exit code 1
I can get a basic command to work child = spawn("ls");
But not the browserify command, can anyone help?

You can use the browserify API within a gulp task. Look at substack/node-browserify#1170 for some tips on globbing with browserify. Then you can just include the output file in your karam config files array.
// Disclaimer: This code is untested
var files = require("glob").sync('./src/js/**/*.js');
files.push('./src/components/tests/suite.js');
var browserify = require("browserify")(files, {transform: 'reactify'});
// your can do more config on the browserify instance
// Run browserify bundle and output to a file
var myFile = require('fs').createWriteStream('myOutput.txt');
browserify.bundle().pipe(myFile);

Related

Impossible to install spookyjs

I want to install spookyjs and find it impossible to do so. I've tried three different ways:
Run the standard spookyjs package.json provided in spookyjs github.
Then I try to run hello.js and I am greeted with this error.
C:\Users\User1\Desktop\test2>node hello.js
events.js:183
throw er; // Unhandled 'error' event
^
Error: spawn casperjs ENOENT
at _errnoException (util.js:1022:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
at onErrorNT (internal/child_process.js:372:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
at Function.Module.runMain (module.js:695:11)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3
Installed phantomjs and casperjs globally and package.json installed spooky and tiny-jsonrpc. I get the same error message.
Installed these dependencies from package.json
"dependencies": {
"spooky": "^0.2.5",
"tiny-jsonrpc": "^2.0.1",
"phantom": "^4.0.12",
"casperjs": "^1.1.4"
I get the same error.
I came across this link:
Issue
and it detailed the solution. That is this chunk of code:
const
path = require('path'),
_ = require('underscore')
;
var
// close env to pass to spawn
env = _.clone(process.env),
// get the PATH - in my local Windows, it was Path
envPath = env.PATH || env.Path,
// get path to node_modules folder where casperjs and
// phantomjs-prebuilt are installed
// this will be different for you
binDir = path.join(__dirname, './../../node_modules/.bin'),
Spooky = require('spooky')
;
// update the path in the cloned env
env.PATH = env.Path = `${envPath};${binDir}`;
var spooky = new Spooky({
child: {
// spooky is trying to call casperjs.bat for windows
// .bat doesn't work, so call the update .cmd file
// this fixes issue 2 with the file
command: /^win/.test(process.platform) ? 'casperjs.cmd' : 'casperjs',
transport: 'http' ,
spawnOptions: {
// set the env using cloned version
// this fixes issue 1 with the path
env: env
}
},
...
So now the program runs without an error. Actually though it runs without anything, because while on the one hand no error pops up, on the other nothing pops up. I debbuged by putting console.log() inside spooky's callback function but nothing is displayed. That is for another question though...
But the error i was receiving has vanished and the interpreter runs the code.

"Error: spawn /usr/bin/compass ENOENT" when using gulp-compass

I'm attempting to run the following Gulp task to compile Sass files, using the plugin, gulp-compass on OS X Yosemite 10.5.5.
var path = require("path");
var gulp = require("gulp");
var compass = require("gulp-compass");
gulp.task("compile2013Base", function() {
var projectPath = path.join(__dirname, '../../ ');
gulp.src(['../sass/desktop/css/2013/*.scss']).pipe(compass({
project: projectPath,
css: 'htdocs/assets/css/2013/',
sass: 'sass/desktop/css/2013'
})).on('error', errorHandler).pipe(gulp.dest('../../htdocs/assets/css/2013/'));
});
function errorHandler (error) {
console.log(error.toString());
this.emit('end');
}
However, when I try to run the task like gulp compile2013Base, I get the following error:
> gulp compile2013Base
[13:39:06] Using gulpfile [**redacted**]/scripts/js/gulpfile.js
[13:39:06] Starting 'compile2013Base'...
[13:39:06] Finished 'compile2013Base' after 9.07 ms
events.js:85
throw er; // Unhandled 'error' event
^
Error: spawn /usr/bin/compass ENOENT
at exports._errnoException (util.js:746:11)
at Process.ChildProcess._handle.onexit (child_process.js:1053:32)
at child_process.js:1144:20
at process._tickCallback (node.js:355:11)
I already have compass installed at /usr/bin/compass, and running compass in the terminal does not show any errors.
I'm not sure what to go on here, how do I get the error details?
This is helped me
sudo gem install -n /usr/local/bin compass
see Error: "compass:dist" Fatal error: spawn /usr/bin/compass ENOENT

Gulp Error: ENOENT, lstat while running tasks

I am using gulp to copy and clean my front-end projects. I want to run some sequential tasks. It means, for example, I want the copy task to be started and finished and then run its the following task (a copy task).
I frequently see this error when I run my tasks:
events.js:72
throw er; // Unhandled 'error' event
^
Error: ENOENT, lstat '/home/reza/projects/account-web/dist/views'
After lstat, each I see a file name randomly. I just find that when there is no dist folder or it is empty copy tasks run properly but when the dist folder is not empty even clean task throws and error.
There are my gulp file and command results below:
var gulp = require('gulp');
var clean = require('gulp-clean');
var merge = require('gulp-merge');
var runSequence = require('run-sequence');
gulp.task('clean', function () {
gulp.src('./dist/**').pipe(clean());
});
gulp.task('copy-js', function () {
return gulp.src('app/js/**').pipe(gulp.dest('dist/js/'));
});
gulp.task('copy-bower', function () {
return gulp.src('bower_components/**').pipe(gulp.dest('dist/bower_components/'));
});
gulp.task('copy-script', function () {
return gulp.src('app/scripts/**').pipe(gulp.dest('dist/scripts/'));
});
gulp.task('copy-styles', function () {
var stream1 = gulp.src('app/styles/**').pipe(gulp.dest('dist/styles/'));
var stream2 = gulp.src('app/fonts/**').pipe(gulp.dest('dist/fonts/'));
var stream3 = gulp.src('app/img/**').pipe(gulp.dest('dist/img/'));
return merge(stream1, stream2, stream3);
});
gulp.task('copy-views', function () {
var stream1 = gulp.src('app/views/**').pipe(gulp.dest('dist/views/'));
var stream2 = gulp.src('app/*').pipe(gulp.dest('dist/'));
return merge(stream1, stream2);
});
gulp.task('dist', function () {
runSequence(['copy-bower','copy-js', 'copy-script', 'copy-styles', 'copy-views']);//
});
gulp.task('dev', function () {
runSequence('clean', 'dist')
});
gulp.task('default', ['dev']);
I thought that there is concurrency problem and the tasks are not running really sequentially, so I tries some modules to solve this problem like runSequence.
➜ account-web git:(master) ✗ gulp clean
[14:20:55] Using gulpfile ~/projects/account-web/Gulpfile.js
[14:20:55] Starting 'clean'...
[14:20:55] Finished 'clean' after 5.58 ms
events.js:72
throw er; // Unhandled 'error' event
^
Error: ENOENT, lstat '/home/reza/projects/account-web/dist/views'
➜ account-web git:(master) ✗ gulp dev
[14:35:03] Using gulpfile ~/projects/account-web/Gulpfile.js
[14:35:03] Starting 'dev'...
[14:35:03] Starting 'clean'...
[14:35:03] Finished 'clean' after 5.47 ms
[14:35:03] Starting 'dist'...
[14:35:03] Starting 'copy-bower'...
[14:35:03] Starting 'copy-js'...
[14:35:03] Starting 'copy-script'...
[14:35:03] Starting 'copy-styles'...
[14:35:03] Starting 'copy-views'...
[14:35:03] Finished 'dist' after 14 ms
[14:35:03] Finished 'dev' after 22 ms
stream.js:94
throw er; // Unhandled stream error in pipe.
^
Error: ENOENT, open '/home/reza/projects/account- web/dist/styles/fonts.css'
I wonder if it's attempting to asynchronously delete a file within a nested folder after the nested folder has already been deleted. Try changing your src to include the dist folder without the wildcards. This will tell it to delete the dist folder instead of each item independently.
gulp.task('clean', function () {
gulp.src('./dist').pipe(clean());
});
It also appears that gulp-clean has been deprecated, you may want to checkout del as a replacement. It is able to handle your original glob pattern correctly.

node errors when running gulp del task

I cannot figure out why I am getting a node ENOENT error, when running a simple task to clean out my vendor files.
My gulp task looks like this
var gulp = require('gulp');
var del = require('del');
module.exports = function(opt){
gulp.task('clean:vendor', function(cb){
return del(['src/vendor/'],cb)
});
}
When I run the command gulp clean:vendor against a file structure that looks like this:
gulpfile.js
src/vendor/js
src/vendor/css
I get this error from node, and I cannot figure out how to catch or fix.
events.js:72
throw er; // Unhandled 'error' event
^
Error: ENOENT, open '/Users/aycollin/seed/src/vendor/js/bootstrap.js'

Node.js run a java program?

I have a simple nodejs server up and running. I am running into trouble when I try to spawn a child process. the jar file I am trying to access, is in the same directory as the node script. It takes in a command line argument that I am trying to pass in and it outputs data to the command line, which I am trying to pipe into the var child.
var child = require('child_process').spawn('java -jar done.jar',['argument to pass in']);
child.stdout.on('data', function(data) {
console.log(data.toString());
});
child.stderr.on("data", function (data) {
console.log(data.toString());
});
This produces the following error message:
events.js:85
throw er; // Unhandled 'error' event
^
Error: spawn java -jar done.jar ENOENT
at exports._errnoException (util.js:746:11)
at Process.ChildProcess._handle.onexit (child_process.js:1046:32)
at child_process.js:1137:20
at process._tickCallback (node.js:355:11)
Any ideas?
You're executing java. -jar and done.jar are arguments to pass.
var child = require('child_process').spawn(
'java', ['-jar', 'done.jar', 'argument to pass in']
);
You will also need to specify the full path to java, or make sure that java is specified in the OS path.

Resources