jest-community / jest-editor-support Goto Github PK
View Code? Open in Web Editor NEWA module for handling editor to jest integration
License: MIT License
A module for handling editor to jest integration
License: MIT License
The version of @babel/[email protected] has been flagged with vulnerability: https://security.snyk.io/vuln/SNYK-JS-BABELTRAVERSE-5962462. This can cause problems for users that have security scans that run in their pipelines, also upgrading will remove the vulnerability.
Here is the code that is referencing the package: https://github.com/jest-community/jest-editor-support/blob/master/package.json#L65C16-L65C16
I noticed, that the it.each
doesn't include the node range for the callback body
See start
and end
markers below:
/*start*/it.each([
['some'],
])('some', async (some: string) => /*end*/{
// Some code
});
When I try to use the package I get Cannot find @babel/traverse
error. Maybe the dependency listed should be changed to @babel/traverse
. Manually installing @babel/traverse
did fix the problem for me!
From the Jest docs, you can structure a describe or a test like so
test.each`
a | b | expected
${1} | ${1} | ${2}
${1} | ${2} | ${3}
${2} | ${1} | ${3}
`('returns $expected when $a is added $b', ({a, b, expected}) => {
expect(a + b).toBe(expected);
});
jest-editor-support does not recognize these expressions as tests in either v28.0.0 or v27.2.0.
I think this is similar, but different from the discussion had in #29 (comment)
When passing a workspace to getSettings
function throws error if paths contain spaces.
Repro:
// test-jest-editor-support.js
const support = require("jest-editor-support");
const {ProjectWorkspace, getSettings} =support;
const projectWorkspace = new ProjectWorkspace(
"C:\\Users\\rossk\\Desktop\\cra test",
"C:\\Users\\rossk\\Desktop\\cra test\\node_modules\\.bin\\jest.cmd",
"C:\\Users\\rossk\\Desktop\\cra test\\jest.config.js",
20,
undefined,
false,
false,
);
getSettings(projectWorkspace).then(results => console.log(results)).catch(error => console.error(error));
Hi, my team would use jest-editor support and to approve that I've to verify all its licenses.
Now I've seen that some modules (i.e. jest-editor-support/src/tests/snapshot.test.js) show this header:
*_ This source code is licensed under the BSD-style license found in the
other modules instead refers to MIT license, but in the root directory of the source I cannot see any license file.
Could you please clarify me what are the licenses?
Thanks for your support on this.
Hi
The project seems great but it's hard to understand how to use it without an API documentation.
It will be nice if you guys could have a little descriptors about the API
Thanks
I wrote the following test:
describe("describe with malformed test", () => {
test("test with missing callback")
})
Notice that it is missing the implementation for the test (the second argument). Running Jest on the console I get the following output:
FAIL src/__tests__/newTest.test.ts
describe with malformed test
× encountered a declaration exception (7ms)
● describe with malformed test › encountered a declaration exception
Missing second argument. It must be a callback function. Perhaps you want to use `test.todo` for a test placeholder.
1 | describe("describe with malformed test", () => {
> 2 | test("test with missing callback")
| ^
3 | })
4 |
at Env.it (node_modules/jest-jasmine2/build/jasmine/Env.js:633:19)
at Suite.test (src/__tests__/newTest.test.ts:2:5)
at Object.describe (src/__tests__/newTest.test.ts:1:1)
Notice how the name of the test is lost and jest-editor-support
returns the test name as "encountered a declaration exception" rather than "test with missing callback" - which causes an error in my extension. Since the Jest output appears to be incorrect, it may be that the error is in that package instead of here. Let me know if you think I should file a bug there instead.
@rossknudsen, @connectdotz, and @seanpoulter have discussed changing the ProjectWorkspace API/Interface. See #45 (comment).
I'm pretty sure this is the right place to create this issue, but if not let me know.
I'm trying to use vscode to debug some of my unit tests. One of my test files uses the relatively new inline type imports feature to condense imports:
import fs from 'node:fs';
import path from 'node:path';
import assert from 'node:assert';
import { EOL } from 'node:os';
import { isNativeError } from 'node:util/types';
import { declare } from '@babel/helper-plugin-utils';
import { asMockedFunction, type AnyFunction } from '@xunnamius/jest-types';
import babel from '@babel/core';
However, the Jest plugin for vscode crashes, giving me the following error as all IDE UI decorations disappear:
/repos/babel-plugin-tester/test/plugin-tester.test.ts: failed to parse test results: SyntaxError: Unexpected token, expected "," (7:32)
Removing the inline type annotation fixes it. Is this expected behavior (that is: am I missing a babel plugin or something)?
Thanks for reading!
I'm creating this issue to keep track of the suggestion from #41 and set a v4.0 milestone.
Acceptance criteria
#41 (comment):
We could just rename theProjectWorkspace.pathToJest
toProjectWorkspace.jestCommandline
pathToJest
as a deprecated value.I see there is some code in babylon_parser.js
for extracting describe blocks, but I don't see that code in any of the releases. With the move out of the Jest mono-repo it's a bit hard to see when the last release was cut.
Is this a feature which has been added but not yet released?
test.each([
[1, 1, 2],
[1, 2, 3],
[2, 1, 3]
])('wtf', (a, b, expected) => {
expect(a + b).toBe(expected);
});
https://jestjs.io/docs/en/api#testeachtablename-fn-timeout
(note: its not possible to put a test.each inside a "it" or a "test" )
parser outputs a warning if he detects such a block.
console.warn node_modules/jest-editor-support/build/parsers/typescript_parser.js:96
**NamedBlock but no name found for it tsNode= NodeObject** {
pos: 442,
end: 526,
flags: 0,
modifierFlagsCache: 0,
transformFlags: 0,
parent: undefined,
kind: 195,
expression: NodeObject {
pos: 442,
end: 459,
flags: 0,
modifierFlagsCache: 0,
transformFlags: 0,
parent: undefined,
kind: 193,
expression: IdentifierObject {
pos: 442,
end: 454,
flags: 0,
modifierFlagsCache: 0,
transformFlags: 0,
parent: undefined,
kind: 75,
escapedText: 'test'
},
questionDotToken: undefined,
name: IdentifierObject {
pos: 455,
end: 459,
flags: 0,
modifierFlagsCache: 0,
transformFlags: 0,
parent: undefined,
kind: 75,
escapedText: 'each'
}
},
questionDotToken: undefined,
arguments: [
NodeObject {
pos: 460,
end: 525,
flags: 0,
modifierFlagsCache: 0,
transformFlags: 0,
parent: undefined,
kind: 191,
multiLine: true,
elements: [Array]
},
pos: 460,
end: 525
]
}
Hi there,
Maybe it is a silly mistake, but I am trying to use the parse method in one tampermonkey script that I am transpiling with vite-monkey-plugin. The rest of the set up was crazy to get working, but in the end managed to make it work.
Now I am trying to use the parse method in one piece of typescript code:
import { parse } from "https://cdn.jsdelivr.net/npm/jest-editor-support/build/index.min.js";
and calling it like:
const parsedSpecFile = parse(path, contents);
When opening the page that calls this code, it complains without even reaching the part of the code that executes this call:
Uncaught SyntaxError: The requested module 'https://cdn.jsdelivr.net/npm/jest-editor-support/build/index.min.js' does not provide an export named 'parse' (at SpecFileItDescription.tsx:8:10)
As far as I understand, the part that actually generates the named export is in index.js on build folder:
Object.defineProperty(exports, "parse", { enumerable: true, get: function get() { return _parsers["default"]; } });
And in the browser, it gets rightfully detected as:
Object.defineProperty(exports, "parse", { enumerable: !0, get: function() { return _parsers.default } });
So any idea what might cause such a weird behaviour?
Thanks in advance :)
Would you consider support for identifying describe
aliases (like context
)? I've got a client that sets global.context = describe
so they can write tests like:
describe('some method', () => {
context('when something is true', () => {
beforeEach(() => {
// make 'something' true
});
it('does things', () => {
// test
});
});
});
This used to be a jest
feature, and it seems like some folks are still using this global
trick like they are: jestjs/jest#2468.
Sadly, because they use context
, it breaks a vs-code plugin I use (https://github.com/firsttris/vscode-jest-runner) because only describe
blocks are identified by this package.
Hey everyone!
Typescript features 3 kinds of decorators - class-level, method-level and parameter-level.
Only the first two seem to be officially supported in babel 7 - https://babeljs.io/docs/en/babel-plugin-proposal-decorators
But there is a plugin available adding support for these - https://github.com/WarnerHooh/babel-plugin-parameter-decorator
So, I have just been investigating a error within a vscode extension, namely vscode-jest-runner and it will fail to work correctly as soon as parameter decorators are used within jest-typescript files.
Issue here: firsttris/vscode-jest-runner#260
Is it possible to register separate plugins to be included before executing parser?
If not, would you mind to include the plugin by default?
Thanks!
Upon encountering an optional chaining operator, the parsing fails. I am using this in the Jest VS Code Extension, but I have also tried the other popular Jest VS Code Extension, both of which fail and both of which use this library. Here is an example that you can try yourself:
This parses correctly. In VS Code, I can see the "Run | Debug" floating over the tests.
describe("Normalization", () => {
test("adds a module to every assignment", () => {
expect(assignment.module.name).toBe("AuthenticationFramework");
});
});
When you add the question mark (optional chaining operator), it no longer parses correctly.
This does not parse correctly. I cannot see the "Run | Debug" floating over the tests anymore.
describe("Normalization", () => {
test("adds a module to every assignment", () => {
expect(assignment.module?.name).toBe("AuthenticationFramework");
});
});
Using the function.name property in describe blocks is a pattern to allow refactoring to update test names automatically. However this fails the babel parser for jest-editor-support with a "TypeError: failed to update namedBlock" error.
describe(functionDotName.name, () => {
it('should parse', () => {});
});
function functionDotName() {}
Since this is a simple enough expression to parse, I would like to see jest-editor-support look at the member expression for a identifier property with a name of "name" and then return the name as the object name.
Inserted at src/parsers/babel_parser.js#L46:
case 'MemberExpression':
const property = arg.property
if (property && property.type === 'Identifier' && property.name === 'name') {
name = arg.object.name;
break;
}
This issue blocks firsttris/vscode-jest-runner#129
I am working on a test adapter implementation for the VS Code Test Explorer extension and it would be beneficial to have the line number reported with the tests. I found that I can do this by overriding the createProcess
option to inject the --testLocationInResults
argument and pass that along to the createProcess
function from jest-editor-support/build/Process.js
. Would it be beneficial to the project to add this as an option? If so, I would be glad to make an attempt at a PR.
I'd like to reopen the issue found in jestjs/jest#4910 that discusses the use of string literals in test names.
The Jest API includes a handful of modifiers to it
that can be combined: only
/skip
, concurrent
, and each
. Currently, the parser will detect an it
if it has, at most, one modifier on it. This means statements like it.concurrent.each
are not detected.
Unsupported Jest API methods (from https://jestjs.io/docs/en/api):
describe.only.each(table)(name, fn)
describe.skip.each(table)(name, fn)
describe.each`table`(name, fn)
(and all variations above)test.concurrent.each(table)(name, fn, timeout)
test.concurrent.only.each(table)(name, fn)
test.concurrent.skip.each(table)(name, fn)
test.only.each(table)(name, fn)
test.skip.each(table)(name, fn)
test.each`table`(name, fn)
(and all variations above)A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.