Vscode-jest: dot doesn't update on format a document without save

Created on 2 Jun 2017  路  16Comments  路  Source: jest-community/vscode-jest

When you run Jest, it put some passed and failed dots in tests, but if you have to format the text, the dots keeps in the middle of the text. Not a big problem at all, but I think we should improve the tool.

bug needs information coverage

All 16 comments

Yeah, sure, I think that's about using the document edit API from vscose to update the dots - it's just a matter of adding it, I've been hesitant because it feels like a lot of code to be running all the time but maybe if we had a heuristic for updating them like total number of lines of code has changed?

Yes @orta, I will try to develop this feature and do some tests on Saturday.

Does this work the way you expect it to now? Seems like they update position (but not the state based on the unsaved document contents).

Looks like we can improve this quite a bit. The dots are displayed every time the document changes, and not configured to "stick" to the test block. Here's an annotated "call graph" that walks through how the dots are unnecessarily applied every time the file changes.

// extension.ts
activate(context) {
  context.subscriptions.push(
    ...registerFileChangeWatchers(instance)
  )
}

// fileChangeWatchers.ts
registerFileChangeWatchers(extension) {
  vscode.workspace.onDidChangeTextDocument({ contentChanges, document }) => {
    extension.triggerUpdateDecorations(editor)
  })
}

// JestExt.ts
triggerUpdateDecorations(editor) {
  showCoverageOverlay(editor, this.coverage)
  // The coverage would have changed, but we haven't run the tests with the unsaved buffer

  if (!canUpdateDecorators(editor)) { ... }
  // Only changes if the Jest settings for testMatch or testRegex change

  updateDotDecorators(editor)
  // The dots may change, but we haven't run the tests with the unsaved buffer
}

// Coverage/overlay.ts
showCoverageOverlay(editor) {
  // Decorators applied using stale coverage. 
  // These decorators don't have a rangeBehavior set.
}

// JestExt.ts
canUpdateDecorators(editor) {
  wouldJestRunURI(uri)
}

wouldJestRunURI(
  // Return value only changes when Jest settings for testMatch or testRegex change
}

updateDotDecorations() {
  // The sorted test results may change, but we haven't run tests with the unsaved buffer.
  // Until then the sorted test results, dot decorations, Debug CodeLens, and inline errors don't change.

  // The dot decorators and inline errors don't have the rangeBehavior set.
  // Not sure how to keep the CodeLens following the decorator position. Hrm ...
}

Since we're already showing stale data, I'll submit a PR with GIFs demonstrating the behavior before and after for the:

  • dot decorations
  • inline error message
  • Debug CodeLens
  • coverage

The dots are displayed every time the document changes

Dang!

Even if we fix this up, we'll still end up with annotations in the wrong spot of a file that opens with unsaved changes. :cry:

After 2.5.6, I'm getting an issue with the decorators never updating. They are green for every status type. Perhaps adding an option to disable these decorators might be a good idea as well?
image

Can you share a repo to reproduce the issue @jonathandelgado? I'll look into it right now.

@seanpoulter Good call! I went ahead and created one here https://github.com/jonathandelgado/vscode-jest-bug

Please let me know if you reproduce, I'll dig in on the debugger this weekend and get it figured out either way.

Thanks @jonathandelgado! Any chance you're running on Windows? Your repo looks AOK on my Linux dev machine for the changes from 2.5.5 to 2.5.6. On my Windows box it's coming up all "unkown" tests.

@seanpoulter Yeah, Windows. I guess that complicates things a bit if it's a platform issue. I'll still try to debug it and get back to you. I did a quick search on issues and the readme for any known Windows issues, so I had assumed it was cross-platform, glad you checked it.

Thanks @jonathandelgado, your repo was really helpful. I recently introduced test result caching using the document path from VS Code. It's always got a lower case drive letter on Windows, which doesn't match what Jest give us.

馃憦 impressive debugging

And here I was just feeling guilty @orta. :relaxed:

@jonathandelgado, @orta just shipped the bug fix in 2.5.7 :rocket:. Thanks for reporting the bug!

looks like this issue should be fixed already, feel free to reopen otherwise

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dandv picture dandv  路  17Comments

therazor picture therazor  路  36Comments

zeroEvidence picture zeroEvidence  路  28Comments

luisrudge picture luisrudge  路  27Comments

qwerty2k picture qwerty2k  路  26Comments