Skip to content
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

Add test for bentofile json schema #7

Merged
merged 4 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"ms-vscode-remote.remote-ssh",
"GitHub.copilot",
"redhat.vscode-yaml",
"ms-vsliveshare.vsliveshare"
"ms-vsliveshare.vsliveshare",
"hbenl.vscode-mocha-test-adapter"
]
}
11 changes: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,16 @@
"outFiles": ["${workspaceFolder}/out/**/*.js", "${workspaceFolder}/dist/**/*.js"],
"preLaunchTask": "tasks: watch-tests"
}
// {
// "name": "Extension Tests",
// "type": "extensionHost",
// "request": "launch",
// "runtimeExecutable": "${execPath}",
// "args": [
// "--extensionDevelopmentPath=${workspaceFolder}",
// "--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
// ],
// "outFiles": ["${workspaceFolder}/out/test/**/*.js"]
// }
]
}
17 changes: 16 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,20 @@
"json.validate.enable": true,
"yaml.schemas": {
"./src/resources/yamlSchemas/bentofileSchema.json": "**/*bentofile.yaml"
}
},
"mochaExplorer.launcherScript": "node_modules/mocha-explorer-launcher-scripts/vscode-test",
// this is key! without this, we cannot set breakpoints in TypeScript test files when using the mocha test explorer extension. This
// causes the test explorer extension
"mochaExplorer.debuggerConfig": "Extension Tests",
"mochaExplorer.autoload": false,
"mochaExplorer.ipcRole": "server",
"mochaExplorer.env": {
"VSCODE_VERSION": "insiders",
"ELECTRON_RUN_AS_NODE": null
},
// SO answer: tests don't run in default bdd mode (https://stackoverflow.com/questions/9795254/nodejs-mocha-suite-is-not-defined-error)
"mochaExplorer.ui": "tdd",
// SO answer: needed for typescript tests (https://stackoverflow.com/questions/68004071/configure-mocha-sidebar-for-typescript-test-file)
"mochaExplorer.files": "src/**/*.test.ts",
"mochaExplorer.require": "ts-node/register"
}
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,53 @@ Here are a few videos with progress updates. Watching these will step you throug
source ./venv/bin/activate
npm run install-python-deps
```

### Testing: Writing, running, and debugging tests

#### The `mocha` testing framework

VS Code's extension template from which this project was generated uses the Mocha testing framework.

Although Mocha isn't strictly required, one of the benefits that we get for going with the testing
framework from the template is that

The [docs for testing VS Code extensions are here](https://code.visualstudio.com/api/working-with-extensions/testing-extension).

#### Run all tests

To run all tests, you can do.

```bash
npm run test
```

#### Run all tests, and set a breakpoint

`npm run test` does not stop at breakpoints. To run all tests while respecting breakpoints, select the `"Extension Tests"` launch configuration in the "Run and Debug" sidebar.

Then press the green "Play" button or press `F5`.

![Run and debug sidebar](./docs/testing/run-and-debug-sidebar.png)

> 📌 Note: If you want to make `F5` run the extension and not the tests, you will need to reselect the `"Run Extension" launch configuration in the "Run and debug sidebar".

#### Run a single test (or groups of tests) -- including breakpoints

The easiest way to do this is using the Mocha Test Explorer extension.

We've configured the project's `settings.json` to use the Mocha Test Explorer extension.

1. Install the [Mocha Test Explorer extension](https://marketplace.visualstudio.com/items?itemName=hbenl.vscode-mocha-test-adapter) in VS Code (extension id: `hbenl.vscode-mocha-test-adapter`)
This will allow VS Code's test explorer to show the tests.

![test explorer](./docs/testing/test-explorer.png)

2. Try setting a break point in a test!

![breakpoint in test](./docs/testing/breakpoint-in-test.png)

To trigger your break point, you can run all tests, or select a test (or group of tests) in the Test Explorer
![alt text](./docs/testing/test-explorer-select-test.png)

Or you can click the context action button above a test in code!
![alt text](./docs/testing/test-debug-context-action.png)
Binary file added docs/testing/breakpoint-in-test.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/testing/run-and-debug-sidebar.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/testing/test-debug-context-action.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/testing/test-explorer-select-test.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/testing/test-explorer.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.