Karma disconnects with timeout even with 2 tests - javascript

I want to use Karma test runner with tap test framework for my project and I get stuck for parallel running of tests when there are only 2 tests
I cannot get karma to run when there is more than one test in the test folder. I have searched the issue on the net and see that most people see memory issue because of hundred tests, and mostly solve with changing timeout values. I tried changing all timeout and disconnect values but it didn't help.
I have read all those StackOverflow pages and I don't think this is a memory et all, because the same problem is seen with only 2 test. Somehow people may though its a memory problem up to this day.
And in the test, (this test runs all OK when it's only one test) only first step runs OK where I test the existence of my project -> t.ok(project, 'projectexist')
after that step, I see DISCONNECT error whatever I make timeout value. I also tried to open 2 browsers didn't help (since my test needs partners from browsers.)
browserDisconnectTimeout: 100000,
browserNoActivityTimeout: 100000,
browserDisconnectTolerance: 10,
Here is error message I get on the console
26 03 2018 09:59:37.240:WARN [Chrome 65.0.3325 (Windows 7.0.0)]: Disconnected (1 times), because no message in 10000 ms.
Chrome 65.0.3325 (Windows 7.0.0) ERROR
Disconnected, because no message in 10000 ms.
Chrome 65.0.3325 (Windows 7.0.0): Executed 0 of 0 DISCONNECTED (10.214 secs / 0 secs)
error Command failed with exit code 1.
And yet another interesting issue I see is, it fails with 2 exact same test, but if I chop one of them I see SUCCESS without running all steps in full test.
let's say I have 2 tests
1 full test
2 1 step only test
Note: Normally full test runs OK when there is only one test, also shows fail correctly if I make the code fail, but this situation above totally strange behavior when there are 2 tests in the folder
karma config file
module.exports = function (config) {
config.set({
plugins: [
require('karma-webpack'),
require('karma-tap'),
require('karma-chrome-launcher')
],
browserDisconnectTimeout: 100000,
browserNoActivityTimeout: 100000,
browserDisconnectTolerance: 10,
basePath: '',
frameworks: ['tap'],
files: ['test/**/*.js'],
preprocessors: {
'test/**/*.js': ['webpack']
},
webpack: {
node: {
fs: 'empty'
}
},
webpackMiddleware: {
noInfo: true
},
reporters: ['dots'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
})
}

Related

Stryker Mutation testing setup in Windows is not running tests

I am using Stryker for Mutation testing in React Application
When I Run the command npx stryker run I am getting the following error
I am able to generate a Stryker report
but when I update the test cases unable to generate the updated report.
$ npx stryker run
12:41:27 (18244) INFO ConfigReader Using stryker.conf.js
12:41:28 (18244) INFO InputFileResolver Found 17 of 142 file(s) to be mutated.
12:41:28 (18244) INFO Instrumenter Instrumented 17 source file(s) with 932 mutant(s)
12:41:28 (18244) INFO ConcurrencyTokenProvider Creating 6 checker process(es) and 5 test runner process(es).
12:41:47 (18244) INFO DryRunExecutor Starting initial test run. This may take a while.
12:41:48 (18244) INFO DryRunExecutor Initial test run succeeded. Ran 0 tests in 1 second (net 0 ms, overhead 1130 ms).
12:41:48 (18244) ERROR Stryker No tests were executed. Stryker will exit prematurely. Please check your configuration.
My Stryker config file:
* #type {import('#stryker-mutator/api/core').StrykerOptions}
* #type {import('#stryker-mutator/typescript-checker').StrykerOptions}
*/
module.exports = {
_comment:
"This config was generated using 'stryker init'. Please see the guide for more information: https://stryker-mutator.io/docs/stryker/guides/react",
testRunner: 'jest',
mutate: [
'src/index.js',
'src/App.js',
],
reporters: ['progress', 'clear-text', 'html'],
coverageAnalysis: 'off',
jest: {
projectType: 'create-react-app',
},
checkers: ['typescript'],
tsconfigFile: 'tsconfig.json',
}; ````
[1]: https://i.stack.imgur.com/Hs8Tq.png
Solved the issue by adding below in the stryker.config.js file
tempDirName: 'strykerTmp',

multiCapabilities and jasmine focused tests

The Story:
We have a rather huge end-to-end protractor test codebase. We have two configs - one is "local" - to run the tests in Chrome and Firefox using directConnect, and the other one is "remote" - to run tests on a remote selenium server - BrowserStack in our case.
Our "local" config is configured to run some tests in Chrome and some in Firefox - because we really cannot run some tests in Chrome - for instance, keyboard shortcuts don't work in Chrome+Mac. Running the tests that require using keyboard shortcuts in Firefox is a workaround until the linked chromedriver issue is resolved.
Here is the relevant part of the configuration:
var firefox_only_specs = [
"../specs/some_spec1.js",
"../specs/some_spec2.js",
"../specs/some_spec3.js"
];
exports.config = {
directConnect: true,
multiCapabilities: [
{
browserName: "chrome",
chromeOptions: {
args: ["incognito", "disable-extensions", "start-maximized"]
},
specs: [
"../specs/**/*.spec.js",
"../specs/**/**/*.spec.js",
"../specs/**/**/**/*.spec.js"
],
exclude: firefox_only_specs
},
{
browserName: "firefox",
specs: firefox_only_specs
}
],
// ...
};
The problem:
Now, the problem is that, if I'm debugging a single test, or want to run a single test - I'm marking it is as focused (via fdescribe/fit) - but protractor starts two driver sessions - one for Chrome and the other one for Firefox, using both configured capabilities:
Running "protractor:local" (protractor) task
[launcher] Running 2 instances of WebDriver
...
------------------------------------
[chrome #1] PID: 2329
[chrome #1] Using ChromeDriver directly...
[chrome #1] Spec started
...
------------------------------------
[firefox #2] PID: 2330
[firefox #2] Using FirefoxDriver directly...
[firefox #2] Spec started
...
The question:
Is there a way to tell protractor to use the only one capability that has a focused spec configured?
Using currently latest protractor 3.0.0.
Hope the question is clear. Let me know if you need any additional information.
I wonder if you can do something to wrap the it statements like:
onPrepare: function() {
browser.getCapabilities().then(function(caps) {
global.browserName = caps.caps_.browserName;
});
global.firefoxOnly = function(name, testFunction) {
if (browserName === 'firefox') {
return it(name, testFunction);
} else {
return xit(name, testFunction).pend('firefox only');
}
};
}
Then when you write a test, instead of it use something like:
describe('when I do something', function() {
firefoxOnly('it should do the right thing', function() {
doSomething();
expect(thing).toBe(right);
)};
});
I have no idea if this actually works, just throwing it out there. In fact, when I get back to my testing computer and try it out, I would be interested in adding a function like wip to use instead of xit to automatically pend my ATDD tests!
Is there a way to tell protractor to use the only one capability that has a focused spec configured?
According to the relevant github issue, it is not possible.

karma test runner not running any tests

I'm using karma with jasmine and followed online guide by installing using
npm install --save-dev karma
and other necessities
i ran
./node_modules/karma/bin/karma start
and
karma start karma.conf.js
which opened up a external chrome browser showing that karma is connected.
I wrote a simple unit test for one my functions it seems its not running any tests at all
This is my karma config file.
// Karma configuration
module.exports = function(config) {
config.set({
// base path, that will be used to resolve files and exclude
basePath: '',
// testing framework to use (jasmine/mocha/qunit/...)
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'app/assets/components/angular/angular.js',
'app/assets/components/angular-mocks/angular-mocks.js',
'app/assets/javascripts/**/**/*.js',
'spec/javascripts/**/*.js'
],
// list of files / patterns to exclude
exclude: [],
// web server port
port: 8080,
// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: ['Chrome'],
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false
});
};
my unit test
describe('Unit: AddMedicalService',function(){
beforeEach(module('DoctiblePreTreatment'));
var ctrl, scope;
beforeEach(inject(function($controller,$rootScope){
scope = $rootScope.$new();
ctrl = $controller('AddMedicalServiceModalCtrl',{
$scope: scope
});
}));
it('should create return true if var 1 is greater than var2 , false if other wise',
function(){
var compare1 = function(){
var var1 = 1;
var var2 = 0;
return var1 > var2;
}
var compare2 = function(){
var var1 = 0;
var var2 = 1;
return var1 > var2;
}
expect(compare1).toBeTruthy();
expect(compare2).toBeFalsy();
});
});
the particular function in the controller im trying to test
(function() {
app.controller('AddMedicalServiceModalCtrl',['ProviderMedicalService','Treatment','$scope','$modalInstance',function(ProviderMedicalService,Treatment,$scope,$modalInstance){
$scope.newTreatment = {}
$scope.checkless = function(var1,var2){
var1 = parseInt(var1);
var2 = parseInt(var2);
if(var1 > var2){
return true;
}
else{
return false;
}
}
}]);
})();
what is displayed on the console when i run karma
INFO [karma]: Karma v0.12.21 server started at http://localhost:8080/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 36.0.1985 (Mac OS X 10.9.4)]: Connected on socket MkqZfXcO6iIX4Od23QEr with id 9498055
Additional info: I'm using angular-js with ruby on rails. I'm aware that there is the jasmine gem out there that can help me. But my boss insisted that we should try using karma to do our unit testing/E2E for anuglarjs portion and rspec for rails.
Under karma.config.js, set either singleRun or autoWatch to true. In your case both of them are set to false, hence karma is not running the tests.
singleRun: If true, it captures browsers, runs tests and exits with 0 exit code (if all tests passed) or 1 exit code (if any test failed).
singleRun: true
autoWatch: Enable or disable watching files and executing the tests whenever one of these files changes. Incase you want to watch your files.
autoWatch: true
Simple but sometimes overlooked cause: ensure you don't have syntax or compilation errors.
If running a Karma test for JavaScript via your IDE, you may have a syntax error which doesn't appear when you run your tests. This leads to Karma issuing the message "no tests were found".
I ran it under WebStorm; the error appeared under the "Karma Server" tab, while the "No tests were found" message appeared under "Test Run" (both tabs under "Run" or "Debug" tool window).
Following configuration works for me -
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO, // config.LOG_DEBUG,
autoWatch: true,
browsers: ['ChromeNS'],
singleRun: false,
customLaunchers: {
ChromeHeadlessNS: {
base: 'ChromeHeadless',
flags: ['--no-sandbox', '--disable-gpu']
},
ChromeNS: {
base: 'Chrome',
flags: ['--no-sandbox', '--disable-gpu']
}
}

Tests result as successful, although errors are found during Tests

I have set up my test environment as described here with QunitJS + PhantomJS + GruntJS: http://jordankasper.com/blog/2013/04/automated-javascript-tests-using-grunt-phantomjs-and-qunit/
Everything works fine, but I have the problem that, my Grunt Task finishes without errors, although errors are found. This is crucial for my build process. Due to the Test results the build either fails or succeeds. But in my case the build always succeeds. Any Ideas why grunt doesn't exit with failure when errors found?
qunit Task of the grunt file:
module.exports = {
services: {
options: {
urls: [
'http://localhost:8000/tests/services.html'
],
timeout: 20000,
force: true
}
},
gui: {
options: {
urls: [
'http://localhost:8000/tests/gui.html'
],
timeout: 20000,
force: true
}
}
};
Output:
Please consider that I cant upload more info due to confidental issues.
You are asking 'why does Grunt continue and when the tests fail?' The answer is 'because you are asking it to'.
The force option controls whether the QUnit task fails if there are failing tests. Setting it to true as you have done tells Grunt to continue even if there are failing tests. Try setting it to false, or removing it altogether as false is the default.

Grunt Karma runs tests but blocks

I have a grunt task to run Karma unit tests using Phantom JS. The tests run but the task doesn't exit. This blocks any other task from starting till I manually kill the karma:unit task using ctrl+c.
My karma.conf.js file is:
// Karma configuration
// Generated on Thu Mar 06 2014 13:17:21 GMT-0500 (Eastern Standard Time)
module.exports = function(config) {
config.set({
// base path, that will be used to resolve files and exclude
basePath: '',
// frameworks to use
frameworks: ['mocha', 'requirejs', 'chai', 'sinon'],
// list of files / patterns to load in the browser
files: [
{ pattern: 'src/vendor/**/*.js', included: false },
{ pattern: 'src/*.js', included: false },
{ pattern: 'src/app/*_test.js', included: false },
{ pattern: 'src/app/**/*.js', included: false },
{ pattern: 'src/app/*_test.js', included: false },
'test-main.js'
],
// list of files to exclude
exclude: [
'src/app/main.js',
'**/Gruntfile.js'
],
// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: ['progress', 'coverage'],
preprocessors: {
'src/app/**/!(*_test).js': 'coverage'
},
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera (has to be installed with `npm install karma-opera-launcher`)
// - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`)
// - PhantomJS
// - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
browsers: ['PhantomJS'],
// If browser does not capture in given timeout [ms], kill it
captureTimeout: 10000,
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: true
});
};
My Grunt config for the karma task is:
karma: {
options: {
configFile: 'karma.conf.js'
},
unit: {
autowatch: true,
singleRun: true,
}
},
When I run grunt karma:unit, I get:
Running "karma:unit" (karma) task
INFO [karma]: Karma v0.12.0 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.7 (Windows 7)]: Connected on socket V2NFfUtyUi_gl0gWqbov with id 17494532
PhantomJS 1.9.7 (Windows 7): Executed 2 of 2 SUCCESS (0.012 secs / 0 secs)
but it never gets to Done, without errors until I press ctrl+C
I reinstalled karma and PhantomJS in the project and the problem cleared. I noticed that when I changed my karma configuration to use Chrome, everything worked normally so I figured the issue had to be with PhantomJS
npm install karma --save-dev
npm install phantomjs --save-dev

Categories

Resources