Skip to content

fix #37570 add RELATIVE_FILEPATH snippet variable - #114208

Merged
Johannes Rieken (jrieken) merged 3 commits into
microsoft:masterfrom
gjsjohnmurray:fix-37570
Jan 14, 2021
Merged

Johannes Rieken (jrieken) merged 3 commits into
microsoft:masterfrom
gjsjohnmurray:fix-37570

Conversation

@gjsjohnmurray

Copy link
Copy Markdown
Contributor

This PR fixes #37570 by adding a new snippet variable RELATIVE_FILEPATH

@gjsjohnmurray

Copy link
Copy Markdown
Contributor Author

Johannes Rieken (@jrieken) I attempted to add tests for the new variable into snippetVariables.test.ts but the following imports that I needed were flagged as import violations and prevented the push.

import { LabelService } from 'vs/workbench/services/label/common/labelService';
import { TestEnvironmentService, TestPathService } from 'vs/workbench/test/browser/workbenchTestServices';
import { TestContextService } from 'vs/workbench/test/common/workbenchTestServices';

I don't know the right way to solve this.

@gjsjohnmurray

Copy link
Copy Markdown
Contributor Author

I resolved this by adding // eslint-disable-next-line code-import-patterns ahead of each of those lines. Don't know if this is permitted in unit tests, but at least it let me push the new tests for review.

@jrieken

Copy link
Copy Markdown
Contributor

Don't know if this is permitted in unit tests, but at least it let me push the new tests for review.

No, this isn't permitted. To mock services, I would use the mock util. This is an sample of how it is used:

const labelService = new class extends mock<ILabelService>() {

With mock you should be quick to make the compiler happy and be required to implement the minimun of the service that your test needs

@gjsjohnmurray

Copy link
Copy Markdown
Contributor Author

My concern about providing a mock label service is that I'll naturally make the mock service do what I reckon is the right thing when the RELATIVE_PATH code calls it with options { relative: true, noPrefix: true }, but the value of the test will be diminished because it's not calling the real method in src/vs/workbench/services/label/common/labelService.ts. So if the real method ever gets changed in a way that adversely affects the call from RELATIVE_PATH resolution, the unit test won't detect this.

@jrieken

Copy link
Copy Markdown
Contributor

Well, you aren't writing a test for how a certain label service works but for a snippet variable that should use some instance of that service

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add relative directory/filepath support to snippets

2 participants