Is there any way to stop Karma &/or Protractor from linting files in the stream passed to it? We are using gulp, but this could probably apply to other automation tools/environments. While I am sure they are just trying to be helpful, this clogs up our console and is redundant. Worse, it can be confusing to see the same error twice.
Here is an example task:
var karma = require('karma').server;
var spawn = require('child_process').spawn;
gulp.task('tests', function() {
karma.start({
files = 'my/unit/test/files/*.spec.js',
singleRun: true
}, function(error) {
if(error) {
console.log(error);
}
});
spawn('protractor', ['--specs=my/e2e/test/files/*.e2e.js'],
{stdio: 'inherit'}
);
});
If the file "my/e2e/test/files/test.e2e.js" exists & has a JSHint error, Protractor will report the error, whether or not you also run gulp-jshint or something else.
As an example, if the file "my/e2e/test/files/test.e2e.js" looked like this:
describe('some test', function() {
);
The output of gulp tests might look like this:
... some setup...
Protractor:
[09:32:30] An error occurred during the end-to-end testing run
[09:32:30] my/e2e/test/files/test.e2e.js:3
);
^
... some Protractor tests ...
... some Karma tests ...
If the file "my/unit/test/files/test.spec.js" exists & has a JSHint error, Karma will report this error, and it will not run. For example, if the file "my/unit/test/files/test.spec.js" looks the same as "my/e2e/test/files/test.e2e.js" above, the output of gulp tests may look like this:
...some setup...
Karma (I think):
PhantomJS 1.9.8 (Linux) ERROR
SyntaxError: Parse error
at my/unit/test/files/test.spec.js
SUMMARY:
✔ 0 tests completed
...some protractor tests...
It seems that Karma fails the task and does not run if there is an error in the spec files passed to it, and Protractor will report the error but still run, and will report the error in the tasks contained in the errored file. I would rather both streams run, both sets of tests run completely, and perhaps report syntax errors in the test output. However, they should not report the syntax errors before the tests run, or after, because we already have gulp-jshint for linting files. This is just redundant, and it is twice-redundant, in the case of Protractor, if you have a linting plugin already.
So, back to my question: Is there any way to prevent Karma &/or Protractor from linting in their respective streams, separately from the output of the tests? Is there any way to get access to their respective error reporters, without changing their source code? I could always kill them both on any errors before they run, but I may want to run the tests anyway, and I would definitely want to run the other testing framework (for example, run Karma if there are syntax errors in .e2e.js files).
The errors that both Protractor and Karma are Error that the Javascript Engines (the browser you're using for testing) are shouting to you.
Karma and Protractor are not "linting" anything themselves.
To debug the issue in Karma follow these steps:
Add a regular browser to the karma configuration: instead of PhantomJS use either Chrome or Firefox
Start the karma server (not the runner): in your Gulpfile.js change singleRun from true to false.
Once karma and your browser have started you should have a similar window:
Now click on the DEBUG button, it will open a new tab, where you can open the Dev Tools (in case you're using Chrome):
In the Javascript console now you should be able to see that Syntax Error "Karma is reporting" (effectively karma is just repeating what Phantom is trying to say)
Solve those issues and then try to run again in the browser.
Once everything has been fixed switch back to PhantomJS and singleRun: true.
It's not about linting, it's about having understandable/parsable code.
Your example file "my/e2e/test/files/test.e2e.js" is not well written, you're missing function close. Some errors can be "understood" by karma, protractor or your browser, like a missing semicolon.
But errors like not closing a function breaks the parsing of the file and parser won't understand what you mean.
Having such code in a website would break the rendering and result in not running.
Related
I am running mocha unit tests that are written in ES6. Using Babel to run the tests and running into a very bizarre error. This happens as soon as I import something from multiple test scripts. If ES6 Import is used from only one single test script everything works fine.
Here is a snippet of what the error looks like and I have a video that shows exactly how it can be reproduced.
/node_modules/#babel/helper-module-transforms/lib/normalize-and-load-metadata.js:37:52
TypeError: undefined is not a function
https://www.youtube.com/watch?v=jm0p1ttwFZc
Here is the git repo of the problem.
npm install
in /server
https://github.com/jiminssy/BabelProblem
This is because you are using https://www.npmjs.com/package/collections. It replaces many ES6-standard libraries with its own versions that do not conform to the standard behaviors that Babel is expecting and relies on to compile files.
Your option option would be to drop that library, or drop #babel/register. I'd recommend dropping the library since it seems to be extremely poorly designed.
I have a gulp task that performs some pretty common tasks - it runs jshint to validate my code, then concats and minimizes the files and outputs them into single .min.js files.
The task (appears) to execute flawlessly when I run it manually. But the second I try to use it in a $gulp.watch it no longer outputs my file (it still executes and executes jshint though).
The code in my task:
gulp.src(path.join(workingPath, folder, '/*.js'))
.pipe(jshint())
.pipe(jshint.reporter(stylish))
.pipe(jshint.reporter('fail')) //stop build if errors found
.on('error', function() {
console.log("Please review and correct jshint errors.");
this.end();
})
.pipe(order([ //order files before concat - ensure module definitions are first
"*.module.js",
"*.js"
]))
.pipe(concat(filename+'.js'))
.pipe(gulp.dest(destinationPath)) //full combined version
.pipe(uglify())
.pipe(rename(filename+'.min.js'))
.pipe(gulp.dest(destinationPath)) //minified combined version
.on('error',function() {
console.log("An error occurred during Gulp processing.");
this.end();
});
My gulp watch (the task is named 'components'):
gulp.watch(componentsBasePath+"/**/*.js",['components']);
One thing that I've noticed though is at the end of the manual run I see "Process finished with exit code..". And if I kill my gulp.watch it outputs "Process finished with exit code.." - then it DOES creates the output files!
My goal is to have my 'components' task create those output files every time it is triggered by the watch - not just when I kill the watch.
Thank you!
Cliff
Ok so my hacky way to fix the problem with jetbrains (im using phpstorm), you gotta understand 2 things.
gulp watchers act on file save.
jetbrains will not auto update the project files (as you have found out it uses a cache).
To get around this problem i created a macro called saveSync which does the following actions:
Save all
Synchronize
Synchronize
Synchronize
Why did i synchronize 3 times? Because gulp takes a few seconds to finish tasks (compiling, etc) and if you update before they finish obviously the project view doesn't get update properly. I haven't figured out a way to insert a time delay into the macro itself.
After i created the macro, i just rebound ctrl + s from save all to the macro, and it worked.
If there is a 'cleaner' way of doing this i have yet to discover it.
Ran this by someone else and he found the cause of the issue. Though - it's not Gulp related at all it turns out.
The IDE I was using updated the folder and file structure instantly when I manually ran my 'components' task, however it did not do the same when I ran the gulp.watch task. I am happy to report though that the files were being created successfully, they just never appeared in the IDE until I killed the task.
I'm using gulp-karma + mocha + chai + sinon in order to unit test some front end.
The nasty thing I keep getting into is the "Script Error" message that karma spits out without any other relevant detail.
How can I make karma display the source of the error also ?
This might be a little late, but as others may find this problem I thought I'd add some notes.
The Script error comes when the error is produced in a different domain than it's consumed. Browsers then remove the error details for security reasons. Typically this happens if:
you load scripts/pages from different domains
you run eval code. Note that this is what webpack often does in development scenarios
To mitigate this you can
add relevant HTTP CORS headers
skip running eval code - if you're running webpack, choose a devtool not containing "eval"
load resources from the same domain
Hope it helps
The gulpfile.js I wrote is Common gulpfile.js.
In a build task, inject should inject all static files into html outputs, but it inject nothing in the clean build , I must run same command(here is gulp -p project build) twice(gulp -p project build && gulp -p project build) to inject them successful.
I have tried use run-sequence, it helps nothing.
Is this a bug?
Thanks :)
Your gulp tasks appear not to be returning their streams. If you do not return a stream from a task, then any other tasks that depend on it will not wait for the async behaviour to complete before running.
So more or less, what you're seeing is that you have two levels of things that have to happen: first your "script", "style", and "asset" tasks need to be completed, and then when everything's ready your "view" task can do its work. The first time you run it, all four tasks are run at nearly the same time (so "view" runs with old "asset" results, etc.)
To fix it, just return the working stream in each task:
gulp.task('style', ['check'], function () {
var less_filter = gulpFilter('**/*.less');
return gulp.src(path_current.src_path_style)
.pipe(less_filter)
// ... the rest of your pipes
.pipe(browserSync.reload({stream:true}));
});
I'm stuck configuring tests for Jenkins. In the Publish JUnit test result report I have test-reports/*.xml but I'm getting the error:
'test-reports/*.xml' doesn't match anything: 'test-reports' exists but not 'test-reports/*.xml'
When I try */.xml I get:
Did not manage to validate **/*.xml (may be too slow)
When I throw an .xml file into test-reports folder manually it is deleted after the build.
What do?
It might actually be an issue with XCode. We figured out that it was actually skipping the application tests and it just wasn't evident anywhere on Jenkins' console output.