Skip to content

Commit

Permalink
fix: fix vitest configuration
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Golovin <[email protected]>
  • Loading branch information
dgolovin committed Jan 22, 2024
1 parent 51a7aee commit 7a32feb
Show file tree
Hide file tree
Showing 4 changed files with 999 additions and 5 deletions.
24 changes: 24 additions & 0 deletions __mocks__/@podman-desktop/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**********************************************************************
* Copyright (C) 2022 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://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.
*
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/

/**
* Mock the extension API for vitest.
* This file is referenced from vitest.config.js file.
*/
const plugin = {};
module.exports = plugin;
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@
"@rollup/plugin-node-resolve": "^15.0.2",
"@rollup/plugin-typescript": "^11.1.0",
"@types/js-yaml": "^4.0.5",
"@vitest/coverage-v8": "^1.2.1",
"mkdirp": "^2.1.3",
"rollup": "^3.20.4",
"tslib": "^2.5.0",
"typescript": "^5.0.4",
"zip-local": "^0.3.5",
"vite": "^5.0.11",
"vitest": "^1.1.1"
"vitest": "^1.1.1",
"zip-local": "^0.3.5"
}
}
44 changes: 42 additions & 2 deletions vitest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,51 @@
***********************************************************************/

import path from 'node:path';
import { coverageConfig, testConfig } from '../../vitest-shared-extensions.config';

const PACKAGE_ROOT = __dirname;
const PACKAGE_NAME = 'extensions/kube-context';

/**
* Default project code coverage configuration for vitest
* @param {*} packageRoot root of the project where coverage is being calculated
* @param {*} packageName package name to appear in test-resources/coverage in project root folder
* @returns object for code coverage configuration
*/
export function coverageConfig(packageRoot, packageName) {
const obj = { coverage: {
all: true,
clean: true,
src: [packageRoot],
exclude: [
'**/builtin/**',
'**/dist/**',
'**/node_modules/**',
'**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}',
'**/*.{tsx,cjs,js,d.ts}',
'**/*-info.ts',
'**/.{cache,git,idea,output,temp,cdix}/**',
'**/*{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tailwind,postcss}.config.*',
],
provider: 'v8',
reportsDirectory: path.join(packageRoot, `test-resources/coverage/${packageName}`),
reporter: ['lcov', 'text'],
},
};
return obj;
}

export function testConfig() {
return {
exclude: [
'**/builtin/**',
'**/node_modules/**',
'**/dist/**',
'**/.{idea,git,cache,output,temp,cdix}/**',
'**/{.electron-builder,babel,changelog,docusaurus,jest,postcss,prettier,rollup,svelte,tailwind,vite,vitest*,webpack}.config.*',
],
};
}

/**
* Config for global end-to-end tests
* placed in project root tests folder
Expand All @@ -36,7 +76,7 @@ const config = {
},
resolve: {
alias: {
'@podman-desktop/api': path.resolve(PACKAGE_ROOT, '../../', '__mocks__/@podman-desktop/api.js'),
'@podman-desktop/api': path.resolve(PACKAGE_ROOT, '__mocks__/@podman-desktop/api.js'),
},
},
};
Expand Down
Loading

0 comments on commit 7a32feb

Please sign in to comment.