Skip to content

Commit

Permalink
Introduce unit/integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
apupier committed Sep 16, 2024
1 parent 1393a8a commit 8a6b202
Show file tree
Hide file tree
Showing 9 changed files with 314 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ jobs:
run: yarn build:prod
- name: vsix package
run: yarn vsce package --no-dependencies --yarn
- name: Run Unit tests on Linux
run: xvfb-run -a yarn test:unit
if: ${{ matrix.os == 'ubuntu-latest' }}
- name: Run Unit tests on Other OSes than Linux
run: yarn test:unit
if: ${{ matrix.os != 'ubuntu-latest' }}
- name: Run UI Tests on Linux
run: xvfb-run -a yarn run test:it:with-prebuilt-vsix
if: ${{ matrix.os == 'ubuntu-latest' }}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/main-kaoto.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ jobs:
- name: vsix package
working-directory: vscode-kaoto
run: yarn vsce package --no-dependencies --yarn
- name: Run Unit tests
working-directory: vscode-kaoto
run: xvfb-run -a yarn test:unit
- name: Run UI Tests
working-directory: vscode-kaoto
run: xvfb-run -a yarn run test:it:with-prebuilt-vsix
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dist
# testing
/coverage
.vscode-test-web
.vscode-test
/uitest-resources
/test-extensions
/test-resources
Expand Down
12 changes: 12 additions & 0 deletions .vscode-test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineConfig } from '@vscode/test-cli';

export default defineConfig({
files: 'out/test/**/*.test.js',
workspaceFolder: './test Fixture with speci@l chars',
mocha: {
ui: 'tdd',
color: true,
timeout: 100000,
reporter: 'mocha-jenkins-reporter'
}
});
7 changes: 6 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ node('rhel8'){
sh "yarn build:dev"
sh "yarn build:prod"

stage('Test') {
stage('Unit Tests') {
wrap([$class: 'Xvnc']) {
sh "yarn test:unit"
}
}
stage('UI Tests') {
wrap([$class: 'Xvnc']) {
sh "yarn test:it"
}
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
"lint": "yarn eslint ./src --ext .ts,.tsx",
"build:prod": "rimraf dist && webpack",
"build:dev": "rimraf dist && webpack --env dev",
"build:test:it": "tsc --project tsconfig.it-tests.json --skipLibCheck --sourceMap true",
"build:test:it": "rimraf ./out && tsc --project tsconfig.it-tests.json --skipLibCheck --sourceMap true",
"build:test:unit": "rimraf ./out && tsc --project tsconfig.unit-tests.json --skipLibCheck --sourceMap true",
"compile": "webpack",
"watch": "webpack --env dev",
"run:webmode": "yarn vscode-test-web --browserType=chromium --extensionDevelopmentPath=. --open-devtools ./resources",
"test:unit": "yarn build:test:unit && vscode-test",
"test:it": "yarn build:test:it && extest setup-and-run --yarn --uninstall_extension --extensions_dir ./test-resources 'out/**/*.test.js' --open_resource './test Fixture with speci@l chars'",
"test:it:with-prebuilt-vsix": "yarn build:test:it && extest get-vscode && extest get-chromedriver && extest install-vsix --vsix_file vscode-kaoto-$npm_package_version.vsix --extensions_dir ./test-resources && extest run-tests --uninstall_extension --extensions_dir ./test-resources 'out/**/*.test.js' --open_resource './test Fixture with speci@l chars'",
"test:it:clean": "rimraf ./test-resources && rimraf ./out && rimraf *.vsix"
Expand Down Expand Up @@ -184,6 +186,8 @@
"@types/fs-extra": "^11.0.4",
"@types/mocha": "^10.0.8",
"@types/react": "18.2.79",
"@vscode/test-cli": "^0.0.10",
"@vscode/test-electron": "^2.4.1",
"@vscode/test-web": "^0.0.60",
"@vscode/vsce": "^3.1.0",
"async-wait-until": "^2.0.12",
Expand All @@ -194,6 +198,7 @@
"css-loader": "6.8.1",
"fs-extra": "^11.2.0",
"mocha": "^10.7.3",
"mocha-jenkins-reporter": "^0.4.8",
"node-fetch": "2",
"npm-link-shared": "^0.5.6",
"os-browserify": "^0.3.0",
Expand Down
26 changes: 26 additions & 0 deletions src/test/activation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License", destination); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { assert } from 'chai';
import * as vscode from 'vscode';

suite('Extension is activated', () => {
test('Extension is activated', async() => {
const extension = await vscode.extensions.getExtension('redhat.vscode-kaoto');
assert.isNotNull(extension, 'VS Code Kaoto not found');
assert.isTrue(extension?.isActive, 'VS Code Kaoto is not activated despite the workspace used for tests contains yaml files');
});
})
12 changes: 12 additions & 0 deletions tsconfig.unit-tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "CommonJS",
"moduleResolution": "Node",
"declaration": false,
"declarationMap": false,
"resolveJsonModule": true,
"outDir": "out/test"
},
"include": ["src/test"]
}
Loading

0 comments on commit 8a6b202

Please sign in to comment.