@forsakringskassan/cypress-config 1.2.0 → 1.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/README.md CHANGED
@@ -14,6 +14,10 @@ If you previously had these packages installed, they can be uninstalled:
14
14
  npm rm mocha-multi-reporter
15
15
  ```
16
16
 
17
+ - [Usage](#usage)
18
+ - [docs-generator](#docs-generator)
19
+ - [HTML-Validate](#html-validate)
20
+
17
21
  ## Usage
18
22
 
19
23
  In `cypress.config.ts`, replace the vanilla `defineConfig()` helper from `cypress` with `@forsakringskassan/cypress-config` and pass in `import.meta.dirname` as the first parameter:
@@ -59,6 +63,42 @@ configure({
59
63
 
60
64
  See the various components for details.
61
65
 
66
+ ### docs-generator
67
+
68
+ A plugin to get all pages and examples generated by `@forsakringskassan/docs-generator`.
69
+ This is typically only useful in E2E testing.
70
+
71
+ ```ts
72
+ import {
73
+ defineConfig,
74
+ docsGeneratorPlugin,
75
+ } from "@forsakringskassan/cypress-config";
76
+ /
77
+ const docs = new Generator(import.meta.url, {});
78
+ const sourceFiles = [];
79
+
80
+ export default defineConfig(import.meta.dirname, {
81
+ e2e: {
82
+ async setupNodeEvents(on, config) {
83
+ config = await docsGeneratorPlugin(on, config, docs, sourceFiles);
84
+ return config;
85
+ },
86
+ },
87
+ });
88
+ ```
89
+
90
+ The pages are retrieved using `Cypress.expose("pages")` which contains additional information:
91
+
92
+ ```ts
93
+ const pages = Cypress.expose("pages") ?? [];
94
+ for (const page of pages) {
95
+ const { path, examples } = page;
96
+ /* ... */
97
+ }
98
+ ```
99
+
100
+ See [manifest documentation](https://forsakringskassan.github.io/docs-generator/latest/processors/manifest.html) for details about what each page entry contains.
101
+
62
102
  ### HTML-Validate
63
103
 
64
104
  A preconfigured [HTML-validate](https://html-validate.org/) plugin ([cypress-html-validate](https://gitlab.com/html-validate/cypress-html-validate/)) is exported as `htmlValidatePlugin`:
package/dist/index.d.ts CHANGED
@@ -42,6 +42,22 @@ export declare function defineConfig(_rootDir: string, userConfig?: Omit<ConfigO
42
42
  component?: Partial<ConfigOptions["component"]>;
43
43
  }): Readonly<ConfigOptions>;
44
44
 
45
+ /**
46
+ * Fetch document pages and examples for documentation generated by
47
+ * `@forsakringskassan/docs-generator`.
48
+ *
49
+ * @public
50
+ * @since v1.3.0
51
+ * @param on - Cypress `on` callback from `setupNodeEvents`.
52
+ * @param config - Cypress `config` parameter from `setupNodeEvents`.
53
+ * @param docs - A `Generator` instance.
54
+ * @param sourceFiles - A set of source files generate manifest for.
55
+ * @returns A promise resolved with the updated cypress configuration.
56
+ */
57
+ export declare function docsGeneratorPlugin<T extends unknown[]>(_on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions, docs: {
58
+ manifest(sourceFiles: T): Promise<unknown>;
59
+ }, sourceFiles: T): Promise<Cypress.PluginConfigOptions>;
60
+
45
61
  /**
46
62
  * Preconfigured `cypress-html-validate` plugin.
47
63
  *
package/dist/index.mjs CHANGED
@@ -131,6 +131,16 @@ var require_cjs = __commonJS({
131
131
  }
132
132
  });
133
133
 
134
+ // src/plugins/docs-generator.ts
135
+ async function docsGeneratorPlugin(_on, config, docs, sourceFiles) {
136
+ const manifest = await docs.manifest(sourceFiles);
137
+ const pages = manifest.pages.filter((it) => {
138
+ return it.path.endsWith(".html");
139
+ });
140
+ config.expose["pages"] = pages;
141
+ return config;
142
+ }
143
+
134
144
  // src/plugins/html-validate.ts
135
145
  import { createRequire } from "node:module";
136
146
  import "cypress";
@@ -232,5 +242,6 @@ function defineConfig(_rootDir, userConfig) {
232
242
  export {
233
243
  defaultConfig,
234
244
  defineConfig,
245
+ docsGeneratorPlugin,
235
246
  htmlValidatePlugin
236
247
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forsakringskassan/cypress-config",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Sharable Cypress configuration building blocks for Försäkringskassan",
5
5
  "keywords": [
6
6
  "cypress"
@@ -44,9 +44,15 @@
44
44
  },
45
45
  "peerDependencies": {
46
46
  "@fkui/vue": ">= 6.0.0",
47
+ "@forsakringskassan/docs-generator": "^3.0.0",
47
48
  "cypress": "^15.17.0",
48
49
  "html-validate": ">= 8.0.0"
49
50
  },
51
+ "peerDependenciesMeta": {
52
+ "@forsakringskassan/docs-generator": {
53
+ "optional": true
54
+ }
55
+ },
50
56
  "engines": {
51
57
  "node": "^22.16 || >= 24",
52
58
  "npm": ">= 7"