Export Function From Test file and use it in component file? - node.js

I am new in Angular and NodeJS UTs. I have a function in test file and I have exported that function to use it in another file but once I call it from another file then I am receiving an error of describe block. Here is my code:
abc.controller.ts
export function mockGetAppByName(exists: boolean, error?: boolean) {
// some execution
}
mock.app.ts
import { mockGetAppByName} from '../../test/api/abc/abc.controller.test';
//Called function below in some other function
mockGetAppByName(true);
When I run command npm start It throws below error. If I does not export it then it works fine...When I export and import this function in another file then also I am not receiving any error...BUT...once I call that function in my code then it throws an error. It does not allow my server to start and it keep throwing error.
ERROR
C:\Ambuj Khanna\Project\STA_Console\STAConsole\server\tmp\test\api\action\action.controller.test.js:194
describe('ActionController', () => {
^
ReferenceError: describe is not defined
at Object. (C:\Ambuj
Khanna\Project\project\server\tmp\test\api\action\abc.controller.test.js:194:1)
←[90m at Module._compile (internal/modules/cjs/loader.js:955:30)←[39m
←[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)←[39m
←[90m at Module.load (internal/modules/cjs/loader.js:811:32)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:723:14)←[39m
←[90m at Module.require (internal/modules/cjs/loader.js:848:19)←[39m
←[90m at require (internal/modules/cjs/helpers.js:74:18)←[39m
at Object. (C:\Ambuj
Khanna\Project\project\server\tmp\src\mock\mock.application.js:10:34)
←[90m at Module._compile (internal/modules/cjs/loader.js:955:30)←[39m
←[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)←[39m
←[90m at Module.load (internal/modules/cjs/loader.js:811:32)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:723:14)←[39m
←[90m at Module.require (internal/modules/cjs/loader.js:848:19)←[39m
←[90m at require (internal/modules/cjs/helpers.js:74:18)←[39m
at Object. (C:\Ambuj
Khanna\Project\STA_Console\STAConsole\server\tmp\src\mock\index.js:5:28)
←[90m at Module._compile (internal/modules/cjs/loader.js:955:30)←[39m
←[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)←[39m
←[90m at Module.load (internal/modules/cjs/loader.js:811:32)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:723:14)←[39m
←[90m at Module.require (internal/modules/cjs/loader.js:848:19)←[39m
←[90m at require (internal/modules/cjs/helpers.js:74:18)←[39m
at Object. (C:\Ambuj Khanna\Project\STA_Console\STAConsole\server\tmp\src\app.js:7:14)

Related

My compiler is not showing any error on tsc but it's not running program

And this error is appearing on running
internal/modules/run_main.js:54
internalBinding('errors').triggerUncaughtException(
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'D:\node\node_modules\chalk\source\node_modules\' imported from D:\node\node_modules\chalk\source\index.js
←[90m at packageMainResolve (internal/modules/esm/resolve.js:461:9)←[39m
←[90m at packageResolve (internal/modules/esm/resolve.js:604:14)←[39m
←[90m at moduleResolve (internal/modules/esm/resolve.js:649:14)←[39m
←[90m at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:695:13)←[39m
←[90m at Loader.resolve (internal/modules/esm/loader.js:97:40)←[39m
←[90m at Loader.getModuleJob (internal/modules/esm/loader.js:243:28)←[39m
←[90m at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:42:40)←[39m
←[90m at link (internal/modules/esm/module_job.js:41:36)←[39m {
code: ←[32m'ERR_MODULE_NOT_FOUND'←[39m
}
Please tell me how should I run it and what changes or commands should I use.

Algorithm should be set

I'm working on a Cypress project that was working fine.
But recently, it started throwing some errors. I searched for reasons as to why I was getting the errors. I found out that in my index.js file the export.module had a line to throw an error if the option algorithm was not set as below.
My question is where should I set the said algorithms and how?
Here's the git repository of the project
https://github.com/Leealp/BugsFixed2
module.exports = function(options) {
....................................................................
if (!options.algorithms) throw new Error('algorithms should be set');
var secretCallback = options.secret;
if (!isFunction(secretCallback)){
secretCallback = wrapStaticSecretInCallback(secretCallback);
}
....................
....................
}
The error is below:
C:\Users\AlphaLy\Documents\Coding\Cypress Web Automation upload\CypressLastPractices\node-express-sequelize-nextjs(L)\node_modules\express-jwt\lib\index.js:22
if (!options.algorithms) throw new Error('algorithms should be set');
^
Error: algorithms should be set
at module.exports (C:\Users\AlphaLy\Documents\Coding\Cypress Web Automation upload\CypressLastPractices\node-express-sequelize-nextjs(L)\node_modules\express-jwt\lib\index.js:22:34)
at Object.<anonymous> (C:\Users\AlphaLy\Documents\Coding\Cypress Web Automation upload\CypressLastPractices\node-express-sequelize-nextjs(L)\auth.js:20:13)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\Users\AlphaLy\Documents\Coding\Cypress Web Automation upload\CypressLastPractices\node-express-sequelize-nextjs(L)\api\users.js:3:14)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\Users\AlphaLy\Documents\Coding\Cypress Web Automation upload\CypressLastPractices\node-express-sequelize-nextjs(L)\api\index.js:8:17)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\Users\AlphaLy\Documents\Coding\Cypress Web Automation upload\CypressLastPractices\node-express-sequelize-nextjs(L)\app.js:17:13)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47
PS C:\Users\AlphaLy\Documents\Coding\Cypress Web Automation upload\CypressLastPractices\node-express-sequelize-nextjs(L)>

npm command fails after reinstalling windows 10

I have reinstalled Windows and since then, I cannot use npm, I always face the following bug.
I have tried reinstalling node, switching its versions but the npm commands keeps failing.
$ npm
node:internal/modules/cjs/loader:933
const err = new Error(message);
^
Error: Cannot find module './utils/unsupported.js'
Require stack:
- C:\Users\Guillaume\AppData\Roaming\npm\node_modules\npm\lib\cli.js
- C:\Users\Guillaume\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js
←[90m at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)←[39m
←[90m at Function.Module._load (node:internal/modules/cjs/loader:778:27)←[39m
←[90m at Module.require (node:internal/modules/cjs/loader:999:19)←[39m
←[90m at require (node:internal/modules/cjs/helpers:102:18)←[39m
at module.exports (C:\Users\Guillaume\AppData\Roaming\npm\node_modules\←[4mnpm←[24m\lib\cli.js:14:59)
at Object.<anonymous> (C:\Users\Guillaume\AppData\Roaming\npm\node_modules\←[4mnpm←[24m\bin\npm-cli.js:2:25)
←[90m at Module._compile (node:internal/modules/cjs/loader:1099:14)←[39m
←[90m at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)←[39m
←[90m at Module.load (node:internal/modules/cjs/loader:975:32)←[39m
←[90m at Function.Module._load (node:internal/modules/cjs/loader:822:12)←[39m {
code: ←[32m'MODULE_NOT_FOUND'←[39m,
requireStack: [
←[32m'C:\\Users\\Guillaume\\AppData\\Roaming\\npm\\node_modules\\npm\\lib\\cli.js'←[39m,
←[32m'C:\\Users\\Guillaume\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js'←[39m
]
}
Node.js v17.8.0

How to run server.js file in nodejs

Tried to run nodejs application.If i run node server.js i am getting module not found error.All files path is correct but i am getting module not found error.How to resolve this issue?
I have shared the errors below with folder structure:
Folder structure:
test = Main folder
node_modules
src
-controllers =folder
-dataaccess =folder
-routes =folder
-service =folder
-server.js
.angulardoc.json
package.json
package-lock.json
tsconfig.json
tslint.json
Error:
internal/modules/cjs/loader.js:969
throw err;
^
Error: Cannot find module './dataaccess/middlewares/base/MiddlewaresBase'
Require stack:
- C:\xampp\htdocs\test\src\server.js
←[90m at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966
:17)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:859:27)←[39m
←[90m at Module.require (internal/modules/cjs/loader.js:1028:19)←[39m
←[90m at require (internal/modules/cjs/helpers.js:72:18)←[39m
at Object.<anonymous> (C:\xampp\htdocs\test\src\server.js
:4:19)
←[90m at Module._compile (internal/modules/cjs/loader.js:1139:30)←[39m
←[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1159:1
0)←[39m
←[90m at Module.load (internal/modules/cjs/loader.js:988:32)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:896:14)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_ma
in.js:71:12)←[39m {
code: ←[32m'MODULE_NOT_FOUND'←[39m,
requireStack: [ ←[32m'C:\\xampp\\htdocs\\test\\serve
r.js'←[39m ]
}

Getting type error with Sequelizejs

Im getting the following error and I can't figure out through the stack trace where it's erroring.
/Users/rahulsharma/Desktop/Jobletics/node_modules/sequelize/lib/sequelize.js:298
this.importCache[path] = defineCall(this, DataTypes)
^
TypeError: object is not a function
at module.exports.Sequelize.import (/Users/ra/Desktop/Js/node_modules/sequelize/lib/sequelize.js:298:32)
at db.sequelize (/Users/ra/Desktop/Js/models/index.js:14:33)
at Array.forEach (native)
at Object.<anonymous> (/Users/ra/Desktop/Js/models/index.js:13:4)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
Here is the git:
https://github.com/rahul1346/jb
Any idea?
business_model.js is an empty file.

Resources