Skip to content

Great effort, but can't make this work #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tomitrescak opened this issue Mar 6, 2018 · 17 comments
Closed

Great effort, but can't make this work #2

tomitrescak opened this issue Mar 6, 2018 · 17 comments

Comments

@tomitrescak
Copy link

Hi. Not sure why I can't make this work in vscode.

This is my tsconfig.json

"plugins": [
      {
        "name": "typescript-snapshots-plugin",
        "snapshotCallIdentifiers": ["matchSnapshot"]
      }
    ]

this is my tasks.json

{
  "version": "0.1.0",
  "command": "./node_modules/.bin/tsc",
  "isShellCommand": true,
  "args": ["-w", "-p", "./tsconfig.json"],
  "showOutput": "silent",
  "isBackground": true,
  "problemMatcher": "$tsc-watch"
}

I have my environment set to local Typescript "2.7.2"

and this is the test file:

it ('ok', () => {
   'test'.should.matchSnapshot();
})

I have no options for snapshot when hovering over matchSnapshot

@asvetliakov
Copy link
Owner

asvetliakov commented Mar 6, 2018

Hello,
Could you make a minimal repro repository? I just tried your use case and it worked for me

@tomitrescak
Copy link
Author

tomitrescak commented Mar 7, 2018

Please check out this repo: https://github.com/tomitrescak/semantic-ui-mobx/tree/RemoveValue
In src/tests/index.test.tsx you find following code:

it('fails', () => {
  const test = new Test();

  // works
  expect(test.validate()).toMatchSnapshot();

  // does not work
  test.validate().should.matchSnapshot();
});

@asvetliakov
Copy link
Owner

@tomitrescak
Thank you for the repro. For some reason your repo works for me:
screen shot 2018-03-07 at 03 15 37

However, the first one you've marked with //works doesn't work because you overwrote snapshotCallIdentifiers in tsconfig.json and didn't specify toMatchSnapshot.

@asvetliakov
Copy link
Owner

Stupid question - but did you restart the TS server/VScode after changing tsconfig.json ?

@tomitrescak
Copy link
Author

@asvetliakov thanks for your help. Restart on that small repo seemed to solve the issue, but it does not work on my big repo. I will investigate. There is one problem and that is that the custom snapshot package I use allows to rename the snapshot and then these snapshots are not found. I'll just probably stop renaming. Will post back and close the issue once all is solved.

@asvetliakov
Copy link
Owner

asvetliakov commented Mar 7, 2018

ah sorry, but specifying custom snapshot names (such as toMatchSnapshot("myCustomName")) is not supported. I can look into this but no estimates 😸

@tomitrescak
Copy link
Author

Any advice on how can I debug this? I just can't make it work im my big project. In my small projects it works. I tried to put console.logs in the .js files, but then the plugin is not loaded at all.

@asvetliakov
Copy link
Owner

If you can provide the full copy of the one test file which doesn't work with corresponding snapshot - it would be best. The errors/missing references/imports/etc... shouldn't matter, just single test file and snapshot.

The console.log won't work in the plugin since the plugins must do logging via something like project.projectService.logger.info("")

The error may be caused by few things:

  1. TS fails to parse test file, i.e. determine it/describe blocks due to some unsupported TS syntax
  2. snapshot file is not located in the known directory __snapshots__ or has different name/extension, for example test.js.snap instead of test.ts.snap
  3. Dynamic it/describe blocks or test/suite names, see dynamic test name #1

Also enabling logging in the TS server and checking it may provide some clues too

@asvetliakov
Copy link
Owner

asvetliakov commented Mar 7, 2018

If you want to debug by self, you need to pass info.project.projectService.logger into tryGetSnapshotForPosition function in index.js.

Then you can log by using this statement:

logger.info("Some log");

pass logger further if needed.

@asvetliakov
Copy link
Owner

@tomitrescak
Ping

@tomitrescak
Copy link
Author

@asvetliakov thanks for your answers. I debugged it with your help and found out that the test structure got in the way as I was using a custom TDD interface (not only it, describe).

@christianvogt
Copy link

@asvetliakov I can't get the plugin to work on 3 different projects. I even tried the project noted in a comment above and it doesn't work. Can you please retest with the project above and let me know if it does still work?

@asvetliakov
Copy link
Owner

@christianvogt Did you switch the TS version in VS code to workspace version?

@christianvogt
Copy link

@asvetliakov I have this in my vscode settings: "typescript.tsdk": "./node_modules/typescript/lib",. Is this what you meant or is there another setting?

I also checked out the project above and it doesn't work for me.

@asvetliakov
Copy link
Owner

@christianvogt Just setting the setting doesn't work since vscode 1.13 or so (i don't remember exactly). You need manually to click on the TS version and choose "Use workspace typescript version" (once per workspace folder) otherwise it will continue to use the bundled TS.

I'll recheck the project in comment above today and let you know.

Also, you can try to enable TS server logging in vscode and check in the log if the plugin was loaded correctly.

@asvetliakov
Copy link
Owner

asvetliakov commented Aug 9, 2018

@christianvogt
The repo in comments above works fine - either with TS 2.7.2 / Plugin 1.1.1 or TS 3.0.1 (after updating to latest version) / Plugin 1.2.0

@christianvogt
Copy link

@asvetliakov clicking on the version and choosing to use workspace made it work! Thanks for the tip.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants