@jahia/cypress 4.4.0 → 5.1.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;
@@ -3,10 +3,18 @@ import RequestOptions = Cypress.RequestOptions;
3
3
  declare global {
4
4
  namespace Cypress {
5
5
  interface Chainable<Subject> {
6
- runProvisioningScript(script: FormFile | StringDictionary[], files?: FormFile[], jahiaServer?: JahiaServer): Chainable<any>;
6
+ runProvisioningScript(params: RunProvisioningScriptParams): Chainable<void>;
7
7
  }
8
8
  }
9
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
+ }
10
18
  export declare type StringDictionary = {
11
19
  [key: string]: string;
12
20
  };
@@ -22,4 +30,4 @@ export declare type JahiaServer = {
22
30
  username: string;
23
31
  password: string;
24
32
  };
25
- export declare const runProvisioningScript: (script: FormFile | StringDictionary[], files?: FormFile[], jahiaServer?: JahiaServer, options?: Cypress.Loggable, timeout?: number, requestOptions?: Partial<RequestOptions>) => void;
33
+ export declare const runProvisioningScript: ({ script, files, jahiaServer, options, requestOptions }: RunProvisioningScriptParams) => void;
@@ -46,11 +46,8 @@ var serverDefaults = {
46
46
  function isFormFile(script) {
47
47
  return Boolean(script.fileContent || script.fileName);
48
48
  }
49
- // eslint-disable-next-line default-param-last, max-params
50
- var runProvisioningScript = function (script, files, jahiaServer, options, timeout, requestOptions) {
51
- if (jahiaServer === void 0) { jahiaServer = serverDefaults; }
52
- if (options === void 0) { options = { log: true }; }
53
- if (requestOptions === void 0) { requestOptions = {}; }
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;
54
51
  var formData = new FormData();
55
52
  if (isFormFile(script)) {
56
53
  append(script, formData, 'script');
@@ -92,18 +89,20 @@ var runProvisioningScript = function (script, files, jahiaServer, options, timeo
92
89
  pass: jahiaServer.password,
93
90
  sendImmediately: true
94
91
  }, body: formData, log: false }, requestOptions);
95
- if (typeof timeout !== 'undefined') {
96
- request.timeout = timeout;
97
- }
98
92
  cy.request(request).then(function (res) {
99
93
  response = res;
100
- expect(res.status, 'Script result').to.eq(200);
101
- try {
102
- var decoder = new TextDecoder();
103
- result = JSON.parse(decoder.decode(response.body));
94
+ // If the response status is 200, decode the response, otherwise return the response as is
95
+ if (res.status === 200) {
96
+ try {
97
+ var decoder = new TextDecoder();
98
+ result = JSON.parse(decoder.decode(response.body));
99
+ }
100
+ catch (e) {
101
+ result = e;
102
+ }
104
103
  }
105
- catch (e) {
106
- result = e;
104
+ else {
105
+ result = res;
107
106
  }
108
107
  logger === null || logger === void 0 ? void 0 : logger.end();
109
108
  return result;
@@ -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.4.0",
3
+ "version": "5.1.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,101 +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`)
21
34
 
22
- The script can be specified either from an external file (using fileName) or inline (using fileContent)
35
+ The script can be specified either from an external file (using `fileName`) or inline (using `fileContent`).
23
36
 
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`
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`.
27
40
 
28
- #### &gt; jahiaServer (`JahiaServer`)
41
+ #### `jahiaServer` (`JahiaServer`)
29
42
 
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).
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).
31
44
 
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
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.
35
48
 
36
- #### &gt; files (`FormFile[]`)
49
+ #### `files` (`FormFile[]`)
37
50
 
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
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.
39
52
 
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
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.
43
56
 
44
- #### &gt; options (`Loggable`)
57
+ #### `options` (`Cypress.Loggable`)
45
58
 
46
- - `log` : should the command be logged or not
59
+ Options for the Cypress command.
47
60
 
48
- #### &gt; timeout (`number`)
61
+ - **log**: (`boolean`) - Indicates whether the command should be logged or not.
49
62
 
50
- the timeout in milliseconds
63
+ #### `requestOptions` (`RequestOptions`)
51
64
 
52
- #### &gt; requestOptions (`RequestOptions`)
65
+ Additional options for the Cypress request object. Some useful ones include:
53
66
 
54
- Addition options for the cypress request object, some useful ones are:
55
- - `failOnStatusCode` : useful when you expect a 4xx or 5xx error and need to test it
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.
56
69
 
57
70
  ### Yields
58
71
 
59
- The provisioning script result, as JSON object
72
+ The provisioning script result, as a JSON object.
60
73
 
61
74
  ## Examples
62
75
 
63
- ### Execute a script
76
+ ### Execute a Script
64
77
 
65
- Will run the script in `fixtures/provisioning/test.yaml` :
78
+ Will run the script in `fixtures/provisioning/test.yaml`:
66
79
 
67
- ```
68
- cy.runProvisioningScript({fileName:'provisioning/test.yaml', type:'application/yaml'})
80
+ ```javascript
81
+ cy.runProvisioningScript({
82
+ script: { fileName: 'provisioning/test.yaml', type: 'application/yaml' }
83
+ });
69
84
  ```
70
85
 
71
- ### Inline script with additional file
86
+ ### Inline Script with Additional File
72
87
 
73
- Will install the bundle in `fixtures/bundle.jar` :
88
+ Will install the bundle in `fixtures/bundle.jar`:
74
89
 
75
- ```
76
- cy.runProvisioningScript(
77
- {fileContent: '- installBundle: "bundle.jar"',type: 'application/yaml'},
78
- [
79
- { 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' }
80
95
  ]
81
- )
96
+ });
82
97
  ```
83
98
 
84
- ## Rules
99
+ ### Use a Custom Jahia Server
85
100
 
86
- ### Requirements
101
+ Will run the script on a specific Jahia server:
102
+
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
+ ```
87
109
 
88
- - `cy.useProvisioningScript()` requires being chained off of `cy`.
110
+ ## Rules
89
111
 
90
- ### Assertions
112
+ ### Requirements
91
113
 
92
- ### Timeouts
114
+ - `cy.runProvisioningScript()` must be chained off of `cy`.
93
115
 
94
116
  ## Command Log
95
117
 
96
- 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:
97
119
 
98
- - `Script`: the name and content of the script sent
99
- - `Files`: the name and content of every additional files sent
100
- - `Response`: the response from the REST call
101
- - `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, requestOptions: Partial<RequestOptions> = {}): 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)) {
@@ -123,18 +136,19 @@ export const runProvisioningScript = (script: FormFile | StringDictionary[], fil
123
136
  ...requestOptions
124
137
  };
125
138
 
126
- if (typeof timeout !== 'undefined') {
127
- request.timeout = timeout;
128
- }
129
-
130
139
  cy.request(request).then(res => {
131
140
  response = res;
132
- expect(res.status, 'Script result').to.eq(200);
133
- try {
134
- const decoder = new TextDecoder();
135
- result = JSON.parse(decoder.decode(response.body));
136
- } catch (e) {
137
- result = e;
141
+
142
+ // If the response status is 200, decode the response, otherwise return the response as is
143
+ if (res.status === 200) {
144
+ try {
145
+ const decoder = new TextDecoder();
146
+ result = JSON.parse(decoder.decode(response.body));
147
+ } catch (e) {
148
+ result = e;
149
+ }
150
+ } else {
151
+ result = res;
138
152
  }
139
153
 
140
154
  logger?.end();
@@ -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 => {