提交 dbcd6b84 编写于 作者: T Tomas Vik

test: replace mocha with jest for unit testing

This change introduces Jest test framework to run our unit tests.
上级 faa83e3d
......@@ -2,7 +2,8 @@
"extends": ["airbnb-base", "prettier" ],
"plugins": ["import", "prettier"],
"env": {
"mocha": true
"mocha": true,
"jest": true
},
"ignorePatterns": [
"node_modules/",
......
......@@ -10,18 +10,14 @@
"args": ["--disable-extensions", "--extensionDevelopmentPath=${workspaceRoot}"],
"stopOnEntry": false
},
{
"name": "Unit Tests",
"args": [
"--timeout",
"999999",
"--colors",
"--ignore",
"${workspaceFolder}/src/webview/node_modules/**",
"${workspaceFolder}/src/**/**.test.js"
"-i",
],
"internalConsoleOptions": "openOnSessionStart",
"program": "${workspaceFolder}/node_modules/.bin/mocha",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"request": "launch",
"type": "node"
},
......
......@@ -32,7 +32,7 @@ When looking at the tests from the perspective of the testing pyramid[^1], the V
### Unit tests
Unit tests (usually run by `mocha`) are run directly in the development environment, and they are not dependent on the VS Code editor and its APIs. The tests will fail to execute if they import any code dependent on the `vscode` module.
Unit tests (written in Jest) are run directly in the development environment, and they are not dependent on the VS Code editor and its APIs. The tests will fail to execute if they import any code dependent on the `vscode` module.
### Integration tests
......
......@@ -4,11 +4,11 @@ This document provides technical details about our automated tests. Please see [
## Technology choice
We are using [`mocha`](https://mochajs.org/) as a test runner for both unit and integration tests. We use [`assert`](https://nodejs.org/docs/latest-v12.x/api/assert.html) for assertions. We use [`vscode-test`](https://code.visualstudio.com/api/working-with-extensions/testing-extension#the-test-script) to run integration tests.
We are using [Jest](https://jestjs.io/) for our unit tests[^1]. For integration tests, we use [`mocha`](https://mochajs.org/) as a test runner, [`assert`](https://nodejs.org/docs/latest-v12.x/api/assert.html) for assertions, and [`vscode-test`](https://code.visualstudio.com/api/working-with-extensions/testing-extension#the-test-script) to run integration tests in VS Code instance.
## Unit tests `npm run test-unit`
Modules that don't depend on `vscode` module can be unit tested. Unit tests for a module are placed in the same folder. The name of the test file has `.test.js` suffix.
Modules that **don't depend on `vscode` module** can be unit tested. Unit tests for a module are placed in the same folder. The name of the test file has `.test.js` suffix.
- `src/git/git_remote_parser.js` - production file
- `src/git/git_remote_parser.test.js` - test file
......@@ -48,3 +48,5 @@ For debugging of the integration tests, we first need to create a test workspace
Then we can debug the by running the "Integration Tests" [Launch configuration].
[Launch configuration]: https://code.visualstudio.com/docs/editor/debugging#_launch-configurations
[^1]: https://gitlab.com/gitlab-org/gitlab-vscode-extension/-/merge_requests/87
// For a detailed explanation regarding each configuration property, visit:
// https://jestjs.io/docs/en/configuration.html
module.exports = {
clearMocks: true,
coverageDirectory: 'coverage',
coverageProvider: 'v8',
coverageReporters: ['lcov'],
roots: ['src'],
testEnvironment: 'node',
};
此差异已折叠。
......@@ -494,7 +494,7 @@
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"test-unit": "mocha ./src/**/**.test.js",
"test-unit": "jest",
"test-integration": "npm run compile && node ./out/runTest.js",
"create-test-workspace": "npm run compile && node ./scripts/create_workspace_for_test_debugging.js",
"test": "npm run test-unit && npm run test-integration",
......@@ -517,6 +517,7 @@
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-import": "^2.20.0",
"eslint-plugin-prettier": "^3.1.2",
"jest": "^26.2.2",
"mocha": "^7.0.1",
"msw": "^0.19.5",
"prettier": "^1.19.1",
......
const assert = require('assert');
const { parseGitRemote } = require('./git_remote_parser');
const parameters = [
{
argument: 'git@gitlab.com:fatihacet/gitlab-vscode-extension.git',
result: ['ssh:', 'gitlab.com', 'fatihacet', 'gitlab-vscode-extension'],
},
{
argument: 'gitlab-ci@gitlab-mydomain.com:fatihacet/gitlab-vscode-extension.git',
result: ['ssh:', 'gitlab-mydomain.com', 'fatihacet', 'gitlab-vscode-extension'],
},
{
argument: 'ssh://git@gitlab.com:fatihacet/gitlab-vscode-extension.git',
result: ['ssh:', 'gitlab.com', 'fatihacet', 'gitlab-vscode-extension'],
},
{
argument: 'git://git@gitlab.com:fatihacet/gitlab-vscode-extension.git',
result: ['git:', 'gitlab.com', 'fatihacet', 'gitlab-vscode-extension'],
},
{
argument: 'http://git@gitlab.com/fatihacet/gitlab-vscode-extension.git',
result: ['http:', 'gitlab.com', 'fatihacet', 'gitlab-vscode-extension'],
},
{
argument: 'http://gitlab.com/fatihacet/gitlab-vscode-extension.git',
result: ['http:', 'gitlab.com', 'fatihacet', 'gitlab-vscode-extension'],
},
{
argument: 'https://git@gitlab.com/fatihacet/gitlab-vscode-extension.git',
result: ['https:', 'gitlab.com', 'fatihacet', 'gitlab-vscode-extension'],
},
{
argument: 'https://gitlab.com/fatihacet/gitlab-vscode-extension.git',
result: ['https:', 'gitlab.com', 'fatihacet', 'gitlab-vscode-extension'],
},
{
argument: 'https://gitlab.com/fatihacet/gitlab-vscode-extension',
result: ['https:', 'gitlab.com', 'fatihacet', 'gitlab-vscode-extension'],
},
{
argument: 'https://gitlab.company.com/fatihacet/gitlab-vscode-extension.git',
result: ['https:', 'gitlab.company.com', 'fatihacet', 'gitlab-vscode-extension'],
},
{
argument: 'https://gitlab.company.com:8443/fatihacet/gitlab-vscode-extension.git',
result: ['https:', 'gitlab.company.com:8443', 'fatihacet', 'gitlab-vscode-extension'],
},
];
describe('git_remote_parser', () => {
parameters.forEach(p => {
it(`should parse ${p.argument}`, () => {
assert.deepEqual(parseGitRemote('https://gitlab.com', p.argument), p.result);
});
it.each([
[
'git@gitlab.com:fatihacet/gitlab-vscode-extension.git',
['ssh:', 'gitlab.com', 'fatihacet', 'gitlab-vscode-extension'],
],
[
'gitlab-ci@gitlab-mydomain.com:fatihacet/gitlab-vscode-extension.git',
['ssh:', 'gitlab-mydomain.com', 'fatihacet', 'gitlab-vscode-extension'],
],
[
'ssh://git@gitlab.com:fatihacet/gitlab-vscode-extension.git',
['ssh:', 'gitlab.com', 'fatihacet', 'gitlab-vscode-extension'],
],
[
'git://git@gitlab.com:fatihacet/gitlab-vscode-extension.git',
['git:', 'gitlab.com', 'fatihacet', 'gitlab-vscode-extension'],
],
[
'http://git@gitlab.com/fatihacet/gitlab-vscode-extension.git',
['http:', 'gitlab.com', 'fatihacet', 'gitlab-vscode-extension'],
],
[
'http://gitlab.com/fatihacet/gitlab-vscode-extension.git',
['http:', 'gitlab.com', 'fatihacet', 'gitlab-vscode-extension'],
],
[
'https://git@gitlab.com/fatihacet/gitlab-vscode-extension.git',
['https:', 'gitlab.com', 'fatihacet', 'gitlab-vscode-extension'],
],
[
'https://gitlab.com/fatihacet/gitlab-vscode-extension.git',
['https:', 'gitlab.com', 'fatihacet', 'gitlab-vscode-extension'],
],
[
'https://gitlab.com/fatihacet/gitlab-vscode-extension',
['https:', 'gitlab.com', 'fatihacet', 'gitlab-vscode-extension'],
],
[
'https://gitlab.company.com/fatihacet/gitlab-vscode-extension.git',
['https:', 'gitlab.company.com', 'fatihacet', 'gitlab-vscode-extension'],
],
[
'https://gitlab.company.com:8443/fatihacet/gitlab-vscode-extension.git',
['https:', 'gitlab.company.com:8443', 'fatihacet', 'gitlab-vscode-extension'],
],
])('should parse %s', (remote, parsed) => {
expect(parseGitRemote('https://gitlab.com', remote)).toEqual(parsed);
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册