@jahia/cypress 4.3.0 → 5.0.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.
@@ -11,12 +11,16 @@ var serverDefaults = {
11
11
  var executeGroovy = function (scriptFile, replacements, jahiaServer) {
12
12
  if (jahiaServer === void 0) { jahiaServer = serverDefaults; }
13
13
  cy.runProvisioningScript({
14
- fileContent: '- executeScript: "' + scriptFile + '"',
15
- type: 'application/yaml'
16
- }, [{
17
- fileName: scriptFile,
18
- replacements: replacements,
19
- type: 'text/plain'
20
- }], jahiaServer).then(function (r) { return r[0]; });
14
+ script: {
15
+ fileContent: '- executeScript: "' + scriptFile + '"',
16
+ type: 'application/yaml'
17
+ },
18
+ files: [{
19
+ fileName: scriptFile,
20
+ replacements: replacements,
21
+ type: 'text/plain'
22
+ }],
23
+ jahiaServer: jahiaServer
24
+ }).then(function (r) { return r[0]; });
21
25
  };
22
26
  exports.executeGroovy = executeGroovy;
@@ -4,9 +4,12 @@ exports.__esModule = true;
4
4
  exports.installBundle = void 0;
5
5
  /// <reference types="cypress" />
6
6
  var installBundle = function (bundleFile) {
7
- cy.runProvisioningScript([{ installBundle: bundleFile }], [{
8
- fileName: bundleFile,
9
- type: 'text/plain'
10
- }]);
7
+ cy.runProvisioningScript({
8
+ script: [{ installBundle: bundleFile }],
9
+ files: [{
10
+ fileName: bundleFile,
11
+ type: 'text/plain'
12
+ }]
13
+ });
11
14
  };
12
15
  exports.installBundle = installBundle;
@@ -1,11 +1,20 @@
1
1
  /// <reference types="cypress" />
2
+ import RequestOptions = Cypress.RequestOptions;
2
3
  declare global {
3
4
  namespace Cypress {
4
5
  interface Chainable<Subject> {
5
- runProvisioningScript(script: FormFile | StringDictionary[], files?: FormFile[], jahiaServer?: JahiaServer): Chainable<any>;
6
+ runProvisioningScript(params: RunProvisioningScriptParams): Chainable<void>;
6
7
  }
7
8
  }
8
9
  }
10
+ export interface RunProvisioningScriptParams {
11
+ script: FormFile | StringDictionary[];
12
+ files?: FormFile[];
13
+ /** Optional, defaults to serverDefaults */
14
+ jahiaServer?: JahiaServer;
15
+ options?: Cypress.Loggable;
16
+ requestOptions?: Partial<RequestOptions>;
17
+ }
9
18
  export declare type StringDictionary = {
10
19
  [key: string]: string;
11
20
  };
@@ -21,4 +30,4 @@ export declare type JahiaServer = {
21
30
  username: string;
22
31
  password: string;
23
32
  };
24
- export declare const runProvisioningScript: (script: FormFile | StringDictionary[], files?: FormFile[], jahiaServer?: JahiaServer, options?: Cypress.Loggable, timeout?: number) => void;
33
+ export declare const runProvisioningScript: ({ script, files, jahiaServer, options, requestOptions }: RunProvisioningScriptParams) => void;
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  exports.__esModule = true;
3
14
  exports.runProvisioningScript = void 0;
4
15
  function processContent(formFile) {
@@ -35,10 +46,8 @@ var serverDefaults = {
35
46
  function isFormFile(script) {
36
47
  return Boolean(script.fileContent || script.fileName);
37
48
  }
38
- // eslint-disable-next-line default-param-last, max-params
39
- var runProvisioningScript = function (script, files, jahiaServer, options, timeout) {
40
- if (jahiaServer === void 0) { jahiaServer = serverDefaults; }
41
- if (options === void 0) { options = { log: true }; }
49
+ var runProvisioningScript = function (_a) {
50
+ var script = _a.script, files = _a.files, _b = _a.jahiaServer, jahiaServer = _b === void 0 ? serverDefaults : _b, _c = _a.options, options = _c === void 0 ? { log: true } : _c, _d = _a.requestOptions, requestOptions = _d === void 0 ? {} : _d;
42
51
  var formData = new FormData();
43
52
  if (isFormFile(script)) {
44
53
  append(script, formData, 'script');
@@ -75,20 +84,11 @@ var runProvisioningScript = function (script, files, jahiaServer, options, timeo
75
84
  }
76
85
  });
77
86
  }
78
- var request = {
79
- url: jahiaServer.url + "/modules/api/provisioning",
80
- method: 'POST',
81
- auth: {
87
+ var request = __assign({ url: jahiaServer.url + "/modules/api/provisioning", method: 'POST', auth: {
82
88
  user: jahiaServer.username,
83
89
  pass: jahiaServer.password,
84
90
  sendImmediately: true
85
- },
86
- body: formData,
87
- log: false
88
- };
89
- if (typeof timeout !== 'undefined') {
90
- request.timeout = timeout;
91
- }
91
+ }, body: formData, log: false }, requestOptions);
92
92
  cy.request(request).then(function (res) {
93
93
  response = res;
94
94
  expect(res.status, 'Script result').to.eq(200);
@@ -5,8 +5,10 @@ exports.uninstallBundle = void 0;
5
5
  /// <reference types="cypress" />
6
6
  var uninstallBundle = function (bundleSymbolicName) {
7
7
  cy.runProvisioningScript({
8
- fileContent: '- uninstallBundle: "' + bundleSymbolicName + '"\n',
9
- type: 'application/yaml'
8
+ script: {
9
+ fileContent: '- uninstallBundle: "' + bundleSymbolicName + '"\n',
10
+ type: 'application/yaml'
11
+ }
10
12
  });
11
13
  };
12
14
  exports.uninstallBundle = uninstallBundle;
@@ -21,9 +21,12 @@ var deleteSite = function (siteKey, jahiaServer) {
21
21
  exports.deleteSite = deleteSite;
22
22
  var enableModule = function (moduleName, siteKey, jahiaServer) {
23
23
  cy.runProvisioningScript({
24
- fileContent: '- enable: "' + moduleName + '"\n site: "' + siteKey + '"',
25
- type: 'application/yaml'
26
- }, undefined, jahiaServer);
24
+ script: {
25
+ fileContent: '- enable: "' + moduleName + '"\n site: "' + siteKey + '"',
26
+ type: 'application/yaml'
27
+ },
28
+ jahiaServer: jahiaServer
29
+ });
27
30
  };
28
31
  exports.enableModule = enableModule;
29
32
  var disableModule = function (moduleName, siteKey) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jahia/cypress",
3
- "version": "4.3.0",
3
+ "version": "5.0.0",
4
4
  "scripts": {
5
5
  "build": "tsc",
6
6
  "lint": "eslint src -c .eslintrc.json --ext .ts --max-warnings=0"
@@ -26,11 +26,15 @@ const serverDefaults = {
26
26
 
27
27
  export const executeGroovy = function (scriptFile: string, replacements?: { [key: string]: string }, jahiaServer: JahiaServer = serverDefaults): void {
28
28
  cy.runProvisioningScript({
29
- fileContent: '- executeScript: "' + scriptFile + '"',
30
- type: 'application/yaml'
31
- }, [{
32
- fileName: scriptFile,
33
- replacements,
34
- type: 'text/plain'
35
- }], jahiaServer).then(r => r[0]);
29
+ script: {
30
+ fileContent: '- executeScript: "' + scriptFile + '"',
31
+ type: 'application/yaml'
32
+ },
33
+ files: [{
34
+ fileName: scriptFile,
35
+ replacements,
36
+ type: 'text/plain'
37
+ }],
38
+ jahiaServer
39
+ }).then(r => r[0]);
36
40
  };
@@ -13,8 +13,11 @@ declare global {
13
13
  }
14
14
 
15
15
  export const installBundle = function (bundleFile: string): void {
16
- cy.runProvisioningScript([{installBundle: bundleFile}], [{
17
- fileName: bundleFile,
18
- type: 'text/plain'
19
- }]);
16
+ cy.runProvisioningScript({
17
+ script: [{installBundle: bundleFile}],
18
+ files: [{
19
+ fileName: bundleFile,
20
+ type: 'text/plain'
21
+ }]
22
+ });
20
23
  };
@@ -1,92 +1,123 @@
1
1
  # runProvisioningScript
2
2
 
3
- This commands execute a provisioning script
3
+ This command executes a provisioning script.
4
4
 
5
- > This can be used to install modules, import sites, execute groovy/graphql/sql script with the help of the provisioning REST API
5
+ > This can be used to install modules, import sites, execute Groovy/GraphQL/SQL scripts with the help of the provisioning REST API.
6
6
 
7
7
  ## Syntax
8
8
 
9
9
  ### Usage
10
10
 
11
- ```
12
- cy.runProvisioningScript({fileName:'prov.yaml', type:'application/yaml'})
13
- cy.runProvisioningScript({fileName:'prov.yaml', type:'application/yaml'}, [{fileName: 'file1.zip'}])
14
- cy.runProvisioningScript({fileContent:'- startBundle: "module"', type:'application/yaml'})
15
- cy.runProvisioningScript({fileContent:'- startBundle: "module"', type:'application/yaml'}, null, {url: 'http://jahia-processing.jahia.net:8080', username: 'root', password: 'root1234'})
11
+ ```javascript
12
+ cy.runProvisioningScript({
13
+ script: { fileName: 'prov.yaml', type: 'application/yaml' }
14
+ });
15
+
16
+ cy.runProvisioningScript({
17
+ script: { fileName: 'prov.yaml', type: 'application/yaml' },
18
+ files: [{ fileName: 'file1.zip' }]
19
+ });
20
+
21
+ cy.runProvisioningScript({
22
+ script: { fileContent: '- startBundle: "module"', type: 'application/yaml' }
23
+ });
24
+
25
+ cy.runProvisioningScript({
26
+ script: { fileContent: '- startBundle: "module"', type: 'application/yaml' },
27
+ jahiaServer: { url: 'http://jahia-processing.jahia.net:8080', username: 'root', password: 'root1234' }
28
+ });
16
29
  ```
17
30
 
18
31
  ### Arguments
19
32
 
20
- #### &gt; script (`FormFile`)
33
+ #### `script` (`FormFile`)
34
+
35
+ The script can be specified either from an external file (using `fileName`) or inline (using `fileContent`).
36
+
37
+ - **fileName**: (`string`) - The name of the script file, located in the `fixtures` folder.
38
+ - **fileContent**: (`string`) - The content of the script. If specified, `fileName` is ignored.
39
+ - **type**: (`string`) - Content type, either `application/yaml` or `application/json`.
40
+
41
+ #### `jahiaServer` (`JahiaServer`)
42
+
43
+ A Jahia server can be specified if there is a need to use something other than the default. This is useful when using Jahia in a cluster, or if there is a need to redirect a provisioning script to a specific Jahia server (e.g., a processing node).
21
44
 
22
- The script can be specified either from an external file (using fileName) or inline (using fileContent)
45
+ - **url**: (`string`) - The URL of the server (e.g., `http://processing.jahia.net:8080`).
46
+ - **username**: (`string`) - The root username.
47
+ - **password**: (`string`) - The password for the root user.
23
48
 
24
- - fileName: (`string`) : The name of the script file, in fixtures folder
25
- - fileContent: (`string`) : The content of the script. If specified, fileName is ignored.
26
- - type: (`string`) : Content type, either `application/yaml` or `application/json`
49
+ #### `files` (`FormFile[]`)
27
50
 
28
- #### &gt; jahiaServer (`JahiaServer`)
51
+ Additional files that can be referenced in the script. When an operation requires a URL, directly specify the file name (without protocol) to use one of these files.
29
52
 
30
- A Jahia server can be specified if there is a need to use something other than default. This is useful when using Jahia in cluster, if there is a need to redirect a provisioning script to a specific Jahia server (for example a processig node).
53
+ - **fileName**: (`string`) - The name of the file, located in the `fixtures` folder.
54
+ - **fileContent**: (`string`) - The content of the file. If specified, `fileName` is ignored.
55
+ - **type**: (`string`) - The content type of the file.
31
56
 
32
- - url: (`string`) : The url of the server (for example: http://processing.jahia.net:8080)
33
- - username: (`string`) : Root user
34
- - password: (`string`) : Password for the root user
57
+ #### `options` (`Cypress.Loggable`)
35
58
 
36
- #### &gt; files (`FormFile[]`)
59
+ Options for the Cypress command.
37
60
 
38
- Additional files that can be referenced in the script. When an operation requires a URL, directly specify the file name (without protocol) to use one these files
61
+ - **log**: (`boolean`) - Indicates whether the command should be logged or not.
39
62
 
40
- - fileName: (`string`) : The name of the file, in fixtures folder
41
- - fileContent: (`string`) : The content of the file. If specified, fileName is ignored.
42
- - type: (`string`) : Content type
63
+ #### `requestOptions` (`RequestOptions`)
43
64
 
44
- #### &gt; options (`Loggable`)
65
+ Additional options for the Cypress request object. Some useful ones include:
45
66
 
46
- - `log` : should the command be logged or not
67
+ - **failOnStatusCode**: (`boolean`) - Useful when you expect a 4xx or 5xx error and need to test it.
68
+ - **timeout**: (`number`) - Useful when you need control over the timeout of the request.
47
69
 
48
70
  ### Yields
49
71
 
50
- The provisioning script result, as JSON object
72
+ The provisioning script result, as a JSON object.
51
73
 
52
74
  ## Examples
53
75
 
54
- ### Execute a script
76
+ ### Execute a Script
55
77
 
56
- Will run the script in `fixtures/provisioning/test.yaml` :
78
+ Will run the script in `fixtures/provisioning/test.yaml`:
57
79
 
58
- ```
59
- cy.runProvisioningScript({fileName:'provisioning/test.yaml', type:'application/yaml'})
80
+ ```javascript
81
+ cy.runProvisioningScript({
82
+ script: { fileName: 'provisioning/test.yaml', type: 'application/yaml' }
83
+ });
60
84
  ```
61
85
 
62
- ### Inline script with additional file
86
+ ### Inline Script with Additional File
63
87
 
64
- Will install the bundle in `fixtures/bundle.jar` :
88
+ Will install the bundle in `fixtures/bundle.jar`:
65
89
 
66
- ```
67
- cy.runProvisioningScript(
68
- {fileContent: '- installBundle: "bundle.jar"',type: 'application/yaml'},
69
- [
70
- { fileName: "bundle.jar", type: 'application/java-archive' }
90
+ ```javascript
91
+ cy.runProvisioningScript({
92
+ script: { fileContent: '- installBundle: "bundle.jar"', type: 'application/yaml' },
93
+ files: [
94
+ { fileName: 'bundle.jar', type: 'application/java-archive' }
71
95
  ]
72
- )
96
+ });
73
97
  ```
74
98
 
75
- ## Rules
99
+ ### Use a Custom Jahia Server
76
100
 
77
- ### Requirements
101
+ Will run the script on a specific Jahia server:
78
102
 
79
- - `cy.useProvisioningScript()` requires being chained off of `cy`.
103
+ ```javascript
104
+ cy.runProvisioningScript({
105
+ script: { fileName: 'prov.yaml', type: 'application/yaml' },
106
+ jahiaServer: { url: 'http://custom-server.jahia.net:8080', username: 'admin', password: 'admin123' }
107
+ });
108
+ ```
109
+
110
+ ## Rules
80
111
 
81
- ### Assertions
112
+ ### Requirements
82
113
 
83
- ### Timeouts
114
+ - `cy.runProvisioningScript()` must be chained off of `cy`.
84
115
 
85
116
  ## Command Log
86
117
 
87
- When clicking on `provScript` within the command log, the console outputs the following:
118
+ When clicking on `runProvisioningScript` within the command log, the console outputs the following:
88
119
 
89
- - `Script`: the name and content of the script sent
90
- - `Files`: the name and content of every additional files sent
91
- - `Response`: the response from the REST call
92
- - `Yielded`: the JSON result yielded
120
+ - **Script**: The name and content of the script sent.
121
+ - **Files**: The name and content of every additional file sent.
122
+ - **Response**: The response from the REST call.
123
+ - **Yielded**: The JSON result yielded.
@@ -8,12 +8,20 @@ declare global {
8
8
  namespace Cypress {
9
9
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
10
10
  interface Chainable<Subject> {
11
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
- runProvisioningScript(script: FormFile | StringDictionary[], files?: FormFile[], jahiaServer?: JahiaServer): Chainable<any>
11
+ runProvisioningScript(params: RunProvisioningScriptParams): Chainable<void>;
13
12
  }
14
13
  }
15
14
  }
16
15
 
16
+ export interface RunProvisioningScriptParams {
17
+ script: FormFile | StringDictionary[];
18
+ files?: FormFile[];
19
+ /** Optional, defaults to serverDefaults */
20
+ jahiaServer?: JahiaServer;
21
+ options?: Cypress.Loggable; // Optional, defaults to { log: true }
22
+ requestOptions?: Partial<RequestOptions>; // Optional, defaults to {}
23
+ }
24
+
17
25
  export type StringDictionary = { [key: string]: string }
18
26
 
19
27
  export type FormFile = {
@@ -68,8 +76,13 @@ function isFormFile(script: FormFile | StringDictionary[]): script is FormFile {
68
76
  return Boolean((script as FormFile).fileContent || (script as FormFile).fileName);
69
77
  }
70
78
 
71
- // eslint-disable-next-line default-param-last, max-params
72
- export const runProvisioningScript = (script: FormFile | StringDictionary[], files?: FormFile[], jahiaServer: JahiaServer = serverDefaults, options: Cypress.Loggable = {log: true}, timeout?: number): void => {
79
+ export const runProvisioningScript = ({
80
+ script,
81
+ files,
82
+ jahiaServer = serverDefaults,
83
+ options = {log: true},
84
+ requestOptions = {}
85
+ }: RunProvisioningScriptParams): void => {
73
86
  const formData = new FormData();
74
87
 
75
88
  if (isFormFile(script)) {
@@ -119,13 +132,10 @@ export const runProvisioningScript = (script: FormFile | StringDictionary[], fil
119
132
  sendImmediately: true
120
133
  },
121
134
  body: formData,
122
- log: false
135
+ log: false,
136
+ ...requestOptions
123
137
  };
124
138
 
125
- if (typeof timeout !== 'undefined') {
126
- request.timeout = timeout;
127
- }
128
-
129
139
  cy.request(request).then(res => {
130
140
  response = res;
131
141
  expect(res.status, 'Script result').to.eq(200);
@@ -14,7 +14,9 @@ declare global {
14
14
 
15
15
  export const uninstallBundle = function (bundleSymbolicName: string): void {
16
16
  cy.runProvisioningScript({
17
- fileContent: '- uninstallBundle: "' + bundleSymbolicName + '"\n',
18
- type: 'application/yaml'
17
+ script: {
18
+ fileContent: '- uninstallBundle: "' + bundleSymbolicName + '"\n',
19
+ type: 'application/yaml'
20
+ }
19
21
  });
20
22
  };
@@ -19,9 +19,12 @@ export const deleteSite = (siteKey: string, jahiaServer?: JahiaServer): void =>
19
19
 
20
20
  export const enableModule = (moduleName: string, siteKey: string, jahiaServer?: JahiaServer): void => {
21
21
  cy.runProvisioningScript({
22
- fileContent: '- enable: "' + moduleName + '"\n site: "' + siteKey + '"',
23
- type: 'application/yaml'
24
- }, undefined, jahiaServer);
22
+ script: {
23
+ fileContent: '- enable: "' + moduleName + '"\n site: "' + siteKey + '"',
24
+ type: 'application/yaml'
25
+ },
26
+ jahiaServer
27
+ });
25
28
  };
26
29
 
27
30
  export const disableModule = (moduleName: string, siteKey: string): void => {