@forsakringskassan/cypress-config 1.1.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
@@ -2,6 +2,22 @@
2
2
 
3
3
  Sharable Cypress configuration building blocks for Försäkringskassan.
4
4
 
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install --save-dev @forsakringskassan/cypress-config
9
+ ```
10
+
11
+ If you previously had these packages installed, they can be uninstalled:
12
+
13
+ ```bash
14
+ npm rm mocha-multi-reporter
15
+ ```
16
+
17
+ - [Usage](#usage)
18
+ - [docs-generator](#docs-generator)
19
+ - [HTML-Validate](#html-validate)
20
+
5
21
  ## Usage
6
22
 
7
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:
@@ -47,6 +63,42 @@ configure({
47
63
 
48
64
  See the various components for details.
49
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
+
50
102
  ### HTML-Validate
51
103
 
52
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
@@ -16,6 +16,14 @@ export declare type ConfigOptions = Parameters<typeof defineConfig_2>[0];
16
16
  export declare const defaultConfig: Readonly<{
17
17
  allowCypressEnv: false;
18
18
  video: false;
19
+ defaultBrowser: string;
20
+ reporter: string;
21
+ reporterOptions: {
22
+ reporterEnabled: string;
23
+ mochaJunitReporterReporterOptions: {
24
+ mochaFile: string;
25
+ };
26
+ };
19
27
  component: {
20
28
  devServer: {
21
29
  framework: "vue";
@@ -34,6 +42,22 @@ export declare function defineConfig(_rootDir: string, userConfig?: Omit<ConfigO
34
42
  component?: Partial<ConfigOptions["component"]>;
35
43
  }): Readonly<ConfigOptions>;
36
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
+
37
61
  /**
38
62
  * Preconfigured `cypress-html-validate` plugin.
39
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";
@@ -197,11 +207,22 @@ function htmlValidatePlugin(on, cypressConfig, userConfig, userOptions) {
197
207
  // src/default-config.ts
198
208
  import { createRequire as createRequire2 } from "node:module";
199
209
  var require3 = createRequire2(import.meta.url);
210
+ var isGithub = Boolean(process.env["GITHUB_ACTION"]);
200
211
  var defaultConfig = Object.freeze({
201
212
  allowCypressEnv: false,
202
213
  /* disable video recording, it is to slow both on remote machines and on
203
214
  * CI/CD testing. */
204
215
  video: false,
216
+ /* use chrome instead of electron as default browser */
217
+ defaultBrowser: "chrome",
218
+ /* reporter configuration */
219
+ reporter: require3.resolve("mocha-multi-reporters"),
220
+ reporterOptions: {
221
+ reporterEnabled: isGithub ? "spec, github-actions, mocha-junit-reporter" : "spec, mocha-junit-reporter",
222
+ mochaJunitReporterReporterOptions: {
223
+ mochaFile: "test-results/cypress-test-output_[hash].xml"
224
+ }
225
+ },
205
226
  component: {
206
227
  devServer: {
207
228
  framework: "vue",
@@ -221,5 +242,6 @@ function defineConfig(_rootDir, userConfig) {
221
242
  export {
222
243
  defaultConfig,
223
244
  defineConfig,
245
+ docsGeneratorPlugin,
224
246
  htmlValidatePlugin
225
247
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forsakringskassan/cypress-config",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "description": "Sharable Cypress configuration building blocks for Försäkringskassan",
5
5
  "keywords": [
6
6
  "cypress"
@@ -39,13 +39,20 @@
39
39
  "dist"
40
40
  ],
41
41
  "dependencies": {
42
- "cypress-html-validate": "9.0.0"
42
+ "cypress-html-validate": "9.0.0",
43
+ "mocha-multi-reporters": "1.5.1"
43
44
  },
44
45
  "peerDependencies": {
45
46
  "@fkui/vue": ">= 6.0.0",
47
+ "@forsakringskassan/docs-generator": "^3.0.0",
46
48
  "cypress": "^15.17.0",
47
49
  "html-validate": ">= 8.0.0"
48
50
  },
51
+ "peerDependenciesMeta": {
52
+ "@forsakringskassan/docs-generator": {
53
+ "optional": true
54
+ }
55
+ },
49
56
  "engines": {
50
57
  "node": "^22.16 || >= 24",
51
58
  "npm": ">= 7"