Unknown provider: $rootElementProvider <- $rootElement <- $location error in karma run - jasmine

hi i am getting the error while running karma run
controller :
myApp.controller('LookupCtrl', function($scope, $rootScope, LCService, $q, $http,$location) {....}
Here the above controller users LCService
LCService :
myApp.service("AccountService", function($rootScope, $http, $location) {...}
in karma.conf.js file
files: [
//angular files
'app/js/vendor/angular/angular.js',
'app/js/vendor/angular/angular-route.js',
...
]
i have the 'angular-route.js' in my application as well., but when i run this it shows the following error
Error: [$injector:unpr] Unknown provider: $rootElementProvider<-$rootElement<-$location
how to fix this ?

Related

socketio-jwt error in building typescript when importing library [Cannot find namespace 'SocketIO'.]

hello guys I am working on a nestjs#v9 that has a chat functionality and I want to be able to authorize the tokens sent by the user while creating the websocket
the app has a build script "build":"npm run remove-build && tsc -p tsconfig.build.json"
when running this script using yarn build
it gives me the error
yarn run build stdout:
$ npm run remove-build && tsc -p tsconfig.build.json
> remove-build
> rm -rf dist
../../node_modules/socketio-jwt/types/index.d.ts(26,14): error TS2503: Cannot find namespace 'SocketIO'.
../../node_modules/socketio-jwt/types/index.d.ts(63,38): error TS2503: Cannot find namespace 'SocketIO'.
I found that if I remove this line
// import { authorize } from 'socketio-jwt';
the error disappears but unfortunately I need to use this authorize method
so my question how can I solve this Issue.
[NOTE] i have this packages inside my package.json
"socket.io": "^4.5.2",
"socket.io-redis": "^6.1.1",
"socketio-jwt": "^4.6.2",
the client should be connecting using this code
const socket = io('http://localhost:1080', {
transports: ['websocket'],
query: {
token: TOKEN,
},
});
the server should authorize the socket using
import { authorize } from 'socketio-jwt';
public createIOServer(port: number, options?: ServerOptions): any {...
const server = super.createIOServer(port, options);
server.adapter(this.redisAdapter);
server.use(
authorize({
decodedPropertyName: 'token',
handshake: true,
secret: secret,
}) as any,
);

Reference Error :cy is not defined while running cypress test

Describe('The Login', function () {
beforeEach(function () {
cy.readFile(Cypress.env('test')).as("user")});
it("Login", () => {
cy.get("#user").then((user) =>
cy.login(user.username, user.password))})
FAIL cypress/integration/login.spec.js
● The Login Page ›
ReferenceError: cy is not defined
at Object.<anonymous> (cypress/integration/login.spec.js:4:5)
at new Promise (<anonymous>)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
To add some context to the answer by #sai, to resolve this eslint error all I had to do was install eslint-plugin-cypress from here.
npm install eslint-plugin-cypress --save-dev
Then, in my eslint config I added one line to my extends array.
Your config could be .eslintrc.json or the "eslintConfig" configuration object in your package.json
{
"extends": [
"plugin:cypress/recommended"
]
}
Testing locally, this should work for you. Change path of your json file, and use your custom command cy.login. In my example I just printed variables to console.
describe('The Login', () => {
beforeEach(() => {
cy.readFile('cypress/integration/test/test.json').as("user")});
it("Login", () => {
cy.get("#user").then((user) =>
cy.log(user.username, user.pass))
})
})
My test.json was:
{
"username":"test#test.com",
"pass":"pass"
}
The issue was related to eslint
Had to install few packages and made an update to eslintrc files

Cannot read property 'Base' of undefined error using mocha-allure-reporter in Cypress

I am trying to use mocha-allure-reporter in Cypress. I installed mocha and mocha-allure-reporter as dev dependencies and mentioned mocha-allure-reporter as the reporter in cypress.json.
I tried the below code quoted in the example section of mocha allure page:
require('mocha-allure-reporter');
describe("simple test demo", () => {
const testStep = allure.createStep("initial", () => {
console.log("First Test")
});
it("simple passed test", () => {
testStep();
});
}
However, I am getting the following error:
Uncaught TypeError: Cannot read property 'Base' of undefined
...at the first line itself:
require('mocha-allure-reporter')
Upon looking on console, I see that the error is originated at line - var Base = require("mocha").reporters.Base in the Allure reporter :
var Base = require("mocha").reporters.Base;
var Allure = require("allure-js-commons");
...
...
global.allure = new Runtime(allureReporter);
/**
* Initialize a new `Allure` test reporter.
*
* #param {Runner} runner
* #param {Object} opts mocha options
* #api public
*/
function AllureReporter(runner, opts) {
...
...
Please note that the following output xml file is getting created in the allure-results directory once the execution is done.
<?xml version='1.0'?>
<ns2:test-suite xmlns:ns2='urn:model.allure.qatools.yandex.ru' start='1547481439243' stop='1547481439477'>
<name></name>
<title></title>
<test-cases>
<test-case start='1547481439282' status='broken' stop='1547481439460'>
<name>An uncaught error was detected outside of a test</name>
<title>An uncaught error was detected outside of a test</title>
<labels/>
<parameters/>
<steps/>
<attachments/>
<failure>
<message>Cannot read property 'Base' of undefined
This error originated from your test code, not from Cypress.
When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.
Cypress could not associate this error to any specific test.
We dynamically generated a new test to display this failure.</message>
<stack-trace>Uncaught TypeError: Cannot read property 'Base' of undefined
This error originated from your test code, not from Cypress.
When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.
Cypress could not associate this error to any specific test.
We dynamically generated a new test to display this failure.
at Object.<anonymous> (http://localhost:61925/__cypress/tests?p=cypress\integration\Tests\Test.spec.js-289:15125:38)
at Object.98.allure-js-commons (http://localhost:61925/__cypress/tests?p=cypress\integration\Tests\Test.spec.js-289:15201:4)
at o (http://localhost:61925/__cypress/tests?p=cypress\integration\Tests\Test.spec.js-289:1:265)
at http://localhost:61925/__cypress/tests?p=cypress\integration\Tests\Test.spec.js-289:1:316
at Object.40.mocha-allure-reporter (http://localhost:61925/__cypress/tests?p=cypress\integration\Tests\Test.spec.js-289:7566:1)
at o (http://localhost:61925/__cypress/tests?p=cypress\integration\Tests\Test.spec.js-289:1:265)
at r (http://localhost:61925/__cypress/tests?p=cypress\integration\Tests\Test.spec.js-289:1:431)
at http://localhost:61925/__cypress/tests?p=cypress\integration\Tests\Test.spec.js-289:1:460</stack-trace>
</failure>
</test-case>
</test-cases>
</ns2:test-suite>
Please guide me. Thanks!
I was able to use mocha-allure-reporter by simply installing it (along with mocha),
npm install mocha mocha-allure-reporter
and setting up a script in package.json, following the Cypress guidelines for npm reporters here
"scripts": {
...
"cypress:run": "cypress run --reporter mocha-allure-reporter"
Note, I think that these reporters only work with the Cypress 'run' command, not the Cypress 'open' command.
The output is a folder called 'allure-results' which contains a bunch of xml files. I presume these can then be displayed using the Allure framework tool.
Example output file:
<?xml version='1.0'?>
<ns2:test-suite xmlns:ns2='urn:model.allure.qatools.yandex.ru' start='1547254197911' stop='1547254201289'>
<name>Tasks Page</name>
<title>Tasks Page</title>
<test-cases>
<test-case start='1547254199721' status='passed' stop='1547254199815'>
<name>should have a title</name>
<title>should have a title</title>
<labels/>
<parameters/>
<steps/>
<attachments/>
</test-case>
</test-cases>
</ns2:test-suite>
Run allure code in cy.task()
To run the allure code, you need to access the nodejs context through cy.task.
For example,
/cypress/plugins/index.js
require('mocha-allure-reporter');
module.exports = (on) => {
on('task', {
allureTestStep () {
const testStep = allure.createStep("initial", () => {
console.log("First Test")
});
testStep()
return null
}
})
}
spec
describe("simple test demo", () => {
it("simple passed test", () => {
cy.task('allureTestStep')
});
})
Note this produces the console log in the command window where you start Cypress, not the browser console.
However, you can pass a value back from the task into the test, depending on what you are actually trying to do (see docs for details).

Protractor error selenium spring boot

vegan#vegan:~/hb-productupload/gateway/src/test/javascript$ gulp protractor
[15:47:24] Working directory changed to ~/hb-productupload/gateway
[15:47:51] Using gulpfile ~/hb-productupload/gateway/gulpfile.js
[15:47:51] Starting 'protractor'...
Using ChromeDriver directly...
[launcher] Running 1 instances of WebDriver
/home/vegan/hb-productupload/gateway/node_modules/selenium-webdriver/http/index.js:174
callback(new Error(message));
^
Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:47841
at ClientRequest.<anonymous> (/home/vegan/hb-productupload/gateway/node_modules/selenium-webdriver/http/index.js:174:16)
at emitOne (events.js:90:13)
at ClientRequest.emit (events.js:182:7)
at Socket.socketErrorListener (_http_client.js:306:9)
at emitOne (events.js:90:13)
at Socket.emit (events.js:182:7)
at emitErrorNT (net.js:1265:8)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
From: Task: WebDriver.createSession()
at Function.webdriver.WebDriver.acquireSession_ (/home/vegan/hb-productupload/gateway/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:157:22)
at Function.webdriver.WebDriver.createSession (/home/vegan/hb-productupload/gateway/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:131:30)
at new Driver (/home/vegan/hb-productupload/gateway/node_modules/selenium-webdriver/chrome.js:810:36)
at [object Object].DirectDriverProvider.getNewDriver (/home/vegan/hb-productupload/gateway/node_modules/gulp-protractor/node_modules/protractor/lib/driverProviders/direct.js:68:16)
at [object Object].Runner.createBrowser (/home/vegan/hb-productupload/gateway/node_modules/gulp-protractor/node_modules/protractor/lib/runner.js:186:37)
at /home/vegan/hb-productupload/gateway/node_modules/gulp-protractor/node_modules/protractor/lib/runner.js:276:21
at _fulfilled (/home/vegan/hb-productupload/gateway/node_modules/gulp-protractor/node_modules/q/q.js:797:54)
at self.promiseDispatch.done (/home/vegan/hb-productupload/gateway/node_modules/gulp-protractor/node_modules/q/q.js:826:30)
at Promise.promise.promiseDispatch (/home/vegan/hb-productupload/gateway/node_modules/gulp-protractor/node_modules/q/q.js:759:13)
at /home/vegan/hb-productupload/gateway/node_modules/gulp-protractor/node_modules/q/q.js:525:49
[launcher] Process exited with error code 1
[15:47:59] gulp-notify: [JHipster Gulp Build] Error: protractor exited with code 1
[15:47:59] Finished 'protractor' after 7.34 s
[15:47:59] E2E Tests failed
I am trying to run a simple
i updated chrme driver.
Then i made
npm install
bower install
gulp install
but did not work when i run
gulp protractor
I run with gulp for project but also i downloaded to my ubuntu and i can run as local. But same error for that local happens when i run
protractor protractor.conf.js
Ysterday i could run both, i made upgrade. now i cant work both.
this is conf file
var HtmlScreenshotReporter = require("protractor-jasmine2-screenshot-reporter");
var JasmineReporters = require('jasmine-reporters');
var prefix = 'src/test/javascript/'.replace(/[^/]+/g, '..');
exports.config = {
chromeDriver: prefix + 'node_modules/protractor/selenium/chromedriver',
allScriptsTimeout: 20000,
suites: {
login: './e2e/account/login/*.js'
},
capabilities: {
'browserName': 'chrome'
},
directConnect: true,
framework: 'jasmine2',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000
},
onPrepare: function () {
// Disable animations so e2e tests run more quickly
var disableNgAnimate = function () {
angular
.module('disableNgAnimate', [])
.run(
[
'$animate',
function ($animate) {
$animate.enabled(false);
}
]
);
};
var disableCssAnimate = function () {
angular
.module('disableCssAnimate', [])
.run(
function () {
var style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = 'body * {' +
'-webkit-transition: none !important;' +
'-moz-transition: none !important;' +
'-o-transition: none !important;' +
'-ms-transition: none !important;' +
'transition: none !important;' +
'}';
document.getElementsByTagName('head')[0].appendChild(style);
}
);
};
browser.addMockModule('disableNgAnimate', disableNgAnimate);
browser.addMockModule('disableCssAnimate', disableCssAnimate);
browser.driver.manage().window().setSize(1600, 1280);
}
};
this is in protractor config
{
"webdriverVersions": {
"selenium": "2.51.0",
"chromedriver": "2.25",
"iedriver": "2.51.0"
}
}
it was not 2.25 i updated but still same.
I changed chrome driver and selenium driver to latest and it worked.

Uncaught Error: Module name "lib/chai" has not been loaded yet for context: use require([])

i m using karma-mocha ..my karma.conf file is working with karma-jasmine...but not working with karma-mocha....my karma.conf file:--
module.exports = function(config){
config.set({
basePath : '../app',
preprocessors: {
'**/*.html':'ng-html2js'
},
ngHtml2JsPreprocessor: {
prependPrefix: '/'
},
files : [
'node_modules/jquery/**/*.js',
'lib/angular/angular.js',
'lib/angular/angular-*.js',
'../test/lib/angular-mocks.js',
'../test/lib/sinon-1.15.0.js',
'../test/chai/chai.js',
'js/**/*.js',
'../test/unit/**/*.js',
'**/*.html'
],
autoWatch : true,
frameworks: ['mocha','requirejs','chai'],
browsers : ['Chrome'],
plugins : [
'karma-chrome-launcher',
'karma-mocha',
'karma-ng-html2js-preprocessor',
'karma-requirejs',
'karma-chai'
],
junitReporter : {
outputFile: 'test_out/unit.xml',
suite: 'unit'
}
});
};
you are missing chai lib path files array in which is dependency to mocha.include it.
files : [
'node_modules/jquery/**/*.js',
'lib/angular/angular.js',
'lib/angular/angular-*.js',
'../test/lib/angular-mocks.js',
'../test/lib/sinon-1.15.0.js',
'../test/chai/chai.js',
'js/**/*.js',
'../test/unit/**/*.js',
'**/*.html'
],
I came across a similar situation just with Jasmine.
I'd like to introduce my solution.
Try it what is written in the error message. There is a link to a website: http://requirejs.org/docs/errors.html#notloaded
//If this code is not in a define call,
//DO NOT use require('foo'), but use the async
//callback version:
require(['foo'], function (foo) {
//foo is now loaded.
});
My case written for Jasmine in Coffee script looks like this:
sinon = require(['sinon', 'jasmine-sinon']) (foo)->
Now I can use sinon as an object in my unit test and can also follow the documentation of sinon, as well as jasmin-sinon.

Resources