Catch Errors in Protractor Runner - node.js

Is there a way to catch specific errors thrown directly by protractor's runner? For example, one uncaught exception is:
WARNING - pattern /var/www/smoran/repo/app/partials/app/app.controller.e2e.js did not match any files.
[launcher] Process exited with error code 1
/var/www/smoran/repo/node_modules/protractor/node_modules/q/q.js:126
throw e;
^
Error: Spec patterns did not match any files.
at Runner.run (/var/www/smoran/repo/node_modules/protractor/lib/runner.js:249:11)
at TaskRunner.run (/var/www/smoran/repo/node_modules/protractor/lib/taskRunner.js:123:19)
at createNextTaskRunner (/var/www/smoran/repo/node_modules/protractor/lib/launcher.js:220:20)
at /var/www/smoran/repo/node_modules/protractor/lib/launcher.js:243:7
at _fulfilled (/var/www/smoran/repo/node_modules/protractor/node_modules/q/q.js:797:54)
at self.promiseDispatch.done (/var/www/smoran/repo/node_modules/protractor/node_modules/q/q.js:826:30)
at Promise.promise.promiseDispatch (/var/www/smoran/repo/node_modules/protractor/node_modules/q/q.js:759:13)
at /var/www/smoran/repo/node_modules/protractor/node_modules/q/q.js:573:44
at flush (/var/www/smoran/repo/node_modules/protractor/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:419:13)
This error is thrown when protractor can not find any files using the globbing pattern specified or, possibly, when none of the files it finds that do exist can be parsed by jasmine or mocha.
Now, I do not care about the situation that causes this error. I do not care whether protractor can or can not find files with my globbing patterns, and if I do care, I would like to throw my own error(s), as its errors are much too verbose, being in fact uncaught exceptions. Unfortunately, protractor is tripping me up at every turn where I try to do that. It seems to be throwing the error in the runner, then catching it in its dependency, q, then rethrowing it if it is being run under NodeJS (which it is).
I am using gulp, and I am using child_process's spawn to spawn protractor, because all of gulp's protractor plugins seem to be blacklisted or advised not to be used. My code would be too long to show here, but it essentially ends up like this:
gulp.task('protractor', function() {
return spawn('protractor',
[
'--specs=' + notFoundTests
otherArgs
],
{
stdio: 'inherit'
});
});
I have protractor in my PATH, and notFoundTests is a string, not an array. I am using stdio: 'inherit' because I still want to see all the errors & output, but I am trying to find a way to filter it.
No matter what I try to catch, the error seems to not be emitted that way. It seems that it is not emitted as an error, so spawn(...).on('error', function() {}); does not work. Using a try catch block around the call to spawn also does not work. Even using process.on('uncaughtException'); does not catch it, even though it seems to be an uncaught exception.
My question is: How do I catch errors like this, that are thrown by protractor but not really returned? Does protractor provide any hooks, etc.? Also, why is it throwing this particular error? This seems to be an end-developer error, not something that protractor should handle itself.

Related

Debugging jest test in VS Code shows "Error: Cannot find module "jest-environment-node"

I have troubles with debugging my jest tests. Maybe I introduce my setup first:
root-dir
test
sample.spec.ts
jest.config.js
package.json
tsconfig.json
The contents of sample.spec.ts:
describe('Sample', () => {
it.concurrent('App', async () => {
expect(true).toEqual(true); // here the breakpoint is set
});
});
So nothing fancy to be debugged here. I installed the Jest Runner extension in VS Code.
However, when I "click" the "Debug" button, right above the it, the debugger starts, but shows an exception:
Exception has occurred: Error: Cannot find module 'jest-environment-<path-to-my-root-dir>\node_modules\jest-environment-node\build\index.js/package.json' from '<path-to-my-root-dir>'e
What is the problem there? In the node_modules directory, the jest-environment-node is there. The path form the exception is not correct, hence it can't find the package.json. But this one I can't influence!
I appreciate your help!
Kind regards to all of you!
I've found the solution to this problem... which isn't a problem at all. It is also answered here: Cannot find module jest-sequencer-#jest/test-sequencer!
So... never ever tick Caught Exceptions and Uncaught Exceptions in VS Code:
Without those two ticks, jest works out of the box.

Use NodeJS's process in Vue CLI project

I have a challenge using the Node's process.on function in the Vue CLI project's main.js file.
I have the following code in the file.
process.on("unhandledRejection", function(reason, promise){
console.log("Unhandled", reason, promise); // log all your errors, "unsuppressing" them.
throw reason; // optional, in case you want to treat these as errors
});
The project builds but when the app is opened on the browser, I get an error:
Uncaught TypeError: process.on is not a function
How do I configure the project so that I can use the Node's process?
Am I not understanding NodeJS in this context?
Is there something I am missing?
Any assistance is appreciated thanks.

grunt-couch failing with error in task.js:205:15 & taskjs.:241:33

I'm not sure where this error is coming from - a misconfigured grunt.initConfig object, my files, or grunt itself. The error output is not clear about what might be wrong...
The error output:
Error: Task "couch-compile:app" failed.
at Task.<anonymous> (/Users/me/Dev/gitlab/theapp/src/node_modules/grunt/lib/util/task.js:205:15)
at null._onTimeout (/Users/me/Dev/gitlab/theapp/src/node_modules/grunt/lib/util/task.js:241:33)
at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)
I tried figuring it out from other projects getting the same error in the task.js file, but I don't understand what's going on.
My couchapp works with the python version of couchapp push, so getting my project into a format usable by this grunt plugin could be my problem. My structure is basically (almost exactly) what is being expected by this plugin though. I've had to exclude some files that the .couchappignore file lists (the grunt-couch plugin doesn't account for that).
My grunt.initConfig object:
'couch-compile': {
app: {
files: {
'app.json' ['!*.txt','!*.sh','!_docs','!.couchapp*','webapp/**/*']
}
}
}
Could someone tell me whether it's my file structure, my grunt config object, or if the grunt-couch plugin is the one throwing the error?
Thanks.

Gulp.js can't compile angular.js project due to excessive js errors?

I am trying to move from Grunt to Gulp. This project has run fine under Grunt, so I must be doing something wrong in Gulp.
All the other tasks work except scripts. I have tired now adding and commenting out sections.
I keep getting an error relating to an unexpected token. Using mg-min:
stream.js:94
throw er; // Unhandled stream error in pipe.
^
Error: Line 2: Unexpected token :
at throwError (/Users/stevelombardi/Documents/dsg/node_modules/gulp-ngmin/node_modules/ngmin/node_modules/esprima/esprima.js:1156:21)
With ng-min commented out and using Uglify (default):
Error caught from uglify: Unexpected token: punc (:) in /Users/stevelombardi/Documents/dsg/dist/scripts/main.min.js. Returning unminifed code
[gulp] gulp-notify: [Gulp notification] Scripts task complete
[gulp] Finished 'scripts' after 2.97 s
I'm stumped. Here's the task:
// Scripts
gulp.task('scripts', function() {
return gulp.src([
"bower_components/jquery/jquery.js",
"bower_components/angular/angular.js",
"bower_components/bootstrap/dist/js/bootstrap.js",
"bower_components/modernizr/modernizr.js",
"bower_components/angular-resource/angular-resource.js",
"bower_components/angular-cookies/angular-cookies.js",
"bower_components/angular-sanitize/angular-sanitize.js",
"bower_components/angular-route/angular-route.js",
"bower_components/jquery.easy-pie-chart/dist/angular.easypiechart.js",
"bower_components/angular-bootstrap/ui-bootstrap.min.js",
"bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js",
"bower_components/kapusta-jquery.sparkline/dist/jquery.sparkline.js",
"bower_components/leaflet-dist/leaflet.js",
"bower_components/angular-leaflet/dist/angular-leaflet-directive.js",
"bower_components/ngprogress/build/ngProgress.js",
"bower_components/angular-bootstrap-toggle-switch/angular-toggle-switch.js",
"bower_components/flot/jquery.flot.js",
"bower_components/flot/jquery.flot.resize.js",
"bower_components/flot.tooltip/js/jquery.flot.tooltip.js",
"bower_components/angular-flot/angular-flot.js",
'src/scripts/**/*.js',
])
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('default'))
// .pipe(ngmin({
// dynamic: false
// }))
// .pipe(gulp.dest('dist/scripts'))
.pipe(concat('main.js'))
.pipe(gulp.dest('dist/scripts'))
.pipe(rename({
suffix: '.min'
}))
.pipe(uglify())
.pipe(gulp.dest('dist/scripts'))
.pipe(notify({
message: 'Scripts task complete'
}));
});
I think it's safe to say that the output from the two plugins together can be taken to indicate that you have a syntax error on line two of what is being passed to the ngmin or uglify.
The two plugins are just reacting a bit differently from each other. One is helpfully telling you the line number, and the other is helpfully tell you the file name.
Since you've already renamed the file, it seems like they're talking about a file that is already minified, when in fact it's just that you renamed its in-memory representation prematurely.
For starters, I'd recommend not renaming the file until you have minified it because your error is confusing. At that point, you'll probably see that the error appears in the file that is saved to dist/scripts/main.js (on line two of that file you apparently have an errant colon).

PhantomJS exited unexpectedly with exit code -1073741819

I run a bunch of Jasmine specs with PhantomJS (via Grunt) on a Windows 7 PC, and I happen to get the following error:
Testing jasmine specs via phantom
......
Running PhantomJS...ERROR
>> 0 [ '' ]
Warning: PhantomJS exited unexpectedly with exit code -1073741819. Use --force to continue.
Aborted due to warnings.
The error does not appear if I delete a bunch of tests; however I have no idea what causes the error.
What I also find strange, it that it only occurs now and then.
Any idea why this happens?
We are running AngularJS tests via jasmine and grunt, and had this very same problem. For us it turned out to be due to our custom $exceptionHandler function.
We were missing the throw exception line that is in the example handler. By not throwing the exception, the test would pass but it would randomly cause PhantomJS to crash.
This means that some of our tests were failing and we didn't know it!
Here's the sample handler from the $exceptionHandler documentation page:
angular.module('exceptionOverride', []).factory('$exceptionHandler', function () {
return function (exception, cause) {
exception.message += ' (caused by "' + cause + '")';
throw exception; // <--- This is important
};
});
So I'd look and see if you have custom exception handling too and are possibly missing the throw exception line.
I hope it's as simple as that for you too!
(Sadly, I don't have an answer. I would post as a comment, but I don't have the rep.)
I'm getting the same error trying to create html snapshots with grunt-html-snapshot.
Running PhantomJS...ERROR
>> 0 [ '' ]
Warning: PhantomJS exited unexpectedly with exit code -1073741819. Use --force to continue.
Aborted due to warnings.
I'm feeding grunt a list of URLs and I "randomly" get this crash somewhere in the list. I think I have traced it to the child process spawn call that launches phantom.exe with the bridge.js script. It doesn't seem to get as far as trying load the next page before the phantom.exe child process exits with the error. I haven't been able to find any documentation on the error code.
I received the same error message as Helge after renaming a folder and running jasmine in grunt.
The folder contained all the JavaScript files I wanted to minify into one file, and I renamed the folder to match the final file name. For example the folder, \src\modules\ was renamed \src\modules.js\.
Removing .js from the folder name solved the problem.
Using PhantomJS to generate snapshots for AngularJS.
The snapshots script goes through an array of urls of which it has to take snapshots.
Narrowed down to the possible cause and as it turned out there was a bug in my latest fix in AngularJS. This bug resulted in the constantly switching the home page and the page where the error occurred.
Code Visualization:
$state.go('home state');
...
$state.go('an other state');
...
$state.go('home state');
...
$state.go('an other state');
...
$state.go('home state');
...
...
=> Error: PhantomJS exited unexpectedly with exit code -1073741819
In short:
For me this error was caused by an infinite redirect loop.
The warning PhantomJS exited unexpectedly with exit code -1073741819 is also displayed when your local PhantomJS is incompatible or corrupt.
With npm list -g phantomjs you can check your PhantomJS version.
If you think that it is corrupt, just reinstall it with:
npm uninstall phantomjs -g
npm install phantomjs -g

Resources