I am here to ask for some help because I can't reach a solution and I have spent so much time on this.
The problem is a weird behavior in karma + jasmine tests, initially I thought that the problem was in AngularJs code but, stripping down by stripping down I reached the point where there is nothing else to remove and the problem is 100% not in angular.
The actual code that I am using is this:
test.js:
'use strict';
describe('Unit tests suite', function () {
it('test', function () {
expect('base').toEqual('');
});
});
karma.conf.js:
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
files: ['*.js'],
exclude: [],
preprocessors: {},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['PhantomJS'],
singleRun: false,
})
}
Absolutely nothing else. The result of that test is:
13 02 2016 04:32:39.559:WARN [karma]: No captured browser, open http://localhost:9876/
13 02 2016 04:32:39.571:INFO [karma]: Karma v0.13.15 server started at http://localhost:9876/
13 02 2016 04:32:39.578:INFO [launcher]: Starting browser PhantomJS
13 02 2016 04:32:41.248:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket HiC4WW_4235Nlf0rAAAA with id 54292207
PhantomJS 2.1.1 (Mac OS X 0.0.0) Unit tests suite test FAILED
Expected '/Users/Gianmarco/Desktop/test' to equal ''.
/Users/Gianmarco/Desktop/test/test.js:5:31
PhantomJS 2.1.1 (Mac OS X 0.0.0): Executed 1 of 1 (1 FAILED) ERROR (0.003 secs / 0.003 secs)
As you can see it seems that the word "base" is being changed with the path of the folder. This is making me going nuts I can't figure out why it is doing so.
I tried both with MacOSX and Ubuntu 14.04 and the result is the same.
To prepare the folder I did this:
mkdir test
cd test
npm install jasmine-core karma-cli karma-jasmine karma-phantomjs-launcher phantomjs-prebuilt --save
karma init
karma start
and of course my system had a npm install karma-cli -g some time ago.
The versions are:
jasmine-core#2.4.1
karma#0.13.21
karma-cli#0.1.2
karma-jasmine#0.3.7
karma-phantomjs-launcher#1.0.0
phantomjs-prebuilt#2.1.4
The same behaviour is obtained using the word absolute, that is replaced with an empty string
I believe its a problem with the default reporter in karma (progress) it appears the URL_REGEX matches both base and absolute as all the rest of the regex is optional.
var URL_REGEXP = new RegExp('(?:https?:\\/\\/[^\\/]*)?\\/?' +
'(base|absolute)' + // prefix
'((?:[A-z]\\:)?[^\\?\\s\\:]*)' + // path
'(\\?\\w*)?' + // sha
'(\\:(\\d+))?' + // line
'(\\:(\\d+))?' + // column
'', 'g')
https://github.com/karma-runner/karma/blob/684ab1838c6ad7127df2f1785c1f56520298cd6b/lib/reporter.js#L25
Related
On a clean node project with Jest 24.9.0, this test suite
test('a test', () => {
expect('foo').toBe('foo');
});
test('b test', () => {
throw 'foo';
});
outputs the following (abbreviated):
√ a test
× b test (1ms)
● b test
The non-ASCII characters, especially the bullet, cause a significant slow-down in an Emacs buffer on Windows 10.
How can I instruct Jest to output only ASCII characters in its decorations?
Jest documentation is silent on the issue; grepping node_modules folder for these characters turned out nothing promising (directly related to Jest).
I tried various reporters, but not to my satisfaction. It's easiest to simply filter the report:
package.json
{
"scripts": {
"test": "jestwrapper"
}
}
bin/jestwrapper
#!/usr/bin/bash
jest 2>&1 | perl -C -Mutf8 -lpe'tr/√✔✓✘✕●/+++xx-/'
I am going to create end to end(e2e) test using protractor with jasmine and angular 6. I have written some test cases almost 10 cases. That's all working fine, but always some cases become fails. And its failed because of jasmine timeout. I have configure timeout value like below. But I am not getting consistant result. sometimes a test cases is success but at next run it will goes to success or fail. I have searched on google but I have not found any useful solution.
I have defined some common properties for wait
waitForElement(element: ElementFinder){
browser.waitForAngularEnabled(false);
browser.wait(() => element.isPresent(), 100000, 'timeout: ');
}
waitForUrl(url: string){
browser.wait(() => protractor.ExpectedConditions.urlContains(url), 100000, 'timeout')
}
And protractor.conf.js file I have defined that
jasmineNodeOpts: {
showColors: true,
includeStackTrace: true,
defaultTimeoutInterval: 20000,
print: function () {
}
}
I am getting below error
- Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
- Failed: stale element reference: element is not attached to the page document
(Session info: chrome=76.0.3809.100)
(Driver info: chromedriver=76.0.3809.12 (220b19a666554bdcac56dff9ffd44c300842c933-refs/branch-heads/3809#{#83}),platform=Windows NT 10.0.17134 x86_64)
I have got the solution:
I have configured waiting timeout 100000 ms for individual element find where whole script timeout was 20000 ms. So I have follow below process:
Keep full spec timeout below than sum of all elements find timeouts. I have configured defaultTimeoutInterval at jasmineNodeOpts greater than sum of value for all test cases timeout. And then add a large value to allScriptsTimeout: 2000000 inside of export.config. Its resolved my problem.
NB: I gave this answer because I think it may help others who will face this kind of problem.
I'm trying to integrate #nstudio/nativescript-paytm plugin into my app.
as a part the first step i have written code to generate checksum. now i'm getting checksum. if i passed this to further steps as I'm getting below error.
Error in console
chromium: [INFO:library_loader_hooks.cc(50)] Chromium logging enabled: level = 0, default verbosity = 0
06-22 07:31:56.479 2762 2762 I cr_BrowserStartup: Initializing chromium process, singleProcess=true
chromium: [ERROR:filesystem_posix.cc(89)] stat /data/user/0/org.nativescript.demo/cache/WebView/Crashpad: No such file or directory (2)
chromium: [ERROR:filesystem_posix.cc(62)] mkdir /data/user/0/org.nativescript.demo/cache/WebView/Crashpad: No such file or directory (2)
My order param is
var order = {
MID: "V************3",
ORDER_ID: "order1",
CUST_ID: "cust123",
INDUSTRY_TYPE_ID: "Retail",
CHANNEL_ID: "WEB",
TXN_AMOUNT: "100.12",
WEBSITE: "WEBSTAGING",
CALLBACK_URL: "https://pguat.paytm.com/paytmchecksum/paytmCallback.jsp",
CHECKSUMHASH: "NDspZhvSHbq44K3A9Y4daf9En3l2Ndu9fmOdLG+bIwugQ6682Q3JiNprqmhiWAgGUnNcxta3LT2Vtk3EPwDww8o87A8tyn7/jAS2UAS9m+c="
};
I'm using github sample of that plugin(javascript version i.e demo) i haven't modified the code.
I have an e2e protractor-jasmine test in my angular application. I've just run the exact same test several times in a row and it stops at exactly one step. giving the same error:
'Failed: script timeout: result was not received in 20 seconds'
What I have tried:
1. I attempted to make this an async function: ... header', async () => { ...
2. I have tried await(ing) the element: await element(by.css("[ng-click='siteDocLibCtrl.managePermissionsDialog($event)']")).click();
3. I have tried to browser.sleep(3000)
Jasmine version:2.8.0
npm version:
npm: '6.4.1',
ares: '1.15.0',
cldr: '33.1',
http_parser: '2.8.0',
icu: '62.1',
modules: '64',
napi: '3',
nghttp2: '1.34.0',
node: '10.15.0',
openssl: '1.1.0j',
tz: '2018e',
unicode: '11.0',
uv: '1.23.2',
v8: '6.8.275.32-node.45',
zlib: '1.2.11'
element.all(by.repeater("file in siteDocLibCtrl.files | filter:global.search | orderBy:orderByField:reverseSort")).get(0).click(); //selects 1st element
element(by.css("[ng-click='siteDocLibCtrl.managePermissionsDialog($event)']")).click();
The output error i am getting is below:
Failed: script timeout: result was not received in 20 seconds
(Session info: chrome=73.0.3683.103)
(Driver info: chromedriver=2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1),platform=Windows NT 10.0.17134 x86_64)[0m
Stack:
ScriptTimeoutError: script timeout: result was not received in 20 seconds
(Session info: chrome=73.0.3683.103)
(Driver info: chromedriver=2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1),platform=Windows NT 10.0.17134 x86_64)
at Object.checkLegacyResponse (C:\Users\Jagdeep\eclipse-workspace\ProtractorTutorial\node_modules\selenium-webdriver\lib\error.js:546:15)
at parseHttpResponse (C:\Users\Jagdeep\eclipse-workspace\ProtractorTutorial\node_modules\selenium-webdriver\lib\http.js:509:13)
at doSend.then.response (C:\Users\Jagdeep\eclipse-workspace\ProtractorTutorial\node_modules\selenium-webdriver\lib\http.js:441:30)
at process._tickCallback (internal/process/next_tick.js:68:7)
Try add this line before the test:
browser.ignoreSynchronization = true;
This is pretty weird. I'm trying incredibly simple examples. Karma will read my tests. But refuses to say if they passed or failed in the output.
Here's my config file:
// Karma configuration
// Generated on Mon Dec 19 2016 15:50:01 GMT-0500 (Eastern Standard Time)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '/src/tt',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
//plugins
plugins: [
'karma-jasmine',
'karma-chrome-launcher',
'karma-phantomjs-launcher',
'karma-istanbul',
'karma-coverage'
],
// list of files / patterns to load in the browser
files: [
//'server/src/main/resources/webapp/static/app/**/*.js'
//'server/src/main/resources/webapp/static/app/test-view/test-view-controller.spec.js',
'test.spec.js'
],
// list of files to exclude
exclude: [
//'bower_components',
//'node_modules',
//'server/src/main/resources/webapp/static/bower/**/*'
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
//'/**/!(*spec).js': ['coverage'],
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: [],
//reporters: [ '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_DEBUG,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
//browsers: [ 'Chrome'],
browsers: ['PhantomJS'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
})
}
And here is my test file:
'use strict'
describe('test', function() {
it('has to equal 4',
function() {
expect(3).toEqual(4);
});
});
Am I missing something basic? I spent all yesterday afternoon stripping out more and more just trying to get one test to run and I'm not sure what else there is to do.
Here's the debug output so I know I'm loading my test file but no results.
21 12 2016 09:44:19.051:DEBUG [web-server]: serving (cached): c:/src/TT/node_mod
ules/karma-jasmine/lib/adapter.js
21 12 2016 09:44:19.054:DEBUG [middleware:source-files]: Requesting /base/test.s
pec.js?25b2b285aaae5dc1b28e003730ae0711891ed68b /
21 12 2016 09:44:19.055:DEBUG [middleware:source-files]: Fetching c:/src/tt/test
.spec.js
21 12 2016 09:44:19.056:DEBUG [web-server]: serving (cached): c:/src/tt/test.spe
c.js
21 12 2016 09:44:19.075:DEBUG [karma]: Run complete, exiting.
21 12 2016 09:44:19.078:DEBUG [launcher]: Disconnecting all browsers
21 12 2016 09:44:19.090:DEBUG [launcher]: Process PhantomJS exited with code 0
21 12 2016 09:44:19.091:DEBUG [temp-dir]: Cleaning temp dir c:\AppData\Local\Tem
p\karma-63269551
21 12 2016 09:44:19.097:DEBUG [launcher]: Finished all browsers
Who wants to make me feel dumb and point out the comma or quote that's ruining my day?
Okay, so I found my own answer finally here (for credit): Need proper reporter for karma jasmine
The newer jasmine/karma requires you ass the karma-spec-reporter if you want test results to print to the console output. Considering all I've ever used with karma is phantomJS it was pretty difficult to tell that my tests were actually running just fine. Aggravating but hopefully this helps someone else who's stuck too.