@altafusion/test-kit 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/LICENSE +21 -0
- package/README.md +96 -2
- package/index.ts +15 -0
- package/nuxt.ts +8 -0
- package/package.json +61 -3
- package/playwright.ts +59 -0
- package/vitest-app.ts +25 -0
- package/vitest.config.base.ts +61 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @altafusion/test-kit
|
|
2
|
+
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
No changes in this release.
|
|
6
|
+
|
|
7
|
+
## 0.2.0
|
|
8
|
+
|
|
9
|
+
### Minor Changes
|
|
10
|
+
|
|
11
|
+
- 7767e60: Rebrand for the public release. In `@altafusion/shell`, `CODERMAR_BRANDS`, `CODERMAR_BRAND_THEME` and `utils/codermarBrandTheme` become `ALTAFUSION_*` and `utils/altafusionBrandTheme`, and the brand cookie key is now `altafusion:brand`. In `@altafusion/msw`, the `codermarMsw*` exports become `altafusionMsw*`. The site settings schema `$id` is now `https://altafusion.com/schemas/site-settings.json`. Package descriptions and docs no longer reference private sites.
|
|
12
|
+
|
|
13
|
+
## 0.1.1
|
|
14
|
+
|
|
15
|
+
No changes in this release.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Altafusion
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,97 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @altafusion/test-kit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Platform test kit — Vitest, Playwright E2E, and Nuxt test utils presets. Pattern inspired by [UnoCSS](https://github.com/unocss/unocss) centralized configuration.
|
|
4
|
+
|
|
5
|
+
## Exports
|
|
6
|
+
|
|
7
|
+
- **`baseTestConfig`** — mergeable base Vitest config (globals, coverage, env, timeouts)
|
|
8
|
+
- **`sharedVitestConfig`** — full **`defineConfig`** using base
|
|
9
|
+
- **`defineVueAppVitestConfig`** — single-call preset for app-local Vitest (`happy-dom`, `@vitejs/plugin-vue`)
|
|
10
|
+
- **`defineVitestProject`**, **`defineVitestConfig`** — from **`@altafusion/test-kit/nuxt`** for Nuxt runtime tests (optional peer **`@nuxt/test-utils`**)
|
|
11
|
+
- **`defineFrontendPlaywrightConfig`** — from **`@altafusion/test-kit/playwright`** (Chromium + WebKit)
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### Root vitest.config.ts
|
|
16
|
+
|
|
17
|
+
Keep **every package and app that contains tests** under **`test.projects`** so root **`pnpm test`** matches CI.
|
|
18
|
+
|
|
19
|
+
Nuxt runtime tests: **`defineVitestProject`** from **`@altafusion/test-kit/nuxt`**. Add **`@nuxt/test-utils`** on that app. Vitest supports an async factory:
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { fileURLToPath } from 'node:url'
|
|
23
|
+
import { defineConfig } from 'vitest/config'
|
|
24
|
+
import { baseTestConfig } from '@altafusion/test-kit'
|
|
25
|
+
import { defineVitestProject } from '@altafusion/test-kit/nuxt'
|
|
26
|
+
|
|
27
|
+
export default defineConfig(async () => ({
|
|
28
|
+
test: {
|
|
29
|
+
...baseTestConfig,
|
|
30
|
+
projects: [
|
|
31
|
+
await defineVitestProject({
|
|
32
|
+
test: {
|
|
33
|
+
include: ['apps/<app>/**/*.{test,spec}.ts'],
|
|
34
|
+
environment: 'nuxt',
|
|
35
|
+
environmentOptions: {
|
|
36
|
+
nuxt: {
|
|
37
|
+
rootDir: fileURLToPath(new URL('./apps/<app>', import.meta.url)),
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
}),
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
}))
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Vue component tests
|
|
48
|
+
|
|
49
|
+
Packages with **`.vue`** files need **`@vitejs/plugin-vue`**:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import vue from '@vitejs/plugin-vue'
|
|
53
|
+
|
|
54
|
+
{
|
|
55
|
+
plugins: [vue()],
|
|
56
|
+
test: {
|
|
57
|
+
name: 'design-system',
|
|
58
|
+
include: ['packages-fugue/fugue-theme/**/*.{test,spec}.{ts,tsx}'],
|
|
59
|
+
environment: 'happy-dom',
|
|
60
|
+
},
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Per-app vitest.config.ts
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import { defineVueAppVitestConfig } from '@altafusion/test-kit'
|
|
68
|
+
|
|
69
|
+
export default defineVueAppVitestConfig()
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Per-package vitest.config.ts
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import { defineConfig } from 'vitest/config'
|
|
76
|
+
import { baseTestConfig } from '@altafusion/test-kit'
|
|
77
|
+
|
|
78
|
+
export default defineConfig({
|
|
79
|
+
test: {
|
|
80
|
+
...baseTestConfig,
|
|
81
|
+
include: ['**/*.{test,spec}.ts'],
|
|
82
|
+
},
|
|
83
|
+
})
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Dependencies
|
|
87
|
+
|
|
88
|
+
- **`vitest`**, **`@vitejs/plugin-vue`** — declared alongside this package in consumers
|
|
89
|
+
- **`@nuxt/test-utils`** — optional peer for **`@altafusion/test-kit/nuxt`**
|
|
90
|
+
- **`@vue/test-utils`**, **`happy-dom`**, **`msw`**, **`@vitest/coverage-v8`**, **`@vitest/ui`**
|
|
91
|
+
|
|
92
|
+
## Consumers
|
|
93
|
+
|
|
94
|
+
> **Local — do not copy-sync.** Repo wiring, ports, catalog keys, consuming apps, and docs-site links.
|
|
95
|
+
|
|
96
|
+
- Root **`vitest.config.ts`** includes fugue packages, **`packages-consumer/fugue-content`**, **`templates/fugue-content-site`**, etc.
|
|
97
|
+
- **`defineFrontendPlaywrightConfig()`** default base URL targets the starter template preview (**`http://127.0.0.1:8001/`**) — see root **`playwright.config.ts`** and **`templateDevPorts.fugueContentSite`** in **`@altafusion/nuxt-base/dev/ports`**.
|
package/index.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @altafusion/test-kit — Test kit (Vitest, Nuxt test utils, MSW)
|
|
3
|
+
*
|
|
4
|
+
* Centralized Vitest, Nuxt test utils, MSW setup.
|
|
5
|
+
* Pattern inspired by UnoCSS.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* import { baseTestConfig } from '@altafusion/test-kit'
|
|
9
|
+
* import { defineVitestProject } from '@altafusion/test-kit/nuxt'
|
|
10
|
+
* See README.md for full usage examples.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export { baseTestConfig, sharedVitestConfig } from '@altafusion/test-kit/vitest'
|
|
14
|
+
export { defineVueAppVitestConfig } from './vitest-app.ts'
|
|
15
|
+
export type { UserWorkspaceConfig } from 'vitest/config'
|
package/nuxt.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @altafusion/test-kit — Nuxt test utils integration
|
|
3
|
+
*
|
|
4
|
+
* Re-exports defineVitestProject from @nuxt/test-utils/config for Nuxt runtime tests.
|
|
5
|
+
* Use in root vitest.config.ts to add a Nuxt project.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export { defineVitestProject, defineVitestConfig } from '@nuxt/test-utils/config'
|
package/package.json
CHANGED
|
@@ -1,6 +1,64 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@altafusion/test-kit",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.3.0",
|
|
5
|
+
"description": "Test kit for Altafusion packages — Vitest, Nuxt test utils, MSW",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/altafusion/fugue/tree/main/packages-platform/test-kit#readme",
|
|
8
|
+
"bugs": {
|
|
9
|
+
"url": "https://github.com/altafusion/fugue/issues"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/altafusion/fugue.git",
|
|
14
|
+
"directory": "packages-platform/test-kit"
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"main": "./index.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": "./index.ts",
|
|
22
|
+
"./vitest": "./vitest.config.base.ts",
|
|
23
|
+
"./vitest-app": "./vitest-app.ts",
|
|
24
|
+
"./nuxt": "./nuxt.ts",
|
|
25
|
+
"./playwright": "./playwright.ts"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@nuxt/test-utils": ">=4.0.0"
|
|
29
|
+
},
|
|
30
|
+
"peerDependenciesMeta": {
|
|
31
|
+
"@nuxt/test-utils": {
|
|
32
|
+
"optional": true
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@playwright/test": "^1.65.1",
|
|
37
|
+
"@vitejs/plugin-vue": "^6.0.11",
|
|
38
|
+
"vitest": "^5.1.1"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@nuxt/test-utils": "^4.4.0",
|
|
42
|
+
"@vitest/coverage-v8": "^5.1.1",
|
|
43
|
+
"@vitest/ui": "^5.1.1",
|
|
44
|
+
"@vue/test-utils": "^2.6.0",
|
|
45
|
+
"happy-dom": "^21.0.4",
|
|
46
|
+
"msw": "^3.0.7",
|
|
47
|
+
"vue": "^3.5.46"
|
|
48
|
+
},
|
|
49
|
+
"files": [
|
|
50
|
+
"**",
|
|
51
|
+
"!**/*.test.ts",
|
|
52
|
+
"!**/.nuxt",
|
|
53
|
+
"!**/.output",
|
|
54
|
+
"!**/.data",
|
|
55
|
+
"!**/coverage",
|
|
56
|
+
"!**/node_modules"
|
|
57
|
+
],
|
|
58
|
+
"scripts": {
|
|
59
|
+
"test": "pnpm --dir ../.. exec vitest run --project test-kit",
|
|
60
|
+
"test:watch": "pnpm --dir ../.. exec vitest --project test-kit",
|
|
61
|
+
"test:ui": "pnpm --dir ../.. exec vitest --ui --project test-kit",
|
|
62
|
+
"test:coverage": "pnpm --dir ../.. exec vitest run --coverage --project test-kit"
|
|
63
|
+
}
|
|
6
64
|
}
|
package/playwright.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @altafusion/test-kit — Playwright preset for repo-root E2E (Chromium + WebKit).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { defineConfig, devices, type PlaywrightTestConfig } from '@playwright/test'
|
|
6
|
+
|
|
7
|
+
/** Must end with `/` so relative `page.goto('./')` resolves against the app origin. */
|
|
8
|
+
export const defaultPlaywrightBaseURL = `${(
|
|
9
|
+
process.env.PLAYWRIGHT_BASE_URL ?? 'http://127.0.0.1:8001'
|
|
10
|
+
).replace(/\/?$/, '/')}`
|
|
11
|
+
|
|
12
|
+
const defaultProjects: NonNullable<PlaywrightTestConfig['projects']> = [
|
|
13
|
+
{
|
|
14
|
+
name: 'chromium',
|
|
15
|
+
use: { ...devices['Desktop Chrome'] },
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: 'webkit',
|
|
19
|
+
use: { ...devices['Desktop Safari'] },
|
|
20
|
+
},
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
const defaultUse: PlaywrightTestConfig['use'] = {
|
|
24
|
+
baseURL: defaultPlaywrightBaseURL,
|
|
25
|
+
ignoreHTTPSErrors: true,
|
|
26
|
+
trace: 'on-first-retry',
|
|
27
|
+
screenshot: 'only-on-failure',
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Shared Playwright defaults for Altafusion packages.
|
|
32
|
+
* Pass `webServer`, `testDir` overrides, etc. from the repo-root config.
|
|
33
|
+
*/
|
|
34
|
+
export function defineFrontendPlaywrightConfig(
|
|
35
|
+
overrides: PlaywrightTestConfig = {},
|
|
36
|
+
): ReturnType<typeof defineConfig> {
|
|
37
|
+
const baseURL = overrides.use?.baseURL ?? defaultPlaywrightBaseURL
|
|
38
|
+
|
|
39
|
+
return defineConfig({
|
|
40
|
+
testDir: 'e2e',
|
|
41
|
+
fullyParallel: true,
|
|
42
|
+
forbidOnly: !!process.env.CI,
|
|
43
|
+
retries: process.env.CI ? 2 : 0,
|
|
44
|
+
reporter: [
|
|
45
|
+
['list'],
|
|
46
|
+
['html', { open: 'never', outputFolder: 'playwright-report' }],
|
|
47
|
+
],
|
|
48
|
+
...overrides,
|
|
49
|
+
use: {
|
|
50
|
+
...defaultUse,
|
|
51
|
+
...overrides.use,
|
|
52
|
+
baseURL,
|
|
53
|
+
},
|
|
54
|
+
projects: overrides.projects ?? defaultProjects,
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { defineConfig, devices }
|
|
59
|
+
export type { PlaywrightTestConfig } from '@playwright/test'
|
package/vitest-app.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default Vitest preset for Nuxt/Vue apps — happy-dom + Vue plugin + base defaults.
|
|
3
|
+
* Keeps per-app vitest.config.ts to a single import (root projects stay in sync via same defaults).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import vue from '@vitejs/plugin-vue'
|
|
7
|
+
import { defineConfig, mergeConfig, type UserWorkspaceConfig } from 'vitest/config'
|
|
8
|
+
import { baseTestConfig } from '@altafusion/test-kit/vitest'
|
|
9
|
+
|
|
10
|
+
export function defineVueAppVitestConfig(testOverrides?: UserWorkspaceConfig['test']): ReturnType<typeof defineConfig> {
|
|
11
|
+
return defineConfig(
|
|
12
|
+
mergeConfig(
|
|
13
|
+
{
|
|
14
|
+
plugins: [vue()],
|
|
15
|
+
test: {
|
|
16
|
+
...baseTestConfig,
|
|
17
|
+
include: ['**/*.{test,spec}.{ts,tsx}'],
|
|
18
|
+
environment: 'happy-dom',
|
|
19
|
+
passWithNoTests: true,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
testOverrides ? { test: testOverrides } : {},
|
|
23
|
+
),
|
|
24
|
+
)
|
|
25
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @altafusion/test-kit — Base Vitest configuration
|
|
3
|
+
*
|
|
4
|
+
* Centralized test config similar to UnoCSS patterns.
|
|
5
|
+
* Consumers extend this via merge or createVitestConfig().
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { configDefaults, defineConfig } from 'vitest/config'
|
|
9
|
+
import type { UserWorkspaceConfig } from 'vitest/config'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Base test config — globals, env, coverage, default environment.
|
|
13
|
+
* Merge this into your vitest config or use createVitestConfig().
|
|
14
|
+
*/
|
|
15
|
+
export const baseTestConfig = {
|
|
16
|
+
globals: true,
|
|
17
|
+
env: {
|
|
18
|
+
NODE_ENV: 'test',
|
|
19
|
+
},
|
|
20
|
+
testTimeout: 10_000,
|
|
21
|
+
hookTimeout: 10_000,
|
|
22
|
+
environment: 'happy-dom',
|
|
23
|
+
include: ['**/*.{test,spec}.{ts,tsx,js,jsx}'],
|
|
24
|
+
exclude: [
|
|
25
|
+
...configDefaults.exclude,
|
|
26
|
+
'**/node_modules/**',
|
|
27
|
+
'**/dist/**',
|
|
28
|
+
'**/.nuxt/**',
|
|
29
|
+
'**/.output/**',
|
|
30
|
+
'**/coverage/**',
|
|
31
|
+
],
|
|
32
|
+
coverage: {
|
|
33
|
+
provider: 'v8' as const,
|
|
34
|
+
reporter: ['text', 'json', 'html'],
|
|
35
|
+
reportsDirectory: './coverage',
|
|
36
|
+
include: ['**/*.{ts,tsx,js,jsx}'],
|
|
37
|
+
exclude: [
|
|
38
|
+
...configDefaults.exclude,
|
|
39
|
+
'**/node_modules/**',
|
|
40
|
+
'**/dist/**',
|
|
41
|
+
'**/.nuxt/**',
|
|
42
|
+
'**/.output/**',
|
|
43
|
+
'**/coverage/**',
|
|
44
|
+
'**/*.d.ts',
|
|
45
|
+
'**/*.{test,spec}.{ts,tsx,js,jsx}',
|
|
46
|
+
'**/test/**',
|
|
47
|
+
'**/__tests__/**',
|
|
48
|
+
'**/*.config.*',
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Define config that extends the base.
|
|
55
|
+
* Use for packages that don't need the Nuxt environment.
|
|
56
|
+
*/
|
|
57
|
+
export const sharedVitestConfig = defineConfig({
|
|
58
|
+
test: baseTestConfig,
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
export default sharedVitestConfig
|