test:unit task now includes mock-friendly .spec.ts tests

This commit is contained in:
Riccardo Ferretti
2025-09-25 23:38:20 +02:00
parent 3b5906a1cf
commit dcb951004a
5 changed files with 9 additions and 9 deletions

View File

@@ -25,7 +25,7 @@
"editor.formatOnSaveMode": "file",
"editor.defaultFormatter": "esbenp.prettier-vscode",
"jest.rootPath": "packages/foam-vscode",
"jest.jestCommandLine": "yarn test:unit-with-specs",
"jest.jestCommandLine": "yarn test:unit",
"gitdoc.enabled": false,
"search.mode": "reuseEditor",
"[typescript]": {

View File

@@ -25,7 +25,7 @@ All the following commands are to be executed from the `packages/foam-vscode` di
### Testing
- `yarn test` - Run all tests (unit + integration)
- `yarn test:unit-with-specs` - Run only unit tests (\*.test.ts files and the .spec.ts files marked a vscode-mock friendly)
- `yarn test:unit` - Run unit tests (\*.test.ts files and the .spec.ts files marked a vscode-mock friendly)
- `yarn test:e2e` - Run only integration tests (\*.spec.ts files)
- `yarn lint` - Run linting
- `yarn test-reset-workspace` to clean test workspace
@@ -37,11 +37,10 @@ When running tests, do not provide additional parameters, they are ignored by th
Unit tests are named `*.test.ts` and integration tests are `*.spec.ts`. These test files live alongside the code in the `src` directory. An integration test is one that has a direct or indirect dependency on `vscode` module.
There is a mock `vscode` module that can be used to run most integration tests without starting VS Code. Tests that can use this mock are start with the line `/* @unit-ready */`.
- If you are interested in a test inside a `*.test.ts` file, run `yarn test:unit`
- If you are interested in a test inside a `*.spec.ts` file that starts with `/* @unit-ready */` run `yarn test:unit-with-specs`
- If you are interested in a test inside a `*.test.ts` file, run `yarn test:unit` or inside a `*.spec.ts` file that starts with `/* @unit-ready */` run `yarn test:unit`
- If you are interested in a test inside a `*.spec.ts` file that does not include `/* @unit-ready */` run `yarn test`
While in development we mostly want to use `yarn test:unit-with-specs`.
While in development we mostly want to use `yarn test:unit`.
When multiple tests are failing, look at all of them, but only focus on fixing the first one. Once that is fixed, run the test suite again and repeat the process.
When writing tests keep mocking to a bare minimum. Code should be written in a way that is easily testable and if I/O is necessary, it should be done in appropriate temporary directories.

View File

@@ -49,8 +49,8 @@ This dual-environment capability allows us to:
### Available Commands
- **`yarn test:unit`**: Runs only `.test.ts` files (no VS Code dependencies)
- **`yarn test:unit-with-specs`**: Runs `.test.ts` + `@unit-ready` marked `.spec.ts` files using mocks
- **`yarn test:unit`**: Runs `.test.ts` files (no VS Code dependencies) + `@unit-ready` marked `.spec.ts` files using mocks
- **`yarn test:unit-without-specs`**: Runs only `.test.ts` files
- **`yarn test:e2e`**: Runs all `.spec.ts` files in full VS Code extension host
- **`yarn test`**: Runs both unit and e2e test suites sequentially

View File

@@ -17,6 +17,7 @@
"clean": "lerna run clean",
"build": "lerna run build",
"test": "yarn workspace foam-vscode test",
"test:unit": "yarn workspace foam-vscode test:unit",
"lint": "lerna run lint",
"watch": "lerna run watch --concurrency 20"
},

View File

@@ -711,8 +711,8 @@
"test-reset-workspace": "rm -rf .test-workspace && mkdir .test-workspace && touch .test-workspace/.keep",
"test-setup": "yarn compile && yarn build && yarn test-reset-workspace",
"test": "yarn test-setup && node ./out/test/run-tests.js",
"test:unit": "yarn test-setup && node ./out/test/run-tests.js --unit --exclude-specs",
"test:unit-with-specs": "yarn test-setup && node ./out/test/run-tests.js --unit",
"test:unit": "yarn test-setup && node ./out/test/run-tests.js --unit",
"test:unit-without-specs": "yarn test-setup && node ./out/test/run-tests.js --unit --exclude-specs",
"test:e2e": "yarn test-setup && node ./out/test/run-tests.js --e2e",
"lint": "dts lint src",
"clean": "rimraf out",