Jest in dev dependencies, but no context menus or highlighting. What am I missing?

I have a multi-module (lambda function) NodeJS project (for reasons), and I'm a bit frustrated with the jest integration--the lack of it.

My main issue is the lack of a convenient "create jest test" context menu option. I used to have jest installed as a global dependency, but in attempting to get the jest (i.e., create test) context menus to show up, I switched to installing jest-cli globally and saving jest as a dev dependency of each function. That gave me the ability to run individual tests in manually created configurations, but still no context menu option.

Secondly, I can't get syntax highlighting without installing TypeScript.

Is this the expected behavior? I was told WebStorm functionality is subsumed by IDEA (or at least that's how I interpreted [this](https://intellij-support.jetbrains.com/hc/en-us/requests/1164771)), and I know I've seen the context menu affordances. Never had jest syntax highlighting without community stubs though.

9 comments

>I switched to installing jest-cli globally and saving jest as a dev dependency of each function. That gave me the ability to run individual tests in manually created configurations, but still no context menu option.

Works fine for me - if either jest-cli or jest are installed locally and added to dev dependencies, context actions are there. Can you share the project that shows up the issue?

 

>I can't get syntax highlighting without installing TypeScript. Is this the expected behavior?

 

Yes - as Jest module itself doesn't define describe(), test(), etc anywhere, they can't be resolved during static code analysis unless the library stubs are available

0

What do you mean by share? (And how did you quote text from my post?)

It's a work project. I could replicate the structure and share the replica.

 

 

0

If you can't share a project, try creating a sample app with similar structure. I don't need your actual source files, it can be a dummy project with similar configuration. But you should be able to recreate the issue with it - providing a project that doesn't show up any issues makes no sense

 

>And how did you quote text from my post?

there are no special actions for this :( To quote a text, I enter `>` to mark the quotation start, and use the italic style to visually highlight it

0

re quote: I'm just trying to figure out if I can use markdown or HTML or something for formatting. (...and I just noticed the WYSIWIG controls.)

Do you want me to zip and attach the project?

Okay... In the new project. I see "Create..." for 'handle.test.js' but not 'schemas.test.js'.

I'm guessing it's because the tests are generated.

How do I include the source or attach?

0

It's not working for this.

schemas.test.js

"use strict";

const fs = require('fs');
const path = require('path');
const Joi = require('joi');
const JOI_CONF = require('./joi.config.json');

const examplesDir = __dirname + "/examples";
const schemasDir = __dirname + "/schemas";

fs.readdirSync(schemasDir)
.filter(s => s.endsWith('.schema.js'))
.map(s => path.relative(__dirname, s))
.forEach(schema =>
{
const name = path.basename(schema, '.schema.js');
const module = `./schemas/${name}.schema.js`;
const schemaExamplesDir = path.join(examplesDir, name);
const examples = (fs.existsSync(schemaExamplesDir) ? fs.readdirSync(schemaExamplesDir) : [])
.concat(['js', 'json'].map(ext => path.join(examplesDir, `${name}.example.${ext}`)).filter(f => fs.existsSync(f)))
.concat(['js', 'json'].map(ext => path.join(examplesDir, `test.${name}.${ext}`)).filter(f => fs.existsSync(f)))
.map(f => "./" + path.relative(__dirname, f));

describe(`./schemas/${schema}`, () =>
{
it("can be required successfully", () => {require(module)});
it("has at least one example", () => expect(examples.length).toBeGreaterThan(0));
describe("./examples", () => examples.forEach(example => test(example, () =>
{
const raw = require(example);
const hydrated = Joi.attempt(raw, require(module), JOI_CONF);
expect(hydrated).toMatchObject(raw);
})));
});
});
0

handle.test.js

vs.

 

schemas.test.js

0

Adding this on line 11 (in my real project) enables IntelliJ to detect the file as a jest file.


test("detect jest", () => {
const nothing = "todo";
});

0

the problem is that your schemas.test.js is not recognized as a spec file - note its icon: it is a raw js file icon, not the js test one, like the one used for handle.test.js

 

Test file recognition is based on static analysis of a JavaScript file that looks for top-level methods with names matching predefined patterns (e.g. 'describe', 'ddescribe', 'fdescribe', 'it', 'iit', etc). That's why it fails if the suite is wrapped in some other calls/generated dynamically. Related tickets: https://youtrack.jetbrains.com/issue/WEB-8425, https://youtrack.jetbrains.com/issue/WEB-28462, https://youtrack.jetbrains.com/issue/WEB-20442

0

I don't know what a "spec" file  is, but I get the bit about static analysis. It's easy enough to add a random test block somewhere, use the context menu option and then remove it.

 

Thanks for the help!

--Leora

0

Please sign in to leave a comment.