Error: Timeout - Async function did not complete within undefinedms - jasmine

I recently upgraded an Angular 8 application to use newer version of Karma and related packages (upgraded from "karma": "~4.0.0" to "karma": "~4.4.1"). Many unit tests that worked fine before started to fail intermittently after the upgrade with the below error. Failures were mostly in spec files that had multiple describe blocks that used same instance of the component being tested. I made code changes so that instances are not shared across describe suites and added setting for jasmine.DEFAULT_TIMEOUT_INTERVAL in beforeEach functions. These changes greatly reduced the failures. However, one or two tests may still fail intermittently in the Jenkins pipeline. Running locally does not result in timeouts. Error and sample test follows. As you can see the value of jasmine.DEFAULT_TIMEOUT_INTERVAL is set in the test but still the error reports undefinedms
Upgraded packages
"karma": "~4.4.1",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~2.1.1",
"karma-jasmine": "~3.1.1",
"karma-jasmine-html-reporter": "^1.5.2",
Run tests
ng "test" "test-lib" "--browsers=ChromeHeadlessNoSandbox"
Error:
Error: Timeout - Async function did not complete within undefinedms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) at <Jasmine>
Sample Test:
import { async, TestBed } from '#angular/core/testing';
import { MyTestModule } from './my-test.module';
describe('MyTestModule', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [MyTestModule]
}).compileComponents();
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
}));
it('should create', () => {
expect(MyTestModule).toBeDefined();
});
});

You need to call done(); function after all expects;
Like:
it('getHeroes should return value from array', (done: DoneFn) =>{
let heroes: Hero[] = [
{ id: 11, name: 'Dr Nice' },
{ id: 12, name: 'Narco' },
{ id: 13, name: 'Bombasto' },
{ id: 14, name: 'Celeritas' },
{ id: 15, name: 'Magneta' },
{ id: 16, name: 'RubberMan' },
{ id: 17, name: 'Dynama' },
{ id: 18, name: 'Dr IQ' },
{ id: 19, name: 'Magma' },
{ id: 20, name: 'Tornado' }
];
expect(service.getHeroes()).toEqual(heroes);
done();
});

Related

Cannot use import statement outside a module when running android app with firebase

Using nativescript-vue and can't make my app run after upgrading to latest version of nativescript.
"nativescript": {
"id": "xxx",
"tns-ios": {
"version": "6.5.1"
},
"tns-android": {
"version": "6.5.1"
}
},
App.js:
import Vue from "nativescript-vue";
import App from "./components/App";
const firebase = require('nativescript-plugin-firebase')
const {LocalNotifications} = require("nativescript-local-notifications")
firebase.init({
showNotifications: true,
showNotificationsWhenInForeground: true,
onMessageReceivedCallback: (message) => {
console.log('[Firebase] onMessageReceivedCallback:', {message});
LocalNotifications.schedule(
[{
id: 1,
title: message.data.title,
body: message.data.body,
silhouetteIcon: 'res://ic_app_icon',
thumbnail: "res://icon",
forceShowWhenInForeground: true,
notificationLed: true,
channel: i18n.t('messages_about_orders')
}])
.catch(error => console.log("doSchedule error: " + error));
}
}).then(
function () {
console.log("firebase.init done");
},
function (error) {
console.log("firebase.init error: " + error);
}
);
I run tns run android and right after I get Webpack build done in the console, I get these messages and a crash:
nativescript-plugin-firebase: /Users/butaminas/Local Sites/getfast.co.nz-courier-app/platforms/android/.pluginfirebaseinfo not found, forcing prepare!
nativescript-plugin-firebase: running release build or change in environment detected, forcing prepare!
Cannot use import statement outside a module
What could be the problem here? I have another, similar app and it is all working fine.
I figured it out. It was the problem with hooks folder in the project root directory.
I don't know why this happened but after removing the plugin (the hooks directory was not removed) I removed the hooks folder manually and then installed the plugin again - the problem disappeared.

Protractor - jasmine TypeError: cannot read property 'result' of undefined

Recently i encounter an issue below, whenever i try to execute protractor tests remotely.
I receive an error message upon execution:
npm run e2e:remote
> hogs#0.1.22 e2e:remote /home/user/projects/project
> ./node_modules/protractor/bin/protractor e2e/protractor.remote.conf.js
[09:34:07] I/launcher - Running 1 instances of WebDriver
[09:34:07] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
Jasmine started
/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:5120
return children && children[0].result.status;
^
TypeError: Cannot read property 'result' of undefined
at isAfterAll (/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:5120:36)
at Suite.onException (/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:5083:8)
at Suite.onException (/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:5095:27)
at QueueRunner.onException (/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:5191:28)
at onException (/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:4310:14)
at handleError (/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:4243:11)
at process.onerror (/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:2371:17)
at process.emit (events.js:223:5)
at process.emit (/home/user/projects/project/node_modules/protractor/node_modules/source-map-support/source-map-support.js:439:21)
at process.emit (/home/user/projects/project/node_modules/source-map-support/source-map-support.js:485:21)
Due to the above, i am unable to run tests at all at remote.
my protractor.conf.js:
require('dotenv').config();
const { SpecReporter } = require('jasmine-spec-reporter');
/**
* #type { import("protractor").Config }
*/
exports.config = {
seleniumAddress: process.env.SELENIUM_SERVER_ADDRESS || `http://localhost:4444/wd/hub`,
allScriptsTimeout: 11000,
specs: ['./src/**/*.e2e-spec.ts'],
// directConnect: true,
multiCapabilities: [
{
browserName: 'chrome',
shardTestFiles: false,
maxInstances: 2,
},
//{
// browserName: 'firefox',
//},
],
maxSessions: -1,
baseUrl: process.env.REMOTE_URL || "",
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {},
},
onPrepare() {
process.env.USER_EMAIL = process.env.USER_EMAIL || '';
process.env.USER_PASSWORD = process.env.USER_PASSWORD || '';
require('ts-node').register({
project: 'e2e/tsconfig.json',
});
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
},
};
Tests run smoothly when i uncomment the directconnect, though in our project we are supposed to run tests through selenium grid, so it is vital that remote runs without it.
Jasmine version is 3.5.0,
Protractor is ver 5.4.3.

How to run tests programmatically in Nightwatch.js?

I'm using Nightwatch.js and trying to run E2E tests using the programmatic API as described here.
Here is my nightwatch.json file:
{
"src_folders": ["tests"],
"webdriver": {
"start_process": true,
"server_path": "node_modules/.bin/chromedriver",
"port": 9515
},
"test_settings": {
"default": {
"desiredCapabilities": {
"browserName": "chrome"
}
}
}
}
and index.js script:
const Nightwatch = require('nightwatch');
Nightwatch.runTests(require('./nightwatch.json')).then(() => {
console.log('All tests has been passed!');
}).catch(err => {
console.log(err);
});
When I run the script I get the error:
Error: An error occurred while retrieving a new session: "Connection refused to 127.0.0.1:9515". If the Webdriver/Selenium service is managed by Nightwatch, check if "start_process" is set to "true".
I feel it needs some configuration but the documentation isn't very helpful here.

Using karma-typescript with graphql-tag loader

I am trying to run tests written in TypeScript using tape and the karma-typescript loader.
In my project I use webpack with graphql-tag/loader and import the queries directly into my TypeScript files like:
import myQuery from "../query/hello.graphql";
These imports are causing issues when I try and run the tests.
module.exports = function (config) {
config.set({
frameworks: ["tap", "karma-typescript"],
files: [
"src/**/*.ts",
"src/**/*.tsx",
"query/**/*.graphql"
],
preprocessors: {
"src/**/*.ts": ["karma-typescript"],
"src/**/*.tsx": ["karma-typescript"]
},
karmaTypescriptConfig: {
compilerOptions: {
"skipLibCheck": true,
"allowSyntheticDefaultImports": true
},
bundlerOptions: {
transforms: [
require("karma-typescript-es6-transform")()
]
}
},
reporters: ["progress", "karma-typescript"],
browsers: ["Firefox"]
});
};
I guess that I would ideally like to perform a second transform on the .graphql files. Based on the approach used in jest-transform-graphql, I tried adding another transform:
function (context, callback) {
if (/\.graphql$/.test(context.module)) {
context.source = loader.call({ cacheable() { } }, context.source);
return callback(undefined, true);
}
return callback(undefined, false);
}
But I still get errors like:
{
"message": "SyntaxError: unexpected token: identifier\nat query/hello.graphql:1:6\n\n",
"str": "SyntaxError: unexpected token: identifier\nat query/hello.graphql:1:6\n\n"
}
How can I apply the transformation to the graphql files, so that I don't get syntax errors from them in the browser?

raven - sentry + django = No servers configured, and sentry not installed. Cannot send message

I have a sentry server that works ok.
raven test <dnstoserver> -> Sending a test message... success!
I have a dev machine with django 1.3 and raven 1.93.
In the django project I have this:
setting.py:
SENTRY_KEY=<secretkey>
SENTRY_DNS=<dnstoserver>
INSTALLED_APPS = (
'bar',
'foo',
'raven.contrib.django',
)
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'root': {
'level': 'WARNING',
'handlers': ['sentry'],
},
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
},
},
'handlers': {
'sentry': {
'level': 'ERROR',
'class': 'raven.contrib.django.handlers.SentryHandler',
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose'
}
},
'loggers': {
'django.db.backends': {
'level': 'ERROR',
'handlers': ['console'],
'propagate': False,
},
'raven': {
'level': 'DEBUG',
'handlers': ['console', 'sentry'],
'propagate': False,
},
},
}
Mind the absence of 'sentry' in the installed_apps. This is intentionally, since sentry is the server and should not be on a client!
views.py (in a view):
import logging
logger = logging.getLogger("raven")
logger.error("test")
When I run the view I get on the console:
No servers configured, and sentry not installed. Cannot send message
Why, and how to fix?
Were you really setting SENTRY_DNS or SENTRY_DSN?
When you set SENTRY_DSN the instantiation of the major config variables happens automatically (including SENTRY_SERVERS, SENTRY_PUBLIC_KEY, SENTRY_SECRET_KEY, and SENTRY_PROJECT)
The problem was in the construction of the raven DjangoClient. It did not get passed any servers, and couldn't find sentry config to steal that config from.
I added in the settings.py:
SENTRY_SERVERS=<dnstoserver>
Console now outputs this every time raven is called:
INFO 2012-06-21 05:33:19,831 base 4323 140735075462336 Configuring Raven for host: <dnstoserver>
But it works like a charm! Messages in sentry...
BTW. for all the undocumented settings take a look in raven.contrib.django.models.get_client()
I suggest to use:
SENTRY_DSN = 'http://user:password#<domain>:<port>/<project_id>'
And in APPS_INSTALLED add:
'raven.contrib.django.raven_compat'
Also take a look at this guide:
http://code.fetzig.at/post/18607051916/sentry-and-raven-setup-for-django-projects

Resources