| 1 | name: Write Core Unit Test |
| 2 | description: Generate unit tests for core utilities |
| 3 | --- |
| 4 | Write jest tests for the provided code. |
| 5 | Use jest version ^29 (e.g. jest 29.7.0) |
| 6 | |
| 7 | Use best practices. Be clear and concise. |
| 8 | Aim for 100% code coverage where reasonable. |
| 9 | Multiple tests can be written, split up tests for best clarity and readability. |
| 10 | Only use typescript, and if the file/code is not typescript, warn the user. |
| 11 | IMPORTANT Use ESM to import modules, do NOT use `require` anywhere |
| 12 | Tests are to be described in an adjacent file with a path identical except for a `.test.ts` rather than a `.ts` file extension |
| 13 | Use double quotes (or backticks if needed) for strings |
| 14 | |
| 15 | The code being tested is used in IDE extensions, and it: |
| 16 | - accesses code workspaces through the IDE ("workspace directories") |
| 17 | - persists extension-related data to the the local machine of the user ("global directory"), and |
| 18 | - uses configuration via a `ConfigHandler`, which is stored in either the global directory (default) or accessed via a remote "control plane" using the `ControlPlaneClient` |
| 19 | |
| 20 | Jest testing setup includes |
| 21 | - @core/test/jest.global-setup.ts initializes a temporary global directory, which is where files that store persisted extension data live. |
| 22 | - @core/test/testDir.ts provides utils for creating and working with the temporary workspace directory. Use `setUpTestDir` and `tearDownTestDir` explicitly in tests that work with workspace files |
| 23 | - @core/test/jest.setup-after-env.ts gives tests access to node and jest globals |
| 24 | |
| 25 | @core/test/fixtures.ts provides fixtures that should be used in tests to emulate extension behavior |
| 26 | - import `testIde` for IDE/workspace operations |
| 27 | - import `testConfigHandler` for any ConfigHandler needs |
| 28 | - import `testControlPlaneClient` for control plane operations |
| 29 | - import `ideSettingsPromise` for any IdeSettings needs |
| 30 | - import `testLLM` for any ILLM/BaseLLM needs. Set the `completion` property to the desired completion, e.g. `testLLM.completion = "Desired completion";` |
| 31 | |
| 32 | Do NOT write tests for any files in `core/test`, only use them as helpers for testing other files. If no other files are provided, warn the user and write no tests. |
| 33 | |
| 34 | IMPORTANT: Do NOT mock the fixtures above other than using `jest.spyOn`. DO mock 3rd party modules, etc. when sensible. |
| 35 | Instead, generate actual mock files and data for operations |
| 36 | Pure mocks should only be used to emulate specific network responses/error or hard-to-duplicate errors, or to prevent long-duration tests |
| 37 | |
| 38 | Additional types can be imported from @core/index.d.ts |
| 39 | If any needed types, functions, constants, or classes are still not found, warn the user and do not generate tests. |
| 40 | |
| 41 | Write the comment "// Generated by continue" at the top of the generated code/file (not the filepath) |