jest-community / jest-editor-support

A module for handling editor to jest integration
MIT License
28 stars 21 forks source link

Test with missing implementation doesn't parse correctly #31

Closed rossknudsen closed 4 years ago

rossknudsen commented 4 years ago

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.

seanpoulter commented 4 years ago

So ... I don't know how either the TypeScript and Babel parsers in this package would handle a test without a callback, but I since I can't find any reference to the "declaration exception" in this package or your extension I don't think your immediate issue is with this package.

I've had a quick look and found "declaration exception" in the Jasmine test runner in facebook/jest. It throws an Error. You'll also find the error that's reported on when you run Jest on the console in that file: https://github.com/facebook/jest/blob/d7a7b4294a4507030f86fe4f78e1790f53d0bda9/packages/jest-jasmine2/src/jasmine/Env.ts#L545-L549

Does that help? I'd suggest doing a code read to find out why you'd end up throwing two separate errors depending on how it's called from your extension. You might get some insight running Jest and your extension with some breakpoints set or pausing on exceptions thrown. Good luck!

--

Are you OK if we close the issue here?

rossknudsen commented 4 years ago

Hey, thanks for the thoughts. I did find the encountered a declaration exception string in the Jest source. It seems that it it will output this message irrespective of whether the name of the test is available or not. I'll raise the issue there and see whether it is "by design" or whether they would accept returning the name of the test if it is available.

SimenB commented 4 years ago

Doesn't seem like you opened up an issue, but happy to take a PR including the name of the test in the error 👍

rossknudsen commented 4 years ago

Doesn't seem like you opened up an issue, but happy to take a PR including the name of the test in the error 👍

Sorry, yes I was trying to get to the bottom of the problem and raise a PR for it. Hopefully soon!

rossknudsen commented 4 years ago

Issue raised in Jest: facebook/jest#9515