Skip to content

Commit

Permalink
feat(vscode): Add initial setup for unit testing with vitest in exten…
Browse files Browse the repository at this point in the history
…sion code (#4804)
  • Loading branch information
ccastrotrejo committed May 8, 2024
1 parent 98219cf commit e5bc077
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 4 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/base-coverage.yml
Expand Up @@ -30,11 +30,14 @@ jobs:
- recursive: true
args: [--frozen-lockfile, --strict-peer-dependencies]
- run: pnpm turbo run test:lib --cache-dir=.turbo
- name: Run lib unit tests
run: pnpm turbo run test:lib --cache-dir=.turbo
- name: Run extension unit tests
run: pnpm turbo run test:extension-unit --cache-dir=.turbo
- name: Create code coverage report
run: |
dotnet tool install -g dotnet-reportgenerator-globaltool
reportgenerator -reports:"libs/*/coverage/cobertura-coverage.xml" -targetdir:CodeCoverage -reporttypes:'Cobertura;MarkdownSummaryGithub'
reportgenerator -reports:"libs/*/coverage/cobertura-coverage.xml;apps/vs-code-designer/coverage/cobertura-coverage.xml" -targetdir:CodeCoverage -reporttypes:'Cobertura;MarkdownSummaryGithub'
- uses: clearlyip/code-coverage-report-action@v4
with:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Expand Up @@ -45,3 +45,4 @@ jobs:
- run: turbo run build --cache-dir=.turbo
- run: turbo run test:lib --cache-dir=.turbo
- run: turbo run build:extension --cache-dir=.turbo
- run: turbo run test:extension-unit --cache-dir=.turbo
3 changes: 2 additions & 1 deletion apps/vs-code-designer/package.json
Expand Up @@ -43,6 +43,7 @@
"vscode:designer:pack": "pnpm run build:extension && pnpm run vscode:designer:pack:step1 && pnpm run vscode:designer:pack:step2",
"vscode:designer:pack:step1": "cd ./dist && npm install",
"vscode:designer:pack:step2": "cd ./dist && vsce package",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0"
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"test:extension-unit": "vitest --retry=3"
}
}
Expand Up @@ -27,7 +27,6 @@ describe('parameterizeConnection for ConnectionReferenceModel', () => {
scheme: 'Key',
parameter: "@appsetting('arm-connectionKey')",
},
connectionProperties: null,
};

const parameters: any = {};
Expand Down
6 changes: 6 additions & 0 deletions apps/vs-code-designer/test-setup.ts
@@ -0,0 +1,6 @@
import '@testing-library/jest-dom/vitest';
import { cleanup } from '@testing-library/react';
import { afterEach } from 'vitest';

// https://testing-library.com/docs/react-testing-library/api#cleanup
afterEach(() => cleanup());
15 changes: 15 additions & 0 deletions apps/vs-code-designer/vitest.config.ts
@@ -0,0 +1,15 @@
import { defineProject } from 'vitest/config';
import packageJson from './package.json';

export default defineProject({
plugins: [],
test: {
name: packageJson.name,
dir: './src',
watch: false,
environment: 'jsdom',
setupFiles: ['test-setup.ts'],
coverage: { enabled: true, provider: 'istanbul', include: ['src/**/*'], reporter: ['html', 'cobertura'] },
restoreMocks: true,
},
});
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -91,6 +91,7 @@
"start:e2e": "turbo run e2e",
"test:lib": "turbo run test:lib",
"test:e2e": "playwright test",
"test:extension-unit": "turbo run test:extension-unit",
"testgen": "playwright codegen https://localhost:4200",
"vscode:designer:pack": "turbo run vscode:designer:pack"
},
Expand Down
5 changes: 5 additions & 0 deletions turbo.json
Expand Up @@ -52,6 +52,11 @@
"coverage/**"
]
},
"test:extension-unit": {
"outputs": [
"coverage/**"
]
},
"vscode:designer:pack": {
"cache": false,
"dependsOn": [
Expand Down

0 comments on commit e5bc077

Please sign in to comment.