@jahia/cypress 8.0.0 → 8.1.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.
Files changed (56) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +65 -0
  3. package/dist/injections/bash-data.d.ts +1 -0
  4. package/dist/injections/bash-data.js +57 -0
  5. package/dist/injections/chars-data.d.ts +1 -0
  6. package/dist/injections/chars-data.js +25 -0
  7. package/dist/injections/htmlentities-data.d.ts +1 -0
  8. package/dist/injections/htmlentities-data.js +22 -0
  9. package/dist/injections/numbers-data.d.ts +1 -0
  10. package/dist/injections/numbers-data.js +66 -0
  11. package/dist/injections/sql-data.d.ts +1 -0
  12. package/dist/injections/sql-data.js +82 -0
  13. package/dist/injections/xss-data.d.ts +1 -0
  14. package/dist/injections/xss-data.js +740 -0
  15. package/dist/support/apollo/apollo.d.ts +2 -0
  16. package/dist/support/apollo/apollo.js +77 -15
  17. package/dist/support/browserHelper.d.ts +10 -0
  18. package/dist/support/browserHelper.js +167 -0
  19. package/dist/support/index.d.ts +3 -0
  20. package/dist/support/index.js +3 -0
  21. package/dist/support/jfaker.d.ts +60 -0
  22. package/dist/support/jfaker.js +241 -0
  23. package/dist/support/modSince.d.ts +52 -0
  24. package/dist/support/modSince.js +185 -0
  25. package/dist/support/provisioning/executeGroovy.js +41 -2
  26. package/dist/support/provisioning/runProvisioningScript.d.ts +1 -1
  27. package/dist/support/provisioning/runProvisioningScript.js +84 -7
  28. package/dist/support/registerSupport.js +34 -0
  29. package/dist/utils/JahiaPlatformHelper.d.ts +9 -0
  30. package/dist/utils/JahiaPlatformHelper.js +17 -6
  31. package/docs/browser-helper.md +158 -0
  32. package/docs/jfaker.md +450 -0
  33. package/package.json +3 -1
  34. package/src/injections/bash-data.ts +54 -0
  35. package/src/injections/chars-data.ts +22 -0
  36. package/src/injections/htmlentities-data.ts +19 -0
  37. package/src/injections/numbers-data.ts +63 -0
  38. package/src/injections/sql-data.ts +79 -0
  39. package/src/injections/xss-data.ts +737 -0
  40. package/src/support/apollo/apollo.ts +74 -11
  41. package/src/support/browserHelper.ts +186 -0
  42. package/src/support/index.ts +3 -0
  43. package/src/support/jfaker.ts +245 -0
  44. package/src/support/modSince.ts +229 -0
  45. package/src/support/provisioning/executeGroovy.md +7 -1
  46. package/src/support/provisioning/executeGroovy.ts +46 -2
  47. package/src/support/provisioning/runProvisioningScript.ts +89 -12
  48. package/src/support/registerSupport.ts +29 -0
  49. package/src/utils/JahiaPlatformHelper.ts +16 -5
  50. package/tests/cypress/e2e/jfaker.spec.ts +411 -0
  51. package/tests/cypress/e2e/modSince.spec.ts +334 -0
  52. package/tests/cypress.config.ts +23 -0
  53. package/tests/package.json +41 -0
  54. package/tests/reporter-config.json +13 -0
  55. package/tests/yarn.lock +8578 -0
  56. package/tsconfig.json +3 -0
@@ -0,0 +1,334 @@
1
+ import '../../../src/support/apollo/apollo';
2
+ import '../../../src/support/apollo/apolloClient';
3
+ import {modSince, initializeVersionSupport, JAHIA_VERSION_ENV_VAR} from '../../../src/support/modSince';
4
+
5
+ type ItSinceCall = (requiredVersion: string, title: string, fn?: (...args: unknown[]) => unknown) => Mocha.Test;
6
+ type DescribeSinceCall = (requiredVersion: string, title: string, fn: (this: Mocha.Suite) => void) => Mocha.Suite;
7
+
8
+ // Enable version gating
9
+ modSince.enable();
10
+
11
+ // Stub apollo command
12
+ Cypress.Commands.add('apolloClient', (() => {
13
+ return cy.wrap({} as unknown);
14
+ }) as Cypress.CommandFn<'apolloClient'>);
15
+
16
+ Cypress.Commands.add('apollo', (() => {
17
+ return cy.wrap({
18
+ data: {
19
+ admin: {
20
+ jahia: {
21
+ version: {
22
+ release: '8.2.0-SNAPSHOT'
23
+ }
24
+ }
25
+ }
26
+ }
27
+ });
28
+ }) as Cypress.CommandFn<'apollo'>);
29
+
30
+ describe('itSince support', () => {
31
+ describe('registration', () => {
32
+ it('attaches the since helper to it and it.only', () => {
33
+ expect(it.since).to.be.a('function');
34
+ expect(it.only.since).to.be.a('function');
35
+ });
36
+
37
+ it('attaches the since helper to describe and describe.only', () => {
38
+ expect(describe.since).to.be.a('function');
39
+ expect(describe.only.since).to.be.a('function');
40
+ });
41
+
42
+ it('attaches the since helper to it.skip and describe.skip', () => {
43
+ expect(it.skip.since).to.be.a('function');
44
+ expect(describe.skip.since).to.be.a('function');
45
+ });
46
+
47
+ it('throws clear error when it.since args are swapped', () => {
48
+ expect(() => {
49
+ (it.since as unknown as ItSinceCall)(
50
+ 'my test title',
51
+ '8.2.0',
52
+ () => {
53
+ // no-op
54
+ }
55
+ );
56
+ }).to.throw('[it.since] Invalid version: "my test title" (arguments appear swapped).');
57
+ });
58
+
59
+ it('throws clear error when describe.since args are swapped', () => {
60
+ expect(() => {
61
+ (describe.since as unknown as (requiredVersion: string, title: string, fn: (this: Mocha.Suite) => void) => Mocha.Suite)(
62
+ 'my suite title',
63
+ '8.2.0',
64
+ () => {
65
+ // no-op
66
+ }
67
+ );
68
+ }).to.throw('[describe.since] Invalid version: "my suite title" (arguments appear swapped).');
69
+ });
70
+ });
71
+
72
+ describe('skip.since proper title usage', () => {
73
+ const skippedItTitle = 'keeps it.skip.since description as title';
74
+ const skippedSuiteTitle = 'keeps describe.skip.since description as title';
75
+ let skippedItRan = false;
76
+ let skippedDescribeRan = false;
77
+
78
+ const skippedIt = it.skip.since('8.2.0', skippedItTitle, () => {
79
+ skippedItRan = true;
80
+ });
81
+
82
+ const skippedSuite = describe.skip.since('8.2.0', skippedSuiteTitle, () => {
83
+ it('never runs in skipped describe.since suite', () => {
84
+ skippedDescribeRan = true;
85
+ });
86
+ });
87
+
88
+ it('keeps user-provided title for it.skip.since', () => {
89
+ expect(skippedIt.title).to.equal(skippedItTitle);
90
+ });
91
+
92
+ it('keeps user-provided title for describe.skip.since', () => {
93
+ expect(skippedSuite.title).to.equal(skippedSuiteTitle);
94
+ });
95
+
96
+ it('does not execute callback for it.skip.since', () => {
97
+ expect(skippedItRan).to.equal(false);
98
+ });
99
+
100
+ it('does not execute tests inside describe.skip.since', () => {
101
+ expect(skippedDescribeRan).to.equal(false);
102
+ });
103
+ });
104
+
105
+ describe('skip backward compatibility', () => {
106
+ const compatItTitle = 'uses title for accidental it.skip(version, title, fn)';
107
+ const compatDescribeTitle = 'uses title for accidental describe.skip(version, title, fn)';
108
+ let compatItRan = false;
109
+ let compatDescribeRan = false;
110
+
111
+ const compatIt = (it.skip as unknown as ItSinceCall)(
112
+ '8.3.5.0',
113
+ compatItTitle,
114
+ () => {
115
+ compatItRan = true;
116
+ }
117
+ );
118
+
119
+ const compatDescribe = (describe.skip as unknown as DescribeSinceCall)(
120
+ '8.3.5.0',
121
+ compatDescribeTitle,
122
+ () => {
123
+ it('must not run inside compat skipped describe', () => {
124
+ compatDescribeRan = true;
125
+ });
126
+ }
127
+ );
128
+
129
+ it('keeps title for accidental it.skip(version, title, fn)', () => {
130
+ expect(compatIt.title).to.equal(compatItTitle);
131
+ });
132
+
133
+ it('keeps title for accidental describe.skip(version, title, fn)', () => {
134
+ expect(compatDescribe.title).to.equal(compatDescribeTitle);
135
+ });
136
+
137
+ it('does not execute callback for accidental it.skip(version, title, fn)', () => {
138
+ expect(compatItRan).to.equal(false);
139
+ });
140
+
141
+ it('does not execute tests for accidental describe.skip(version, title, fn)', () => {
142
+ expect(compatDescribeRan).to.equal(false);
143
+ });
144
+ });
145
+
146
+ describe('version initialization', () => {
147
+ beforeEach(() => {
148
+ Cypress.env(JAHIA_VERSION_ENV_VAR, '');
149
+ });
150
+
151
+ it('returns cached env version without fetching from GraphQL', () => {
152
+ Cypress.env(JAHIA_VERSION_ENV_VAR, '9.9.9');
153
+ // Use `any` here because custom commands are not part of Cypress's typed EventEmitter keys.
154
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
155
+ const cyAny = cy as any;
156
+ const apolloClientSpy = cy.spy(cyAny, 'apolloClient').as('apolloClientSpy');
157
+ const apolloSpy = cy.spy(cyAny, 'apollo').as('apolloSpy');
158
+
159
+ return initializeVersionSupport().then(version => {
160
+ expect(version).to.equal('9.9.9');
161
+ expect(Cypress.env(JAHIA_VERSION_ENV_VAR)).to.equal('9.9.9');
162
+ expect(apolloClientSpy).to.not.have.been.called;
163
+ expect(apolloSpy).to.not.have.been.called;
164
+ });
165
+ });
166
+
167
+ it('stores normalized Jahia version in Cypress.env', () => {
168
+ return initializeVersionSupport().then(version => {
169
+ expect(version).to.equal('8.2.0');
170
+ expect(Cypress.env(JAHIA_VERSION_ENV_VAR)).to.equal('8.2.0');
171
+ });
172
+ });
173
+ });
174
+
175
+ describe('runtime gating', () => {
176
+ describe('it.since title handling', () => {
177
+ const supportedTitle = 'keeps title for supported it.since test';
178
+ const skippedTitle = 'keeps title for skipped it.since test';
179
+ let supportedRan = false;
180
+ let skippedRan = false;
181
+
182
+ beforeEach(() => {
183
+ Cypress.env(JAHIA_VERSION_ENV_VAR, '8.1.0');
184
+ });
185
+
186
+ const supportedTest = it.since('8.1.0', supportedTitle, () => {
187
+ supportedRan = true;
188
+ });
189
+
190
+ const skippedTest = it.since('8.2.0', skippedTitle, () => {
191
+ skippedRan = true;
192
+ });
193
+
194
+ it('keeps user-provided title for supported it.since', () => {
195
+ expect(supportedTest.title).to.equal(supportedTitle);
196
+ });
197
+
198
+ it('keeps user-provided title for skipped it.since', () => {
199
+ expect(skippedTest.title).to.equal(skippedTitle);
200
+ });
201
+
202
+ it('executes callback for supported it.since', () => {
203
+ expect(supportedRan).to.equal(true);
204
+ });
205
+
206
+ it('does not execute callback for skipped it.since', () => {
207
+ expect(skippedRan).to.equal(false);
208
+ });
209
+ });
210
+
211
+ describe('supported version', () => {
212
+ let ran = false;
213
+
214
+ beforeEach(() => {
215
+ Cypress.env(JAHIA_VERSION_ENV_VAR, '8.2.0');
216
+ });
217
+
218
+ it.since('8.2.0', 'runs test callback when current version matches requirement', () => {
219
+ ran = true;
220
+ });
221
+
222
+ it('executes callback for matching version', () => {
223
+ expect(ran).to.equal(true);
224
+ });
225
+ });
226
+
227
+ describe('unsupported version', () => {
228
+ let ran = false;
229
+
230
+ beforeEach(() => {
231
+ Cypress.env(JAHIA_VERSION_ENV_VAR, '8.1.0');
232
+ });
233
+
234
+ it.since('8.2.0', 'skips test callback when current version is lower than requirement', () => {
235
+ ran = true;
236
+ });
237
+
238
+ it('does not execute callback for lower version', () => {
239
+ expect(ran).to.equal(false);
240
+ });
241
+ });
242
+
243
+ describe('missing version', () => {
244
+ let ran = false;
245
+
246
+ beforeEach(() => {
247
+ Cypress.env(JAHIA_VERSION_ENV_VAR, '');
248
+ });
249
+
250
+ it.since('8.2.0', 'skips test callback when version is missing', () => {
251
+ ran = true;
252
+ });
253
+
254
+ it('does not execute callback when version is empty', () => {
255
+ expect(ran).to.equal(false);
256
+ });
257
+ });
258
+
259
+ describe('config overload', () => {
260
+ let ran = false;
261
+
262
+ beforeEach(() => {
263
+ Cypress.env(JAHIA_VERSION_ENV_VAR, '8.2.0');
264
+ });
265
+
266
+ it.since(
267
+ '8.2.0',
268
+ 'supports Cypress config overload',
269
+ {defaultCommandTimeout: 10000},
270
+ () => {
271
+ ran = true;
272
+ }
273
+ );
274
+
275
+ it('executes callback for config overload form', () => {
276
+ expect(ran).to.equal(true);
277
+ });
278
+ });
279
+
280
+ describe('describe.since supported version', () => {
281
+ let suiteRan = false;
282
+
283
+ before(() => {
284
+ Cypress.env(JAHIA_VERSION_ENV_VAR, '8.2.0');
285
+ });
286
+
287
+ describe.since('8.2.0', 'runs suite when current version matches requirement', () => {
288
+ it('executes suite tests for matching version', () => {
289
+ suiteRan = true;
290
+ });
291
+
292
+ it('executes suite callback for matching version', () => {
293
+ expect(suiteRan).to.equal(true);
294
+ });
295
+ });
296
+ });
297
+
298
+ describe('describe.since unsupported version', () => {
299
+ let suiteRan = false;
300
+
301
+ before(() => {
302
+ Cypress.env(JAHIA_VERSION_ENV_VAR, '8.1.0');
303
+ });
304
+
305
+ describe.since('8.2.0', 'skips suite when current version is lower than requirement', () => {
306
+ it('does not execute suite tests for lower version', () => {
307
+ suiteRan = true;
308
+ });
309
+ });
310
+
311
+ it('does not execute suite callback for lower version', () => {
312
+ expect(suiteRan).to.equal(false);
313
+ });
314
+ });
315
+
316
+ describe('describe.since missing version', () => {
317
+ let suiteRan = false;
318
+
319
+ before(() => {
320
+ Cypress.env(JAHIA_VERSION_ENV_VAR, '');
321
+ });
322
+
323
+ describe.since('8.2.0', 'skips suite when version is missing', () => {
324
+ it('does not execute suite tests when version is empty', () => {
325
+ suiteRan = true;
326
+ });
327
+ });
328
+
329
+ it('does not execute suite callback when version is missing', () => {
330
+ expect(suiteRan).to.equal(false);
331
+ });
332
+ });
333
+ });
334
+ });
@@ -0,0 +1,23 @@
1
+ import {defineConfig} from 'cypress';
2
+
3
+ export default defineConfig({
4
+ reporter: 'cypress-multi-reporters',
5
+
6
+ reporterOptions: {
7
+ configFile: 'reporter-config.json'
8
+ },
9
+
10
+ e2e: {
11
+ // No baseUrl needed for unit tests
12
+ // Spec pattern for test files
13
+ specPattern: 'cypress/e2e/**/*.spec.ts',
14
+ // Support file
15
+ supportFile: false,
16
+ // Video and screenshot settings
17
+ video: false,
18
+ screenshotOnRunFailure: false,
19
+ setupNodeEvents(on, config) {
20
+ return config;
21
+ }
22
+ }
23
+ });
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@jahia/cypress-tests",
3
+ "private": true,
4
+ "scripts": {
5
+ "e2e:ci": "cypress run",
6
+ "e2e:debug": "cypress open",
7
+ "report:merge": "mochawesome-merge results/reports/cypress*.json > results/reports/report.json && rm results/reports/cypress*.json",
8
+ "report:html": "marge --inline results/reports/report.json --reportDir results/reports/"
9
+ },
10
+ "license": "MIT",
11
+ "devDependencies": {
12
+ "@jahia/eslint-config": "^2.2.0",
13
+ "@jahia/jahia-reporter": "^2.1.0",
14
+ "@types/node": "^20.11.0",
15
+ "@typescript-eslint/eslint-plugin": "^8.57.1",
16
+ "@typescript-eslint/parser": "^8.57.1",
17
+ "cross-fetch": "^4.1.0",
18
+ "cypress": "^15.12.0",
19
+ "cypress-multi-reporters": "^2.0.5",
20
+ "cypress-wait-until": "^3.0.2",
21
+ "eslint": "^9.39.4",
22
+ "eslint-plugin-cypress": "^6.2.0",
23
+ "eslint-plugin-jest": "^29.15.0",
24
+ "eslint-plugin-react": "^7.37.5",
25
+ "eslint-plugin-react-hooks": "^7.0.1",
26
+ "mocha": "^11.7.5",
27
+ "mocha-junit-reporter": "^2.2.1",
28
+ "mochawesome": "^7.1.4",
29
+ "mochawesome-merge": "^5.1.1",
30
+ "mochawesome-report-generator": "^6.3.2",
31
+ "typescript": "^5.9.3"
32
+ },
33
+ "dependencies": {
34
+ "@apollo/client": "^4.1.6",
35
+ "cypress-real-events": "^1.15.0",
36
+ "graphql": "^16.13.1",
37
+ "graphql-tag": "^2.12.6",
38
+ "rxjs": "^7.8.2"
39
+ },
40
+ "packageManager": "yarn@4.12.0"
41
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "reporterEnabled": "mochawesome, mocha-junit-reporter",
3
+ "mochaJunitReporterReporterOptions": {
4
+ "mochaFile": "./results/xml_reports/results-[hash].xml"
5
+ },
6
+ "mochawesomeReporterOptions": {
7
+ "reportDir": "./results/reports/",
8
+ "reportFilename": "cypress",
9
+ "overwrite": false,
10
+ "html": true,
11
+ "json": true
12
+ }
13
+ }