{"id":19911051,"url":"https://github.com/streetsidesoftware/jest-mock-vscode","last_synced_at":"2025-07-05T05:06:22.345Z","repository":{"id":54423325,"uuid":"522139453","full_name":"streetsidesoftware/jest-mock-vscode","owner":"streetsidesoftware","description":"VS Code Mock for jest","archived":false,"fork":false,"pushed_at":"2025-06-14T12:01:40.000Z","size":1457,"stargazers_count":19,"open_issues_count":7,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-14T13:18:34.161Z","etag":null,"topics":["jest","mock","testing","vitest","vscode","vscode-extension"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/streetsidesoftware.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["streetsidesoftware"],"patreon":"streetsidesoftware","open_collective":"code-spell-checker","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2022-08-07T06:56:29.000Z","updated_at":"2025-06-10T12:28:51.000Z","dependencies_parsed_at":"2023-02-19T07:10:26.784Z","dependency_job_id":"50940890-73ca-40d8-9de6-5153dfcb9f87","html_url":"https://github.com/streetsidesoftware/jest-mock-vscode","commit_stats":{"total_commits":116,"total_committers":5,"mean_commits":23.2,"dds":0.6896551724137931,"last_synced_commit":"cfdf48797a0235e0d72693e6198ccd535f86f06e"},"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"purl":"pkg:github/streetsidesoftware/jest-mock-vscode","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streetsidesoftware%2Fjest-mock-vscode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streetsidesoftware%2Fjest-mock-vscode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streetsidesoftware%2Fjest-mock-vscode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streetsidesoftware%2Fjest-mock-vscode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/streetsidesoftware","download_url":"https://codeload.github.com/streetsidesoftware/jest-mock-vscode/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streetsidesoftware%2Fjest-mock-vscode/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259826847,"owners_count":22917674,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jest","mock","testing","vitest","vscode","vscode-extension"],"created_at":"2024-11-12T21:23:21.013Z","updated_at":"2025-07-05T05:06:22.323Z","avatar_url":"https://github.com/streetsidesoftware.png","language":"TypeScript","funding_links":["https://github.com/sponsors/streetsidesoftware","https://patreon.com/streetsidesoftware","https://opencollective.com/code-spell-checker"],"categories":[],"sub_categories":[],"readme":"# VS Code Mocks for Jest and Vitest\n\nThis packages is was created to help with the painful process of running unit tests on VS Code extensions.\n\nIt was create to support [Code Spell Checker](https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker).\n\n## Installation\n\n```sh\nnpm install --save-dev jest-mock-vscode\n```\n\n## Jest\n\nBased upon [Manual Mocks · Jest](https://jestjs.io/docs/manual-mocks) add the following file to your project:\n\n**`__mocks__/vscode.js`**\n\n\u003c!--- @@inject: test-packages/jest-integration/src/__mocks__/vscode.js ---\u003e\n\n```js\n/* eslint-disable @typescript-eslint/no-require-imports */\n\nmodule.exports = require('jest-mock-vscode').createVSCodeMock(jest);\n```\n\n\u003c!--- @@inject-end: test-packages/jest-integration/src/__mocks__/vscode.js ---\u003e\n\n### Usage Jest\n\n#### Example Test `vscode.workspace`\n\n\u003c!--- @@inject: test-packages/jest-integration/src/sample.workspace.test.ts ---\u003e\n\n```ts\nimport type { WorkspaceFolder } from 'vscode';\nimport { Uri, workspace } from 'vscode';\n\nconst rootUri = Uri.file(__dirname);\nconst workspaceFolder1: WorkspaceFolder = {\n  uri: Uri.joinPath(rootUri, 'Folder1'),\n  name: 'Folder1',\n  index: 0,\n};\n\nconst workspaceFolder2: WorkspaceFolder = {\n  uri: Uri.joinPath(rootUri, 'Folder2'),\n  name: 'Folder2',\n  index: 1,\n};\n\ndescribe('workspace', () =\u003e {\n  test('getWorkspaceFolder', () =\u003e {\n    const uri = Uri.joinPath(workspaceFolder1.uri, 'code.test.ts');\n    const uri2 = Uri.joinPath(workspaceFolder2.uri, 'test.txt');\n\n    const spy = jest.spyOn(workspace, 'workspaceFolders', 'get');\n    spy.mockReturnValue([workspaceFolder1, workspaceFolder2]);\n\n    expect(workspace.workspaceFolders).toEqual([workspaceFolder1, workspaceFolder2]);\n    expect(workspace.getWorkspaceFolder(uri)).toEqual(workspaceFolder1);\n    expect(workspace.getWorkspaceFolder(uri2)).toEqual(workspaceFolder2);\n  });\n});\n```\n\n\u003c!--- @@inject-end: test-packages/jest-integration/src/sample.workspace.test.ts ---\u003e\n\n## Vitest\n\nBased upon:\n\n- [`vi.Mock()` | Vitest](https://vitest.dev/api/vi.html#vi-mock)\n- [Mocking | Guide | Vitest](https://vitest.dev/guide/mocking.html#modules)\n- [Mock Functions | Vitest](https://vitest.dev/api/mock.html)\n\nYou can add the following file to your project:\n\n**`__mocks__/vscode.cts`**\n\n\u003c!--- @@inject: test-packages/vitest-integration/__mocks__/vscode.cts ---\u003e\n\n```typescript\nimport { createVSCodeMock } from 'jest-mock-vscode';\nimport { vi } from 'vitest';\n\nconst vscode = createVSCodeMock(vi);\n\nmodule.exports = vscode;\n```\n\n\u003c!--- @@inject-end: test-packages/vitest-integration/__mocks__/vscode.cts ---\u003e\n\n### Usage Vitest\n\n\u003c!--- @@inject: test-packages/vitest-integration/src/sample.workspace.test.ts ---\u003e\n\n```ts\nimport { afterEach, describe, expect, test, vi } from 'vitest';\nimport { Uri, window, workspace, type WorkspaceFolder } from 'vscode';\n\nvi.mock('vscode');\n\nconst testFileUri = Uri.file(__filename);\nconst rootUri = Uri.file(__dirname);\nconst workspaceFolder1: WorkspaceFolder = {\n  uri: Uri.joinPath(rootUri, 'Folder1'),\n  name: 'Folder1',\n  index: 0,\n};\n\nconst workspaceFolder2: WorkspaceFolder = {\n  uri: Uri.joinPath(rootUri, 'Folder2'),\n  name: 'Folder2',\n  index: 1,\n};\n\ndescribe('vscode.workspace', () =\u003e {\n  afterEach(() =\u003e {\n    vi.resetAllMocks();\n  });\n\n  test('getWorkspaceFolder', () =\u003e {\n    const uri = Uri.joinPath(workspaceFolder1.uri, 'code.test.ts');\n    const uri2 = Uri.joinPath(workspaceFolder2.uri, 'test.txt');\n\n    const spy = vi.spyOn(workspace, 'workspaceFolders', 'get');\n    spy.mockReturnValue([workspaceFolder1, workspaceFolder2]);\n\n    expect(workspace.workspaceFolders).toEqual([workspaceFolder1, workspaceFolder2]);\n    expect(workspace.getWorkspaceFolder(uri)).toEqual(workspaceFolder1);\n    expect(workspace.getWorkspaceFolder(uri2)).toEqual(workspaceFolder2);\n  });\n\n  test('openTextDocument', async () =\u003e {\n    const uri = testFileUri;\n    const doc = await workspace.openTextDocument(uri);\n    expect(doc.uri).toEqual(uri);\n    expect(doc.getText()).toContain(\"vi.mock('vscode');\");\n  });\n});\n\ndescribe('vscode.window', () =\u003e {\n  afterEach(() =\u003e {\n    vi.resetAllMocks();\n  });\n\n  test('showTextDocument', async () =\u003e {\n    const uri = testFileUri;\n    const doc = await workspace.openTextDocument(uri);\n    const editor = await window.showTextDocument(doc);\n    expect(editor.document).toBe(doc);\n  });\n});\n```\n\n\u003c!--- @@inject-end: test-packages/vitest-integration/src/sample.workspace.test.ts ---\u003e\n\n### Using `vi.mock` factory\n\n```ts\nimport { afterEach, describe, expect, test, vi } from 'vitest';\nimport { Uri, workspace, type WorkspaceFolder } from 'vscode';\n\nvi.mock('vscode', async () =\u003e (await import('jest-mock-vscode')).createVSCodeMock(vi));\n\ndescribe(/* ... */);\n```\n\n## Reading Fixtures as TextDocument\n\n```ts\nimport { readTextDocument } from 'jest-mock-vscode';\nimport { Uri } from 'vscode';\n\n// vi.mock('vscode')\n\nconst pathToFixture = __filename;\n\nconst doc = await readTextDocument(Uri.file(pathToFixture));\n```\n\n## Default Mock Implementations for most VS Code classes and interfaces\n\nHere are a few of items that have been implemented. Most of them are based upon the code from VS Code.\n\n- CodeAction\n- ColorTheme\n- CompletionItem\n- Diagnostic\n- language\n- MarkdownString\n- Position\n- Range\n- Selection\n- TaskGroup\n- TextDocument\n- TextEditor\n- Uri\n- workspace\n- WorkspaceEdit\n\n## Migrating from 3.x to 4.x\n\n- No migration should be necessary.\n\n### Changes\n\n- `@types/vscode` is now a peer dependency\n\n## Migrating from 2.x to 3.x\n\nMigration is only necessary if you used any of the following:\n\n```js\nnew MockWorkspace(...)\nnew MockTabGroups(...)\nnew MockTextEditor(...)\n```\n\nIt is now necessary to use a create function.\n\n- `new MockWorkspace(...)` -\u003e `createWorkspace(...)`\n- `new MockTabGroups(...)` -\u003e `createMockTabGroups(...)`\n- `new MockTextEditor(...)` -\u003e `createMockTextEditor(...)`\n\n## Migrating from 1.x to 2.x\n\n**`__mocks__/vscode.js`**\n\n```diff\n-module.exports = require('jest-mock-vscode');\n+module.exports = require('jest-mock-vscode').createVSCodeMock(jest);\n```\n\n## Notes\n\nThe idea is to use as much of the VS Code as possible. For example the `vscode-uri` is used to implement the `Uri` class. If Microsoft publishes a set of core classes, they will be used.\n\n## License\n\n- Code copied from VS Code belongs to Microsoft.\n- All other code falls under the MIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstreetsidesoftware%2Fjest-mock-vscode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstreetsidesoftware%2Fjest-mock-vscode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstreetsidesoftware%2Fjest-mock-vscode/lists"}