Giter Club home page Giter Club logo

jest-editor-support's People

Contributors

connectdotz avatar dependabot[bot] avatar ehaynes99 avatar firsttris avatar jmarceli avatar mjamin avatar nithinpeter avatar omjadas avatar orta avatar pmcelhaney avatar rossknudsen avatar seanpoulter avatar simenb avatar stephtr avatar thesench avatar xlarsx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

jest-editor-support's Issues

it.each node range doesn't include callback body

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
        });

Cannot find @babel/traverse

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!

Parsing fails when using test.each`table`(name, fn, timeout)

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);
});

reference

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)

getSettings throws error with paths with spaces in Windows

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));

License of some modules

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

  • LICENSE file in the root directory of this source tree. An additional grant
  • of patent rights can be found in the PATENTS file in the same directory._**

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.

Add API documentation

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

Test with missing implementation doesn't parse correctly

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.

  • jest-editor-support: ^27.1.0
  • jest: 25.1.0

Parser crashes on TypeScript inline type imports

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!

Improvement: Our build process doesn't fail on TypeScript errors

One of our library consumers opened PR #42 because:

When trying to compile a Typescript project that depends on this library it was throwing an error


Expected behaviour
We catch TypeScript errors in our CI/CD pipeline

Actual behaviour
😞

Steps to reproduce the issue
- Revert PR #42

What's the status of detecting describe blocks?

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?

parse does not find name for test.each block

      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
      ]
    }

When using jest-editor-support from cdn, fails to locate the parse named method

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 :)

Support additional `describe` aliases

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.

Typescript parameter decorator support

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!

Parsing fails upon encountering optional chaining

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");
    });
});

Does not parse function.name syntax

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

Possibility of adding --testLocationInResults support

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.

Does not parse `it` when used with more than one modifier

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)

Track conversion to Typescript

  • JS -> TS conversion
    • update tsconfig.json - ensure that more strict type checking is enabled. Probably align with a config from facebook/jest, jest-community/vscode-jest, or microsoft/TypeScript-Babel-Starter
    • update eslint.js similar to above
    • remove flowconfig and flow dependencies and build scripts
    • remove babel.config.js and update build scripts to use tsc

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.