Can't run Jest tests from editor in WebStorm - jestjs

I'm looking at a file in WebStorm that contains Jest tests. I can run Jest via a run configuration and it works fine.
However, I can't right-click on a test in the editor and run it, nor do I get any gutter icons that would let me do so. I can right-click on a describe or it block and I have the option to run or debug, but it's trying to run/debug the file, not run the test:
(function (exports, require, module, __filename, __dirname) { import React from "react";
^^^^^
SyntaxError: Unexpected identifier
at new Script (vm.js:80:7)
at createScript (vm.js:274:10)
at Object.runInThisContext (vm.js:326:10)
at Module._compile (internal/modules/cjs/loader.js:664:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
at startup (internal/bootstrap/node.js:283:19)
Process finished with exit code 1
This is a new installation on a new M1 MacBook Pro, but it's got my settings synced with my other machines, so I don't see any reason why this wouldn't work like all my other WebStorm installations. (And it's not just this file, it's any test file anywhere.)

The problem solved itself when I removed babel-jest from our dependencies and added jest, which hadn't previously been there even though the tests would run, including using the "Run tests" run config.
As #lena suggested, the problem appeared to be not having Jest in the package file.

Related

TypeError: hammerhead.extend is not a function

Don't know why I'm experiencing the following inside the package testcafe-hammerhead.
stiva#stiva-ThinkPad-T490:~/AC_Automation$ testcafe --version
Using locally installed version of TestCafe.
/home/stiva/AC_Automation/node_modules/testcafe-hammerhead/lib/utils/logger.js:44
const proxyLogger = hammerhead.extend('proxy');
^
TypeError: hammerhead.extend is not a function
at Object.<anonymous> (/home/stiva/AC_Automation/node_modules/testcafe-hammerhead/lib/utils/logger.js:44:32)
at Module._compile (node:internal/modules/cjs/loader:1091:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1120:10)
at Module.load (node:internal/modules/cjs/loader:971:32)
at Function.Module._load (node:internal/modules/cjs/loader:812:14)
at Module.require (node:internal/modules/cjs/loader:995:19)
at require (node:internal/modules/cjs/helpers:92:18)
at Object.<anonymous> (/home/stiva/AC_Automation/node_modules/testcafe-hammerhead/lib/request-pipeline/context.js:24:34)
at Module._compile (node:internal/modules/cjs/loader:1091:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1120:10)
I have updated testcafe-hammerhead to its latest, 24.2.1 but it still happens whenever i try to use testcafe for anything.
I cannot reproduce this issue with the basic local TestCafe installation. Try deleting your dependencies and your "lock" file and install all dependencies again. Please note that you don't need to update the testcafe-hamemrhead dependency manually in your project, just install the latest TestCafe version. If the issue still appears, please open a new bug report with a complete example using this template.

Visual Studio 2017, Task Runner Explorer not loading module

I am trying to build my project from Task Runner Explorer.
Project is running fine from cmd, using au run.
The error generates is below:
Failed to run "D:\Irshad\Practice\Aurelia\Demo\AureliaDemo2\Gulpfile.ts"...
cmd.exe /c gulp --tasks-simple
D:\Irshad\Practice\Aurelia\Demo\AureliaDemo2\gulpfile.js:1
(function (exports, require, module, __filename, __dirname) { define(["require", "exports", "gulp", "gulp-shell"], function (require, exports, gulp, gulp_shell_1) {
^
ReferenceError: define is not defined
at Object.<anonymous> (D:\Irshad\Practice\Aurelia\Demo\AureliaDemo2\gulpfile.js:1:63)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at execute (D:\Irshad\Practice\Aurelia\Demo\AureliaDemo2\node_modules\gulp\node_modules\gulp-cli\lib\versioned\^4.0.0-alpha.2\index.js:37:18)
at Liftoff.handleArguments (D:\Irshad\Practice\Aurelia\Demo\AureliaDemo2\node_modules\gulp\node_modules\gulp-cli\index.js:173:63)
I have below code in Gulpfile.ts
import * as gulp from 'gulp';
import shell from 'gulp-shell';
gulp.task('build-dev', shell.task(['au build --env dev']));
Note: I have used both SystemJS and RequireJS module loader.
I am assuming, the issue is simple that i need to tell somehow to use SystemJS loader either in tsconfig.json or package.json or ???
Any help is appreciated. May be I should provide more detail, but could not justify what. Please comment, if any context can help in resolving above issue.
Thanks.
Just in case you're still experiencing this problem;
It appears that the globally installed gulp in C:\Users\{user}\AppData\Roaming\npm\node_modules is an outdated version and that this is where the task runner runs from regardless of what you have defined in your package.json.
In the node.js command prompt, you can uninstall gulp globally using:
npm uninstall gulp -g
As I had gulp declared in my project this actually fixed the problem.
But really what you need is the gulp 4 installed globally;
npm install gulp#next -g
Happy coding!
In Visual Studio Tools->Options->Projects and Solutions->Web Package Management.
Moving $(Path) to first index has resoloved the above issue, may be it was because of node or something else version issue installed independently and in VS.
But still getting another issue at later stage of running task.
The new error is below obviously, it is something else, Can anybody guide a good read overcome these issue:
Failed to run "D:\Irshad\Practice\Aurelia\Demo\AureliaDemo2\Gulpfile.ts"...
cmd.exe /c gulp --tasks-simple
C:\Users\irshad.ali\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:147
console.log(Object.keys(localGulp.tasks)
^
TypeError: Cannot convert undefined or null to object
at logTasksSimple (C:\Users\irshad.ali\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:147:22)
at C:\Users\irshad.ali\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:124:14
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickCallback (internal/process/next_tick.js:104:9)
at Module.runMain (module.js:606:11)
at run (bootstrap_node.js:389:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:504:3
I have written this as answer but not market as answer, waiting for a great answer. :)

Deploy to azure website and run grunt build tasks

I am trying to get continuous integration working for my Azure website which uses grunt, npm and bower to build.
I have followed the instructions here: http://www.cptloadtest.com/2013/12/03/Git-And-Grunt-Deploy-To-Windows-Azure.aspx and have modified my deploy.sh deployment section to match.
When I deploy I get the following error message:
Command: bash deploy.sh
Handling node.js grunt deployment.
An error has occurred during web site deployment.
C:\Program Files (x86)\SiteExtensions\Kudu\45.40522.1562\bin\scripts\selectNodeVersion.js:115
select node version failed
throw new Error('Usage: node.exe selectNodeVersion.js <path_to_repo> <path
^
Error: Usage: node.exe selectNodeVersion.js <path_to_repo> <path_to_wwwroot> [path_to_temp]
at Object.<anonymous> (C:\Program Files (x86)\SiteExtensions\Kudu\45.40522.1562\bin\scripts\selectNodeVersion.js:115:11)
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 Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
Does anybody know what I could try next?
I also had some problems doing build and deployment in visual studio online. I added a command line "npm.cmd cache clean" at the top of my build definition. That made it work. Maybe that helps you too.

Can you use Node Inspector with the .coffee handler?

Debugging node apps using node-inspector is pretty simple if you're scripting using JavaScript or compiled Coffee (coffee -c -m script.coffee).
However, when using the coffeescript require handler:
require('coffee-script/register');
require('lib/component.coffee');
in a script I'm trying to debug using node-debug, I get:
(function (exports, require, module, __filename, __dirname) { #
^
SyntaxError: Unexpected token ILLEGAL
at Module._compile (module.js:439:25)
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)
...
right as I require the file.
Is what I'm trying to do possible? I have several CoffeeScript files that I would much rather not have to compile each time I want to test.
Yes, definitely. I use it all the time, the command line looks like these:
node-inspector & coffee --nodejs --debug-brk ./scripts/mongoEtl.coffee
node-inspector & mocha --compilers coffee:coffee-script ./test/dataLayer-test.coffee --ui bdd --debug-brk
node-inspector --web-port=5870 & mocha --compilers coffee:coffee-script/register ./test/dataLayer-test.coffee --ui bdd --debug-brk=5880 -g 'my test name here'
I just checked the last line, it's working and has coffeescript requires in it. However when I'm debugging I'm actually seeing javascript, not coffee. I don't know if it's possible to run and debug coffeescript with node-inspector (edit: yes, it is, use of source maps is required but that is out of scope for this answer). I'm not convinced that has value -- I think it's good to be able to read javascript well, so I haven't looked into it.
I think your issue might be in the compilation, have you tried compiling the file that's being required?

Require cannot find custom module after moving to server

I am trying to deploy a node app that runs fine on my local Mac Lion, however. On the virtual Ubuntu box, it is giving an error:
module.js:340
throw err;
^
Error: Cannot find module '../lib/review'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/websites/Node_apps/min-driver-node/routes/reviews.js:2:14)
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)
There is my own custom modules in ./lib folder that are 'require' from the routes as following:
var Review = require('../lib/review');
What have I tried?
Ensured the same Node.js version running via
nvm(https://github.com/creationix/nvm)
Removed node_modules just to
re-install them by running "npm install"
Why is the 'require' unable import the custom modules from 'lib' folder on Server while works on Mac? Thank You
Try using the complete path to the file instead of using the relative path (../).
It looks like the 'require' module is case sensitive on Ubuntu but not on Mac....all my modules in lib folder starts with upper case(i.e. lib/Review.js), but when required in other parts of the code, it is lower case - require('../lib/review'). This is causing issue on Ubuntu but not on Mac lion. By updating the code to 'require('../lib/Review'), solves the problem
Is this a bug and i should be reporting this?
Try set file permissions chmod -R 744 '../lib/review'

Resources