Jest debugging in terminal error- directory missing - reactjs

I am beginner in Jest learning and writing testcases.
Trying to debug test file so that in terminal tried to run following command following jest document
https://jestjs.io/docs/en/troubleshooting
node --inspect-brk node_modules/.bin/jest --runInBand
It give an error as per below
C:\Users\Documents\Jest\JestApp>node --inspect-brk node_modules/.bin/jest --runInBand
Debugger listening on ws://127.0.0.1:9229/428f8d8b-f9f9-45f3-8961-f3cba283d0df
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Waiting for the debugger to disconnect...
C:\Users\Documents\Jest\JestApp\node_modules\.bin\jest:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
^^^^^^^
SyntaxError: missing ) after argument list
?[90m at Module._compile (internal/modules/cjs/loader.js:891:18)?[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 Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)?[39m
?[90m at internal/main/run_main_module.js:17:11?[39m
How to resolve above error and successfully debug test file in chrome for Windows.
Please post steps to debug testcase step by step.
First help me to resolve this error,
and further under test file, inside testcase added debugger; but debug mode not poping up in chrome://inspect under DevTools for node.

node_modules/.bin contains executable (binary) files. node_modules/.bin/jest is not valid JavaScript but shell script, this results in syntax error.
Jest entry script should be executed instead:
node --inspect-brk node_modules/jest/bin/jest.js --runInBand

In Windows machine -
node --inspect-brk ./node_modules/jest/bin/jest.js` --runInBand
or on other OS -
node --inspect-brk node_modules/.bin/jest --runInBand
As per documentation, https://jestjs.io/docs/en/troubleshooting.
Thank you

Related

Next JS : Error: EPERM: operation not permitted, open

I am trying to build the next Js app production files to deploy it on cPanel, when I execute
npm run dev the app is working just fine but as I start to build a production file with the help of this video(https://youtu.be/1ykSXau838c) and executes npm run build it gives me an error in the terminal as given below:
PS C:\Users\hp\Desktop\reactJs-project\NextJs\test-app> npm run build
> test-app#0.1.0 build
> next build
info - Checking validity of types
info - Creating an optimized production build .node:events:368
throw er; // Unhandled 'error' event
^
Error: EPERM: operation not permitted, open 'C:\Users\hp\Desktop\reactJs-project\NextJs\test-app\.next\trace'
Emitted 'error' event on WriteStream instance at:
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
errno: -4048,
code: 'EPERM',
syscall: 'open',
path: 'C:\\Users\\hp\\Desktop\\reactJs-project\\NextJs\\test-app\\.next\\trace'
}
so I just want to know is there any way to solve this problem?
Posting comment from Koronag as an answer (as it helped me with this error and seems the most likely cause)...
This error is commonly seen when running a build while the dev server is already running. (E.g. in my case, I had a local build running via npm run dev and was trying to commit/push code, which invoked a Git Hook that also runs npm run dev.)
For me, it works fine this answer drives me to the resolver.
I run 2 scripts in terminals:
once for development
another for the build process.
So after killing the development script it looks perfectly fine!
From next-sitemap repo README.md
"Having next-sitemap command & next-sitemap.js file may result in file opening instead of building sitemaps in windows machines.
As a solution to this, it is now possible to use a custom config file instead of next-sitemap.js. Just pass --config .js to build command."
Next-Sitemap README.md - Building Sitemaps
The above worked for me

Yarn start not working for react js after tried setting react native environment mac m1

ajayror#Ajays-MacBook-Air phgh % yarn start
yarn run v1.22.11
warning ../../package.json: No license field
$ react-scripts start
node:internal/modules/cjs/loader:488
throw e;
^
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/tokenize' is not defined by "exports" in /Users/ajayror/Desktop/phgh/node_modules/postcss-safe-parser/node_modules/postcss/package.json
at new NodeError (node:internal/errors:371:5)
at throwExportsNotFound (node:internal/modules/esm/resolve:416:9)
at packageExportsResolve (node:internal/modules/esm/resolve:669:3)
at resolveExports (node:internal/modules/cjs/loader:482:36)
at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/Users/ajayror/Desktop/phgh/node_modules/postcss-safe-parser/lib/safe-parser.js:1:17) {
code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}
Node.js v17.0.1
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
It seems like we all are facing the same issue, it's taken me so long to solve this problem. Simply follow this, uninstall the current version of node (v17.0.1) and install LTS(v16.13.1). I hope it will work no matter what.
Thanks for your douth.

webdriver-manager error when calling update with "Unhandled 'error' event"

I currently have a project which uses jasmine and selenium on top of node.js. Protractor provides some useful modules which I would like to use, so I installed it and tried to run it using "protractor conf.js". I ended up getting the following errors:
[15:55:03] E/direct - Error code: 135
[15:55:03] E/direct - Error message: Could not find update-config.json. Run 'webdriver-manager update'
to download binaries.
[15:55:03] E/direct - Error: Could not find update-config.json. Run 'webdriver-manager update' to down
load binaries.
When I try to run webdriver-manager update, I get this:
[15:46:10] I/file_manager - creating folder C:\Program Files\node-v8.1.0-win-x86\node_modules\protract
or\node_modules\webdriver-manager\selenium
events.js:182
throw er; // Unhandled 'error' event
I saw some other threads with similar errors but they didn't seem to work for me. I suspect that this might be related to the fact that I want to run protractor without AngularJS, but I'm not sure since I believed it was possible to run protractor without angular. Any help would be appreciated.
EDIT: I tried setting "proxy_on" and "npm config set strict-ssl false" but ended up getting the following when running webdriver-manager-update:
events.js:182 throw er; Unhandled 'error' event
Error: self signed certificate in certificate chain at TLSSocket. (_tls_wrap.js:1098:38) at emitNone (events.js:105:13) at TLSSocket.emit (events.js:207:7) at TLSSocket._finishInit (_tls_wrap.js:628:8) at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:458:38)
Edit 2: Using npm 5.0.3, node 8.1.0, webbdriver-manager 12.0.6, OS: Windows 7

protractor elementExplorer

I'm trying to use protractor elementExplorer and not sure why I can't do it (I'm using Mac).
according to the documentation - http://angular.github.io/protractor/#/debugging I'm going to the protractor directory (use/local/bin) and type
node ./bin/elementexplorer.js
I'm getting the following error:
module.js:340
throw err;
^
Error: Cannot find module '/usr/local/bin/bin/elementexplorer.js'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3
any help?
thanks.
You need to cd into the protractor directory:
cd node_modules/protractor
node ./bin/elementexplorer.js
where node_modules in your case should be under /usr/local/lib/.
If you have protractor installed globally as the docs at https://angular.github.io/protractor/#/ suggest you should be able to start protractor --elementExplorer anywhere and then issue commands such as browser.get('http://angular.github.io/protractor/#/ as per the api at https://angular.github.io/protractor/#/api
You can check your protractor install and version by doing protractor --version
Current verison is 3.0.0
Since you are already in protractor/bin directory try,
node elementExplorer.js
The best way to access elementExplorer is (if protractor installed globally):
protractor --elementExplorer
(If protractor installed in a specific folder), try:
Go to the specific folder, then:
node_modules/.bin/protractor --elementExplorer
If you are in Windows, try C:\Users\{username}\AppData\Roaming\npm\node_modules\protractor\bin
Here you can find elementexplorer.js
You can do node elementexplorer.js it will start selenium standalone server and it will open empty browser.. Here you can test your desired web page.

Getting error regarding slice during Karma/AngularJS unit test config

$ karma init configs/karma.conf.js
>
readline.js:507
this.line = this.line.slice(this.cursor);
^
TypeError: Cannot call method 'slice' of undefined
at Interface._deleteLineLeft (readline.js:507:25)
at suggestNextOption (C:\Users\DEVUSER\AppData\Roaming\npm\node_modules\karma\lib\init.js:165:9)
at nextQuestion (C:\Users\DEVUSER\AppData\Roaming\npm\node_modules\karma\lib\init.js:231:12)
at process (C:\Users\DEVUSER\AppData\Roaming\npm\node_modules\karma\lib\init.js:246:10)
at Object.exports.init (C:\Users\DEVUSER\AppData\Roaming\npm\node_modules\karma\lib\init.js:348:6)
at Object.<anonymous> (C:\Users\DEVUSER\AppData\Roaming\npm\node_modules\karma\bin\karma:26:37)
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)
I am getting this error when trying to run karma init configs/karma.conf.js
I have all of this running under Windows 7 x64
I am following this guide: https://coderwall.com/p/xz-qcg
Any suggestions would be appreciated.
I had the same problem, but I was running this in Cygwin. I don't know if you were.
I first uninstalled and reinstalled nodejs.
When I brought up the rxvt window again to try installing karma, it failed with this:
/c/Program Files/nodejs/npm: line 2: $'\r': command not found
/c/Program Files/nodejs/npm: line 4: $'\r': command not found
/c/Program Files/nodejs/npm: line 5: syntax error near unexpected token `$'in\r''
'c/Program Files/nodejs/npm: line 5: `case `uname` in
This is apparently because of my using it in Cygwin, although I don't know why I didn't get this error before. The following talks about this: https://github.com/isaacs/npm/issues/3710 .
So, I then just opened up a plain "cmd" window, and I found that the package install completed, and "karma init" worked well enough to ask me the first "init" question, so I imagine this is resolved.

Resources