mirror of
https://github.com/ivabus/gui
synced 2025-04-23 14:07:14 +03:00
#144 init unit test and coverage in ci
This commit is contained in:
parent
e94a3e5390
commit
baed1cb553
14 changed files with 893 additions and 107 deletions
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
@ -58,6 +58,8 @@ jobs:
|
||||||
cache-dependency-path: pnpm-lock.yaml
|
cache-dependency-path: pnpm-lock.yaml
|
||||||
- name: install app dependencies
|
- name: install app dependencies
|
||||||
run: pnpm install
|
run: pnpm install
|
||||||
|
- name: unit test
|
||||||
|
run: pnpm --filter gui run coverage
|
||||||
- name: lint
|
- name: lint
|
||||||
run: pnpm -r lint
|
run: pnpm -r lint
|
||||||
build_svelte:
|
build_svelte:
|
||||||
|
|
|
@ -11,4 +11,5 @@ node_modules
|
||||||
pnpm-lock.yaml
|
pnpm-lock.yaml
|
||||||
package-lock.json
|
package-lock.json
|
||||||
yarn.lock
|
yarn.lock
|
||||||
src-tauri/target/*
|
src-tauri/target/*
|
||||||
|
coverage/*
|
1
modules/gui/.gitignore
vendored
1
modules/gui/.gitignore
vendored
|
@ -6,3 +6,4 @@ node_modules
|
||||||
.env
|
.env
|
||||||
.env.*
|
.env.*
|
||||||
!.env.example
|
!.env.example
|
||||||
|
coverage/*
|
|
@ -18,4 +18,5 @@ build
|
||||||
/src-tauri/build/*
|
/src-tauri/build/*
|
||||||
/src-tauri/Cargo.lock
|
/src-tauri/Cargo.lock
|
||||||
/src-tauri/Cargo.toml
|
/src-tauri/Cargo.toml
|
||||||
src-tauri
|
src-tauri
|
||||||
|
coverage/*
|
|
@ -28,6 +28,14 @@ You can preview the production build with `npm run preview`.
|
||||||
|
|
||||||
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
|
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm playwright install
|
||||||
|
pnpm test
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
## Intuition Building Links
|
## Intuition Building Links
|
||||||
|
|
||||||
- [Rust module system is weird?](https://www.sheshbabu.com/posts/rust-module-system/)
|
- [Rust module system is weird?](https://www.sheshbabu.com/posts/rust-module-system/)
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
"dev": "vite dev --port 8080",
|
"dev": "vite dev --port 8080",
|
||||||
"build": "vite build && cp build/app.html build/index.html",
|
"build": "vite build && cp build/app.html build/index.html",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
|
"unit:test": "vitest",
|
||||||
|
"coverage": "vitest run --coverage",
|
||||||
"test": "playwright test",
|
"test": "playwright test",
|
||||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
||||||
|
@ -14,18 +16,23 @@
|
||||||
"format": "prettier --plugin-search-dir . --write ."
|
"format": "prettier --plugin-search-dir . --write ."
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@playwright/experimental-ct-svelte": "^1.29.2",
|
||||||
"@playwright/test": "1.25.0",
|
"@playwright/test": "1.25.0",
|
||||||
"@sveltejs/adapter-auto": "^1.0.0",
|
"@sveltejs/adapter-auto": "^1.0.0",
|
||||||
"@sveltejs/adapter-static": "^1.0.0",
|
"@sveltejs/adapter-static": "^1.0.0",
|
||||||
"@sveltejs/kit": "^1.0.1",
|
"@sveltejs/kit": "^1.0.1",
|
||||||
"@tauri-apps/cli": "^1.2.2",
|
"@tauri-apps/cli": "^1.2.2",
|
||||||
"@tea/ui": "workspace:*",
|
"@tea/ui": "workspace:*",
|
||||||
|
"@testing-library/jest-dom": "^5.16.5",
|
||||||
|
"@testing-library/svelte": "^3.2.2",
|
||||||
|
"@types/testing-library__jest-dom": "^5.14.5",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.27.0",
|
"@typescript-eslint/eslint-plugin": "^5.27.0",
|
||||||
"@typescript-eslint/parser": "^5.27.0",
|
"@typescript-eslint/parser": "^5.27.0",
|
||||||
"autoprefixer": "^10.4.13",
|
"autoprefixer": "^10.4.13",
|
||||||
"eslint": "^8.16.0",
|
"eslint": "^8.16.0",
|
||||||
"eslint-config-prettier": "^8.3.0",
|
"eslint-config-prettier": "^8.3.0",
|
||||||
"eslint-plugin-svelte3": "^4.0.0",
|
"eslint-plugin-svelte3": "^4.0.0",
|
||||||
|
"jsdom": "^21.0.0",
|
||||||
"postcss": "^8.4.19",
|
"postcss": "^8.4.19",
|
||||||
"prettier": "^2.7.1",
|
"prettier": "^2.7.1",
|
||||||
"prettier-plugin-svelte": "^2.7.0",
|
"prettier-plugin-svelte": "^2.7.0",
|
||||||
|
@ -37,13 +44,15 @@
|
||||||
"tailwindcss": "^3.2.4",
|
"tailwindcss": "^3.2.4",
|
||||||
"tslib": "^2.3.1",
|
"tslib": "^2.3.1",
|
||||||
"typescript": "^4.7.4",
|
"typescript": "^4.7.4",
|
||||||
"vite": "^4.0.0"
|
"vite": "^4.0.0",
|
||||||
|
"vitest": "^0.27.1"
|
||||||
},
|
},
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tauri-apps/api": "^1.2.0",
|
"@tauri-apps/api": "^1.2.0",
|
||||||
"@types/bcryptjs": "^2.4.2",
|
"@types/bcryptjs": "^2.4.2",
|
||||||
"@types/url-join": "^4.0.1",
|
"@types/url-join": "^4.0.1",
|
||||||
|
"@vitest/coverage-c8": "^0.27.1",
|
||||||
"bcryptjs": "^2.4.3",
|
"bcryptjs": "^2.4.3",
|
||||||
"buffer": "^6.0.3",
|
"buffer": "^6.0.3",
|
||||||
"fuse.js": "^6.6.2",
|
"fuse.js": "^6.6.2",
|
||||||
|
|
4
modules/gui/setupTest.js
Normal file
4
modules/gui/setupTest.js
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
import matchers from '@testing-library/jest-dom/matchers';
|
||||||
|
import { expect, vi } from 'vitest';
|
||||||
|
|
||||||
|
expect.extend(matchers);
|
49
modules/gui/src/libs/__tests__/teaDir.test.ts
Normal file
49
modules/gui/src/libs/__tests__/teaDir.test.ts
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
import { getPkgBottles } from '../teaDir';
|
||||||
|
|
||||||
|
describe('teaDir module', () => {
|
||||||
|
it('should getPkgBottles from nested Dir object/s', () => {
|
||||||
|
const results = getPkgBottles({
|
||||||
|
name: 'kkos',
|
||||||
|
path: '/Users/x/.tea/github.com/kkos',
|
||||||
|
children: [
|
||||||
|
{ name: '.DS_Store', path: '/Users/x/.tea/github.com/kkos/.DS_Store' },
|
||||||
|
{
|
||||||
|
name: 'oniguruma',
|
||||||
|
path: '/Users/x/.tea/github.com/kkos/oniguruma',
|
||||||
|
children: [
|
||||||
|
{ name: '.DS_Store', path: '/Users/x/.tea/github.com/kkos/oniguruma/.DS_Store' },
|
||||||
|
{
|
||||||
|
path: '/Users/x/.tea/github.com/kkos/oniguruma/v6',
|
||||||
|
name: 'v6',
|
||||||
|
children: [
|
||||||
|
{ name: '.DS_Store', path: '/Users/x/.tea/github.com/kkos/oniguruma/v6/.DS_Store' }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'v*',
|
||||||
|
path: '/Users/x/.tea/github.com/kkos/oniguruma/v*',
|
||||||
|
children: []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'v6.9.8',
|
||||||
|
path: '/Users/x/.tea/github.com/kkos/oniguruma/v6.9.8',
|
||||||
|
children: []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'v6.9',
|
||||||
|
path: '/Users/x/.tea/github.com/kkos/oniguruma/v6.9',
|
||||||
|
children: []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(results).toEqual([
|
||||||
|
'github.com/kkos/oniguruma/v*',
|
||||||
|
'github.com/kkos/oniguruma/v6',
|
||||||
|
'github.com/kkos/oniguruma/v6.9',
|
||||||
|
'github.com/kkos/oniguruma/v6.9.8'
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
|
@ -36,8 +36,8 @@ export async function getInstalledPackages() {
|
||||||
const semverTest =
|
const semverTest =
|
||||||
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/g;
|
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/g;
|
||||||
|
|
||||||
const getPkgBottles = (packageDir: Dir): string[] => {
|
export const getPkgBottles = (packageDir: Dir): string[] => {
|
||||||
let bottles: string[] = [];
|
const bottles: string[] = [];
|
||||||
|
|
||||||
const pkg = packageDir.path.split('.tea/')[1];
|
const pkg = packageDir.path.split('.tea/')[1];
|
||||||
const version = pkg.split('/v')[1];
|
const version = pkg.split('/v')[1];
|
||||||
|
@ -46,15 +46,12 @@ const getPkgBottles = (packageDir: Dir): string[] => {
|
||||||
|
|
||||||
if (version && isVersion) {
|
if (version && isVersion) {
|
||||||
bottles.push(pkg);
|
bottles.push(pkg);
|
||||||
} else if (!version && packageDir.children?.length) {
|
} else if (packageDir?.children?.length) {
|
||||||
const childBottles = packageDir.children
|
const childBottles = packageDir.children
|
||||||
.map((dir) => {
|
.map(getPkgBottles)
|
||||||
return getPkgBottles(dir).flatMap((v) => v);
|
.reduce((arr, bottles) => [...arr, ...bottles], []);
|
||||||
})
|
bottles.push(...childBottles);
|
||||||
.map((b) => b[0]);
|
|
||||||
|
|
||||||
bottles = [...bottles, ...childBottles].filter((b) => b);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return bottles; // ie: ["gohugo.io/v*", "gohugo.io/v0", "gohugo.io/v0.108", "gohugo.io/v0.108.0"]
|
return bottles.filter((b) => b !== undefined).sort(); // ie: ["gohugo.io/v*", "gohugo.io/v0", "gohugo.io/v0.108", "gohugo.io/v0.108.0"]
|
||||||
};
|
};
|
||||||
|
|
0
modules/gui/src/setupTets
Normal file
0
modules/gui/src/setupTets
Normal file
|
@ -1,6 +1,5 @@
|
||||||
import { expect, test } from '@playwright/test';
|
import { expect, test } from '@playwright/test';
|
||||||
|
|
||||||
test('index page has expected h1', async ({ page }) => {
|
test('index page has expected Discover header', async ({ page }) => {
|
||||||
await page.goto('/');
|
await page.goto('/');
|
||||||
expect(await page.textContent('h1')).toBe('Welcome to SvelteKit');
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"strict": true,
|
"strict": true,
|
||||||
|
"types": ["vitest/globals", "@testing-library/jest-dom"],
|
||||||
"paths": {
|
"paths": {
|
||||||
"$appcss": ["src/app.css"],
|
"$appcss": ["src/app.css"],
|
||||||
"$libs/*": ["src/libs/*"],
|
"$libs/*": ["src/libs/*"],
|
||||||
|
|
|
@ -21,6 +21,17 @@ const config: UserConfig = {
|
||||||
fs: {
|
fs: {
|
||||||
allow: ['..']
|
allow: ['..']
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
test: {
|
||||||
|
// Jest like globals
|
||||||
|
globals: true,
|
||||||
|
environment: 'jsdom',
|
||||||
|
include: ['src/**/*.{test,spec}.ts'],
|
||||||
|
// Extend jest-dom matchers
|
||||||
|
setupFiles: ['./setupTest.js'],
|
||||||
|
coverage: {
|
||||||
|
provider: 'c8'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
887
pnpm-lock.yaml
887
pnpm-lock.yaml
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue