Intellij Idea ReferenceError: is not defined - javascript

When debugging typescript code from my testcases in Intellij Idea I get the following error inside the Evaluate window (Alt + F8):
ReferenceError: InternalServerException is not defined
at eval (eval at getStatusCodeAndResponse (C:\Users\<user>\Documents\Projecten\stations-api\app\common\error-handler.ts:17:13), <anonymous>:1:1)
at Object.getStatusCodeAndResponse (C:\Users\<user>\Documents\Projecten\stations-api\app\common\error-handler.ts:17:13)
at Lambda.handler (C:\Users\<user>\Documents\Projecten\stations-api\app\get-guiding-lines-combinations.ts:38:20)
at Lambda.<anonymous> (C:\Users\<user>\Documents\Projecten\stations-api\node_modules\#aws-lambda-powertools\metrics\src\Metrics.ts:277:41)
at Lambda.<anonymous> (C:\Users\<user>\Documents\Projecten\stations-api\node_modules\#aws-lambda-powertools\logger\src\Logger.ts:337:41)
at Lambda.<anonymous> (C:\Users\<user>\Documents\Projecten\stations-api\node_modules\#aws-lambda-powertools\tracer\src\Tracer.ts:364:33)
at Object.<anonymous> (C:\Users\<user>\Documents\Projecten\stations-api\app\get-guiding-lines-combinations.test.ts:41:41)
at Promise.then.completed (C:\Users\<user>\Documents\Projecten\stations-api\node_modules\jest-circus\build\utils.js:391:28)
at new Promise (<anonymous>)
at callAsyncCircusFn (C:\Users\<user>\Documents\Projecten\stations-api\node_modules\jest-circus\build\utils.js:316:10)
The way I import my custom class:
import {
BadRequestException,
Exception,
InternalServerException,
NotFoundException,
} from '../models/Exceptions';
The custom class itself:
export class InternalServerException implements Error {
message: string;
name: string = 'InternalServer';
statusCode: number = 500;
constructor(message?: string) {
this.message = message ?? 'Internal server exception';
}
createResponse(): APIGatewayProxyStructuredResultV2 {
return {
statusCode: this.statusCode,
body: this.message,
};
}
}
While it can easely find my custom classes etc when running the tests. How can I get my classes recognized inside the evaluate window? Since this makes debugging a lot easier. (The version I am using is Intellij Idea 2022.3.2 ultimate)

Related

Storing global variable in a separate file for Protractor Tests

I am trying to create a separate inventory file for Protractor Test where I can store all the reusable variable to be used by different test scrips. The sample Variable list is called Vars.js and the specs should import the variables from this file and consume those. However, this fails as shown below. Can this approach actually be used for storing reusable variables? Can I actually create a separate inventory file for protractor tests outside of conf.js?
Vars.js has the following content :
"use strict";
exports.config = {
function() {
global.loginMain = 'https://mytestsite.com/auth/login';
global.TestText = 'I am the test Text';
}
};
and the spec file is as follows:
require ('./Vars.js')
require('..\\waitAbsent.js')
require("../node_modules/jasmine-expect/index.js")
describe('Vairables Import Test', function() {
console.log(global.loginMain);
console.log(global.TestText);
browser.get(global.loginMain);
it('Text Validation', function(){
expect(browser.getCurrentUrl()).toEqual('https://mytestsite.com/auth/login')
})
});
The log
[10:55:29] I/local - Selenium standalone server started at http://192.168.1.187:51256/wd/hub
undefined
undefined
Started
(node:17800) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods
instead.
F
Failures:
1) Vairables Import Test encountered a declaration exception
Message:
TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received type undefined
Stack:
TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received type undefined
at Url.parse (url.js:152:11)
at urlParse (url.js:146:13)
at Url.resolve (url.js:661:29)
at Object.urlResolve [as resolve] (url.js:657:40)
at ProtractorBrowser.get (C:\FCPS_I\FCPS\node_modules\protractor\built\browser.js:653:17)
at Suite.<anonymous> (C:\FCPS_I\FCPS\TestBed_Scripts\TestBed.js:10:13)
at Object.<anonymous> (C:\FCPS_I\FCPS\TestBed_Scripts\TestBed.js:5:1)
1 spec, 1 failure
Update: a revised Vars.js where I used params as shown below also return the same failure.
"use strict";
exports.config = {
params: {
loginMain: 'https://dss-esy.insystechinc.com/auth/login',
TestText : 'I am the test Text',
}
};
The below approach should work for you.
conf.js
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['app.js'],
onPrepare: async() => {
global.globalVariables = require('./globalVariables');
}
};
app.js
describe('desribe the test', () => {
it('the it', async () => {
console.log(globalVariables.loginMain);
console.log(globalVariables.TestText);
})
})
globalVariables.js
module.exports = {
loginMain :'https://mytestsite.com/auth/login',
TestText : 'I am the test Text'
}

serverless framework with json parsing error

I use serverless framework with javascript.
my code is:
import { App } from '../lib/App';
export const hello = (event, context, cb) => {
context.callbackWaitsForEmptyEventLoop = false;
// This resolved promise would be be in the application library code in a real-world application and provide the results
App.handleFirst(event) // eslint-disable-line promise/catch-or-return
.then(result => ({
statusCode: 200,
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
body: JSON.stringify(result)
}))
.asCallback(cb);
return;};
inside App.js
import BbPromise from 'bluebird';
const THE_MESSAGE = 'Hello from the webpack 4 sample';
export class App {
static handleFirst(event) {
const myDemoResult = {
message: App.THE_MESSAGE,
from: 'First lambda ',
event
};
console.info(myDemoResult);
return BbPromise.resolve(myDemoResult);
}
I use fellow command to deploy it.
set SLS_DEBUG=*
severless deploy
my error is:
Syntax Error -------------------------------------------
Unexpected token A in JSON at position 0
For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
Stack Trace --------------------------------------------
SyntaxError: Unexpected token A in JSON at position 0
SyntaxError: Unexpected token A in JSON at position 0
at JSON.parse (<anonymous>)
at BbPromise.try (F:\workspace\svlecma\node_modules\serverless-webpack\lib\packagers\npm.js:61:47)
at tryCatcher (F:\workspace\svlecma\node_modules\bluebird\js\release\util.js:16:23)
at Function.Promise.attempt.Promise.try (F:\workspace\svlecma\node_modules\bluebird\js\release\method.js:39:29)
at Utils.spawnProcess.catch.then.then.depJson (F:\workspace\svlecma\node_modules\serverless-webpack\lib\packagers\npm.js:61:35)
at tryCatcher (F:\workspace\svlecma\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (F:\workspace\svlecma\node_modules\bluebird\js\release\promise.js:512:31)
at Promise._settlePromise (F:\workspace\svlecma\node_modules\bluebird\js\release\promise.js:569:18)
at Promise._settlePromise0 (F:\workspace\svlecma\node_modules\bluebird\js\release\promise.js:614:10)
at Promise._settlePromises (F:\workspace\svlecma\node_modules\bluebird\js\release\promise.js:694:18)
at _drainQueueStep (F:\workspace\svlecma\node_modules\bluebird\js\release\async.js:138:12)
at _drainQueue (F:\workspace\svlecma\node_modules\bluebird\js\release\async.js:131:9)
at Async._drainQueues (F:\workspace\svlecma\node_modules\bluebird\js\release\async.js:147:5)
at Immediate.Async.drainQueues [as _onImmediate] (F:\workspace\svlecma\node_modules\bluebird\js\release\async.js:17:14)
From previous event:
at PluginManager.invoke (C:\Users\sheng\AppData\Roaming\npm\node_modules\serverless\lib\classes\PluginManager.js:390:22)
at PluginManager.spawn (C:\Users\sheng\AppData\Roaming\npm\node_modules\serverless\lib\classes\PluginManager.js:408:17)
at ServerlessWebpack.BbPromise.bind.then.then.then (F:\workspace\svlecma\node_modules\serverless-webpack\index.js:102:51)
at runCallback (timers.js:694:18)
at tryOnImmediate (timers.js:665:5)
at processImmediate (timers.js:647:5)
at process.topLevelDomainCallback (domain.js:121:23)
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com
Your Environment Information -----------------------------
OS: win32
Node Version: 10.10.0
Serverless Version: 1.31.0
my serverless.yml is here:
https://gist.github.com/thinksource/9fd0c8728df2195b7110b3be04aec2ae
why json first element error? how Can I see the json string?
After seeing your serverless.yml file, I believe that the issue may well be in the webpack.config.js file. It may be worth trying changing your custom section, and putting quotes around: 'webpack.config.js'. Like:
custom:
webpack:
webpackConfig: 'webpack.config.js'
includeModules: true
I think that the issue is in your App.js class here:
const myDemoResult = {
message: App.THE_MESSAGE,
from: 'First lambda ',
event
};
You have a invalid JSON structure; where the object event is being passed, it is not being given a key/name. You probably want something like:
const myDemoResult = {
message: App.THE_MESSAGE,
from: 'First lambda ',
event: event
};
Also your constant THE_MESSAGE is not inside your App class. You should move it inside the App classes {..} like this:
export class App {
static get THE_MESSAGE() { return 'Hello from the webpack 4 sample'; }
...

Asteroid Oauth loginServiceConfiguration: 'google' of undefined

I've followed the 'naive' implementation in the project README: https://github.com/mondora/asteroid-oauth-mixin
The only difference in my code from the example is changing the arrow function to a traditional for the usage of this.
asteroid.ddp.on("added", ({collection, id, fields}: { collection: string; fields: {}, id: string }) => {
if (collection === "meteor_accounts_loginServiceConfiguration") {
asteroid.loginServiceConfiguration = {
...asteroid.loginServiceConfiguration,
[id]: {
_id: id,
...fields
}
};
}
});
});
asteroid.getServiceConfig = function(providerName: string) { // ts file
return this.loginServiceConfiguration[providerName];
}
When I do asteroid.loginWith('google')
index.ts:50 Uncaught TypeError: Cannot read property 'google' of undefined
On the meteor backend I also installed meteor add accounts-base accounts-google because I assume this is a dependency.
What am I missing? Thanks!
I've tried adding DDP.loginServiceConfiguration = {} before the snippet above which resolves the error but creates a new error.
asteroid-oauth-mixin.js:787 Uncaught TypeError: Cannot read property 'clientId' of undefined
at getOauthClientId (asteroid-oauth-mixin.js:787)
at Object.getOptions (asteroid-oauth-mixin.js:720)
at Asteroid.loginWith (asteroid-oauth-mixin.js:104)
at LoginForm../src/routes/accounts/auth/LoginForm.tsx.LoginForm.handleLoginWithGoogle (
Also when I run meteor mongo should db.meteor_accounts_loginServiceConfiguration.find().count() be 0 ?
I needed to meteor add service-configuration and setup my configure-accounts.js and create a google clientId for the application.
This gets me to the point where I have a popup and can choose which user to auth with. Then I receive a new error about target origin mismatch, but I'm going to close this question as resolved.

Node-ACl throws uhandled rejection error

i am using ACL module in my express application.At the start of the server i define some roles and their permissions using the acl.allow() function.
But it logs in a error saying undefined rejection type.The error vanishes on giving a callback with error param.But i am not very sure about what is throwing the error and how it should be handled.
My snippet code which i am using is :
var aclmodule = new acl(new acl.mongodbBackend(config.db.URL, "accesscontrol_"));
aclmodule.allow([
{
roles:['rolea'],
allows:[
{resources:['a','b'], permissions:['*']}
]
},
{
roles:['roleb','rolec'],
allows:[
{resources:['a'], permissions:['view']}
]
},
{
roles:['rolec'],
allows:[
{resources:['o'], permissions:['view','edit']}
]
}
]);
});
The error logged in console is :
Unhandled rejection TypeError: undefined is not a function
at D:\user\web\myapp-web\node_modules\acl\lib\mongodb-backend.js:119:15
at D:\myapp\web\myapp-web\node_modules\acl\node_modules\async\lib\async.
js:607:21
at D:\myapp\web\myapp-web\node_modules\acl\node_modules\async\lib\async.
js:246:17
at iterate (D:\myapp\web\myapp-web\node_modules\acl\node_modules\async\l
ib\async.js:146:13)
at async.eachSeries (D:\myapp\web\myapp-web\node_modules\acl\node_module
s\async\lib\async.js:162:9)
at _asyncMap (D:\myapp\web\myapp-web\node_modules\acl\node_modules\async
\lib\async.js:245:13)
at Object.mapSeries (D:\myapp\web\myapp-web\node_modules\acl\node_module
s\async\lib\async.js:228:23)
at Object.async.series (D:\myapp\web\myapp-web\node_modules\acl\node_mod
ules\async\lib\async.js:605:19)
at Object.MongoDBBackend.end (D:\myapp\web\myapp-web\node_modules\acl\li
b\mongodb-backend.js:35:11)
at Object.tryCatcher (D:\myapp\web\myapp-web\node_modules\acl\node_modul
es\bluebird\js\main\util.js:26:23)
at Object.ret [as endAsync] (eval at (D:\myapp\web\myapp-web
\node_modules\acl\node_modules\bluebird\js\main\promisify.js:163:12),
Is config.db.URL a string? If so, this is the cause of your errors. The line it is failing on is (in mongodb-backend.js):
self.db.collection(... -- it is saying that .collection() is undefined. (Which would make sense if "self.db" were only a string.)
Node-acl expects a database instance when creating a new mongodbBackend, like it says in the docs -- for example:
mongoose.connection.on('connected', function() {
var myAcl = new acl(new acl.mongodbBackend(mongoose.connection.db));
});

Typescript create new instance in class

///<reference path="HtmlElementsAction.ts" />
///<reference path="DesktopSocket.ts" />
module Pong {
export class webPage extends HtmlElementsAction {
private socket;
constructor() {
super();
this.socket = new DesktopSocket(this);
}
}
}
I've this code.
When I'm executing it, in browser's console is error:
Uncaught TypeError: undefined is not a function
Error is on new DesktopSocket(this);
What am I doing wrong?
Common error. Check the order of your script tags or if compiling with "out" the order of arguments to tsc.

Categories

Resources