glib-web 4.41.0 → 4.41.1
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/.nycrc.json +18 -0
- package/cypress/support/e2e.ts +2 -1
- package/cypress.config.ts +3 -1
- package/doc/TESTING.md +14 -0
- package/package.json +12 -3
- package/plugins/viteDefaultConfig.js +88 -0
- package/utils/type.js +1 -1
package/.nycrc.json
ADDED
package/cypress/support/e2e.ts
CHANGED
package/cypress.config.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { defineConfig } from "cypress";
|
|
2
|
+
import codeCoverageTask from "@cypress/code-coverage/task";
|
|
2
3
|
|
|
3
4
|
export default defineConfig({
|
|
4
5
|
e2e: {
|
|
5
6
|
setupNodeEvents(on, config) {
|
|
6
|
-
|
|
7
|
+
codeCoverageTask(on, config);
|
|
8
|
+
return config;
|
|
7
9
|
},
|
|
8
10
|
},
|
|
9
11
|
});
|
package/doc/TESTING.md
CHANGED
|
@@ -54,3 +54,17 @@ You **cannot write frontend tests in isolation**.
|
|
|
54
54
|
---
|
|
55
55
|
|
|
56
56
|
These 6 concepts explain **why the test structure exists** and **what you need to get started**. Everything else (selectors, assertions, etc.) is standard Cypress mechanics.
|
|
57
|
+
|
|
58
|
+
## Cypress Coverage Workflow
|
|
59
|
+
|
|
60
|
+
- **Prerequisites**: Keep the backend `glib-web` server running with the matching `test_page/*` fixtures (same as normal Cypress runs) and make sure the frontend package is linked into that app: `yarn link glib-web` (run from the backend repo).
|
|
61
|
+
- **Instrument code**: Coverage is only collected when `VITE_COVERAGE=true` because `vite-plugin-istanbul` has `requireEnv` enabled.
|
|
62
|
+
- **Step-by-step run**:
|
|
63
|
+
1. From the backend repo (`glib-web`), ensure the link is active: `yarn link glib-web`.
|
|
64
|
+
2. From the backend repo, start Vite with instrumentation: `VITE_COVERAGE=true bin/vite dev`.
|
|
65
|
+
3. From the backend repo, start Rails: `bin/rails s`.
|
|
66
|
+
4. From this repo (`glib-web-npm`), execute `yarn test:coverage` to run Cypress and emit coverage reports via `nyc` (uses `.nycrc.json`).
|
|
67
|
+
- **Manual run (if you need custom flags)**:
|
|
68
|
+
1. `VITE_COVERAGE=true yarn test`
|
|
69
|
+
2. `nyc report` (or add reporters, e.g. `nyc report --reporter=lcov`).
|
|
70
|
+
- **Where to read results**: HTML report at `coverage/index.html`; summary printed in the terminal; raw data in `.nyc_output` and `coverage/coverage-final.json`.
|
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
|
+
"type": "module",
|
|
2
3
|
"name": "glib-web",
|
|
3
|
-
"version": "4.41.
|
|
4
|
+
"version": "4.41.1",
|
|
4
5
|
"description": "",
|
|
5
6
|
"main": "index.js",
|
|
6
7
|
"scripts": {
|
|
7
|
-
"test": "cypress run --browser chrome"
|
|
8
|
+
"test": "cypress run --browser chrome",
|
|
9
|
+
"test:coverage": "VITE_COVERAGE=true cypress run --browser chrome && nyc report"
|
|
8
10
|
},
|
|
9
11
|
"author": "",
|
|
10
12
|
"license": "ISC",
|
|
@@ -42,11 +44,18 @@
|
|
|
42
44
|
"vuetify": "3.8.6"
|
|
43
45
|
},
|
|
44
46
|
"devDependencies": {
|
|
47
|
+
"@cypress/code-coverage": "^3.14.7",
|
|
45
48
|
"@types/chart.js": "^2.9.34",
|
|
49
|
+
"@vitejs/plugin-vue": "^6.0.2",
|
|
46
50
|
"cypress": "^13.13.1",
|
|
47
51
|
"eslint": "^8.36.0",
|
|
48
52
|
"eslint-plugin-vue": "^9.26.0",
|
|
49
53
|
"prettier": "^1.18.2",
|
|
50
|
-
"typescript": "^4.9.5"
|
|
54
|
+
"typescript": "^4.9.5",
|
|
55
|
+
"vite": "^7.2.7",
|
|
56
|
+
"vite-plugin-compression": "^0.5.1",
|
|
57
|
+
"vite-plugin-environment": "^1.1.3",
|
|
58
|
+
"vite-plugin-istanbul": "^7.2.1",
|
|
59
|
+
"vite-plugin-ruby": "^5.1.1"
|
|
51
60
|
}
|
|
52
61
|
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { defineConfig } from "vite";
|
|
4
|
+
import RubyPlugin from "vite-plugin-ruby";
|
|
5
|
+
import vue from "@vitejs/plugin-vue";
|
|
6
|
+
import viteCompression from "vite-plugin-compression";
|
|
7
|
+
import EnvironmentPlugin from "vite-plugin-environment";
|
|
8
|
+
import istanbul from "vite-plugin-istanbul";
|
|
9
|
+
import * as TypeUtils from "../utils/type.js";
|
|
10
|
+
|
|
11
|
+
function pickStringArray(value) {
|
|
12
|
+
if (!TypeUtils.isArray(value)) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const filtered = value.filter((item) => TypeUtils.isString(item));
|
|
17
|
+
return filtered.length > 0 ? filtered : null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function resolveGlibRoot(customRoot) {
|
|
21
|
+
if (TypeUtils.isString(customRoot)) {
|
|
22
|
+
return customRoot;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return path.resolve(fileURLToPath(new URL("..", import.meta.url)));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Builds the default Vite configuration used by glib projects.
|
|
31
|
+
*
|
|
32
|
+
* @param {object} [options] Configuration overrides.
|
|
33
|
+
* @param {string} [options.glibRoot] Root directory for the glib package (defaults to repo root).
|
|
34
|
+
* @param {string} [options.aliasName] Module alias name for glib imports.
|
|
35
|
+
* @param {string} [options.aliasPath] Filesystem path used for the alias.
|
|
36
|
+
* @param {string} [options.workspaceRoot] Workspace root for coverage and path resolution.
|
|
37
|
+
* @param {string[]} [options.istanbulInclude] Globs to include when running Istanbul.
|
|
38
|
+
* @param {string[]} [options.environmentVariables] Environment variables exposed to the client.
|
|
39
|
+
* @param {string[]} [options.serverAllow] Additional filesystem paths allowed by Vite dev server.
|
|
40
|
+
* @param {import("vite").Plugin[]} [options.plugins] Extra Vite plugins to append.
|
|
41
|
+
* @returns {import("vite").UserConfig} Config object passed to `defineConfig`.
|
|
42
|
+
*/
|
|
43
|
+
function useGlibViteDefineConfig(options = {}) {
|
|
44
|
+
if (TypeUtils.isNotNull(globalThis.window)) {
|
|
45
|
+
throw new Error("useGlibViteDefineConfig is only available in Node environments.");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const configOptions = TypeUtils.isObject(options) && !TypeUtils.isArray(options) ? options : {};
|
|
49
|
+
|
|
50
|
+
const glibRoot = resolveGlibRoot(configOptions.glibRoot);
|
|
51
|
+
const aliasName = TypeUtils.isString(configOptions.aliasName) ? configOptions.aliasName : "glib-web";
|
|
52
|
+
const aliasPath = TypeUtils.isString(configOptions.aliasPath) ? configOptions.aliasPath : glibRoot;
|
|
53
|
+
const workspaceRoot = TypeUtils.isString(configOptions.workspaceRoot)
|
|
54
|
+
? configOptions.workspaceRoot
|
|
55
|
+
: path.resolve(glibRoot, "..");
|
|
56
|
+
const istanbulInclude = pickStringArray(configOptions.istanbulInclude) ?? [`${path.basename(glibRoot)}/**/*`];
|
|
57
|
+
const environmentVariables = pickStringArray(configOptions.environmentVariables) ?? ["VITE_GMAPS_API_KEY"];
|
|
58
|
+
const serverAllow = pickStringArray(configOptions.serverAllow) ?? [glibRoot];
|
|
59
|
+
const additionalPlugins = TypeUtils.isArray(configOptions.plugins) ? configOptions.plugins : [];
|
|
60
|
+
|
|
61
|
+
return defineConfig({
|
|
62
|
+
server: {
|
|
63
|
+
fs: {
|
|
64
|
+
allow: serverAllow.map((allowedPath) => path.resolve(allowedPath))
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
resolve: {
|
|
68
|
+
alias: {
|
|
69
|
+
[aliasName]: path.resolve(aliasPath)
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
plugins: [
|
|
73
|
+
vue(),
|
|
74
|
+
RubyPlugin(),
|
|
75
|
+
istanbul({
|
|
76
|
+
cwd: path.resolve(workspaceRoot),
|
|
77
|
+
include: istanbulInclude,
|
|
78
|
+
requireEnv: true
|
|
79
|
+
}),
|
|
80
|
+
viteCompression(),
|
|
81
|
+
EnvironmentPlugin(environmentVariables, { defineOn: "import.meta.env" }),
|
|
82
|
+
...additionalPlugins
|
|
83
|
+
]
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export { useGlibViteDefineConfig };
|
|
88
|
+
export default useGlibViteDefineConfig;
|
package/utils/type.js
CHANGED