@jahia/cypress 3.20.0 → 3.21.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.
@@ -1,19 +1,21 @@
1
1
  /// <reference types="cypress" />
2
2
  import { ApolloClient, NormalizedCacheObject } from '@apollo/client/core';
3
- interface AuthMethod {
3
+ interface HostConfig {
4
4
  token?: string;
5
5
  username?: string;
6
6
  password?: string;
7
+ url?: string;
7
8
  }
8
9
  declare global {
9
10
  namespace Cypress {
10
11
  interface Chainable<Subject> {
11
- apolloClient(authMethod?: AuthMethod): Chainable<ApolloClient<NormalizedCacheObject>>;
12
+ apolloClient(config?: HostConfig): Chainable<ApolloClient<NormalizedCacheObject>>;
12
13
  }
13
14
  }
14
15
  }
15
16
  export declare type ApolloClientOptions = Cypress.Loggable & {
16
17
  setCurrentApolloClient: boolean;
17
18
  };
18
- export declare const apolloClient: (authMethod?: AuthMethod, options?: ApolloClientOptions) => void;
19
+ export declare const switchApolloClient: (config?: HostConfig, options?: ApolloClientOptions) => void;
20
+ export declare const apolloClient: (config?: HostConfig, options?: ApolloClientOptions) => void;
19
21
  export {};
@@ -1,24 +1,36 @@
1
1
  "use strict";
2
2
  exports.__esModule = true;
3
- exports.apolloClient = void 0;
3
+ exports.apolloClient = exports.switchApolloClient = void 0;
4
4
  var core_1 = require("@apollo/client/core");
5
5
  var links_1 = require("./links");
6
- var apolloClient = function (authMethod, options) {
6
+ var switchApolloClient = function (config, options) {
7
+ if (config === void 0) { config = { url: Cypress.config().baseUrl }; }
8
+ if (options === void 0) { options = {
9
+ log: true,
10
+ setCurrentApolloClient: true
11
+ }; }
12
+ // Switch context to apollo client
13
+ cy.visit(config.url, { failOnStatusCode: false });
14
+ return exports.apolloClient(config, options);
15
+ };
16
+ exports.switchApolloClient = switchApolloClient;
17
+ var apolloClient = function (config, options) {
18
+ if (config === void 0) { config = { url: Cypress.config().baseUrl }; }
7
19
  if (options === void 0) { options = {
8
20
  log: true,
9
21
  setCurrentApolloClient: true
10
22
  }; }
11
23
  var headers = {};
12
- if (authMethod === undefined) {
13
- headers.authorization = "Basic " + btoa('root:' + Cypress.env('SUPER_USER_PASSWORD'));
24
+ if (config.token !== undefined) {
25
+ headers.authorization = "APIToken " + config.token;
14
26
  }
15
- else if (authMethod.token !== undefined) {
16
- headers.authorization = "APIToken " + authMethod.token;
27
+ else if (config.username !== undefined && config.password !== undefined) {
28
+ headers.authorization = "Basic " + btoa(config.username + ':' + config.password);
17
29
  }
18
- else if (authMethod.username !== undefined && authMethod.password !== undefined) {
19
- headers.authorization = "Basic " + btoa(authMethod.username + ':' + authMethod.password);
30
+ else {
31
+ headers.authorization = "Basic " + btoa('root:' + Cypress.env('SUPER_USER_PASSWORD'));
20
32
  }
21
- var links = [links_1.uploadLink, links_1.formDataHttpLink(Cypress.config().baseUrl, headers)];
33
+ var links = [links_1.uploadLink, links_1.formDataHttpLink(config.url, headers)];
22
34
  var client = new core_1.ApolloClient({
23
35
  link: core_1.from(links),
24
36
  cache: new core_1.InMemoryCache(),
@@ -35,7 +47,7 @@ var apolloClient = function (authMethod, options) {
35
47
  message: 'Create new apollo client',
36
48
  consoleProps: function () {
37
49
  return {
38
- Auth: authMethod,
50
+ Config: config,
39
51
  Yielded: client
40
52
  };
41
53
  }
@@ -7,5 +7,5 @@ declare global {
7
7
  }
8
8
  }
9
9
  }
10
- export declare const login: (username?: string, password?: string) => void;
10
+ export declare const login: (username?: string, password?: string, url?: string) => void;
11
11
  export declare const loginAndStoreSession: (username?: string, password?: string) => void;
@@ -3,9 +3,10 @@
3
3
  exports.__esModule = true;
4
4
  exports.loginAndStoreSession = exports.login = void 0;
5
5
  /// <reference types="cypress" />
6
- var login = function (username, password) {
6
+ var login = function (username, password, url) {
7
7
  if (username === void 0) { username = 'root'; }
8
8
  if (password === void 0) { password = Cypress.env('SUPER_USER_PASSWORD'); }
9
+ if (url === void 0) { url = '/cms/login'; }
9
10
  Cypress.log({
10
11
  name: 'login',
11
12
  message: "Login with " + username,
@@ -17,11 +18,11 @@ var login = function (username, password) {
17
18
  });
18
19
  cy.request({
19
20
  method: 'POST',
20
- url: '/cms/login',
21
21
  form: true,
22
22
  body: { username: username, password: password },
23
23
  followRedirect: false,
24
- log: false
24
+ log: false,
25
+ url: url
25
26
  }).then(function (res) {
26
27
  expect(res.status, 'Login result').to.eq(302);
27
28
  });
@@ -1 +1 @@
1
- export declare const waitUntilSAMStatusGreen: (severity?: string, timeout?: number, interval?: number) => void;
1
+ export declare const waitUntilSAMStatusGreen: (severity?: string, timeout?: number, interval?: number, greenMatchCount?: number) => void;
@@ -1,10 +1,22 @@
1
1
  "use strict";
2
2
  exports.__esModule = true;
3
3
  exports.waitUntilSAMStatusGreen = void 0;
4
- var waitUntilSAMStatusGreen = function (severity, timeout, interval) {
4
+ /*
5
+ When Jahia is starting or performing provisioning operations
6
+ it is expected for the SAM probe to alternate beween GREEN, YELLOW and RED statuses.
7
+
8
+ The primary use of this method is to wait until a Jahia platform stabilizes after a startup or
9
+ provisioning operation.
10
+
11
+ Instead of waiting only for one occurence of a GREEN status, this function will wait until the a
12
+ GREEN status was returned a number of consecutive times (greenMatchCount).
13
+ */
14
+ var waitUntilSAMStatusGreen = function (severity, timeout, interval, greenMatchCount) {
5
15
  if (severity === void 0) { severity = 'MEDIUM'; }
6
16
  if (timeout === void 0) { timeout = 60000; }
7
- if (interval === void 0) { interval = 1000; }
17
+ if (interval === void 0) { interval = 500; }
18
+ if (greenMatchCount === void 0) { greenMatchCount = 10; }
19
+ var greenCount = 0;
8
20
  cy.waitUntil(function () {
9
21
  return cy.apollo({
10
22
  fetchPolicy: 'no-cache',
@@ -16,7 +28,8 @@ var waitUntilSAMStatusGreen = function (severity, timeout, interval) {
16
28
  var _a, _b, _c, _d;
17
29
  var healthStatus = (_d = (_c = (_b = (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.admin) === null || _b === void 0 ? void 0 : _b.jahia) === null || _c === void 0 ? void 0 : _c.healthCheck) === null || _d === void 0 ? void 0 : _d.status;
18
30
  if (healthStatus) {
19
- return healthStatus.health === 'GREEN';
31
+ greenCount = healthStatus.health === 'GREEN' ? greenCount + 1 : 0;
32
+ return greenCount >= greenMatchCount;
20
33
  }
21
34
  });
22
35
  }, {
@@ -1,12 +1,13 @@
1
+ import { JahiaServer } from '../support';
1
2
  export declare const createSite: (siteKey: string, config?: {
2
3
  languages?: string;
3
4
  templateSet: string;
4
5
  serverName: string;
5
6
  locale: string;
6
- }) => void;
7
- export declare const deleteSite: (siteKey: string) => void;
8
- export declare const enableModule: (moduleName: string, siteKey: string) => void;
7
+ }, jahiaServer?: JahiaServer) => void;
8
+ export declare const deleteSite: (siteKey: string, jahiaServer?: JahiaServer) => void;
9
+ export declare const enableModule: (moduleName: string, siteKey: string, jahiaServer?: JahiaServer) => void;
9
10
  export declare const disableModule: (moduleName: string, siteKey: string) => void;
10
11
  export declare const editSite: (siteKey: string, config?: {
11
12
  serverName: string;
12
- }) => void;
13
+ }, jahiaServer?: JahiaServer) => void;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  exports.__esModule = true;
3
3
  exports.editSite = exports.disableModule = exports.enableModule = exports.deleteSite = exports.createSite = void 0;
4
- var createSite = function (siteKey, config) {
4
+ // eslint-disable-next-line default-param-last
5
+ var createSite = function (siteKey, config, jahiaServer) {
5
6
  if (config === void 0) { config = { templateSet: 'dx-base-demo-templates', serverName: 'localhost', locale: 'en' }; }
6
7
  cy.executeGroovy('groovy/admin/createSite.groovy', {
7
8
  SITEKEY: siteKey,
@@ -9,20 +10,20 @@ var createSite = function (siteKey, config) {
9
10
  SERVERNAME: config.serverName,
10
11
  LOCALE: config.locale,
11
12
  LANGUAGES: config.languages || config.locale
12
- });
13
+ }, jahiaServer);
13
14
  };
14
15
  exports.createSite = createSite;
15
- var deleteSite = function (siteKey) {
16
+ var deleteSite = function (siteKey, jahiaServer) {
16
17
  cy.executeGroovy('groovy/admin/deleteSite.groovy', {
17
18
  SITEKEY: siteKey
18
- });
19
+ }, jahiaServer);
19
20
  };
20
21
  exports.deleteSite = deleteSite;
21
- var enableModule = function (moduleName, siteKey) {
22
+ var enableModule = function (moduleName, siteKey, jahiaServer) {
22
23
  cy.runProvisioningScript({
23
24
  fileContent: '- enable: "' + moduleName + '"\n site: "' + siteKey + '"',
24
25
  type: 'application/yaml'
25
- });
26
+ }, undefined, jahiaServer);
26
27
  };
27
28
  exports.enableModule = enableModule;
28
29
  var disableModule = function (moduleName, siteKey) {
@@ -32,11 +33,12 @@ var disableModule = function (moduleName, siteKey) {
32
33
  });
33
34
  };
34
35
  exports.disableModule = disableModule;
35
- var editSite = function (siteKey, config) {
36
+ // eslint-disable-next-line default-param-last
37
+ var editSite = function (siteKey, config, jahiaServer) {
36
38
  if (config === void 0) { config = { serverName: 'localhost' }; }
37
39
  cy.executeGroovy('groovy/admin/editSite.groovy', {
38
40
  SITEKEY: siteKey,
39
41
  SERVERNAME: config.serverName
40
- });
42
+ }, jahiaServer);
41
43
  };
42
44
  exports.editSite = editSite;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jahia/cypress",
3
- "version": "3.20.0",
3
+ "version": "3.21.0",
4
4
  "scripts": {
5
5
  "build": "tsc",
6
6
  "lint": "eslint src -c .eslintrc.json --ext .ts"
@@ -13,13 +13,14 @@ cy.apolloClient()
13
13
 
14
14
  ### Arguments
15
15
 
16
- #### &gt; auth (`AuthMethod`)
16
+ #### &gt; config (`HostConfig`)
17
17
 
18
- If no authorization is passed, will use root credentials. Otherwise :
18
+ If no authorization is passed, will use root credentials and cypress base url. Otherwise :
19
19
 
20
20
  - token: An API token
21
21
  - username
22
22
  - password
23
+ - url
23
24
 
24
25
  #### &gt; options (`ApolloClientOptions`)
25
26
 
@@ -1,10 +1,11 @@
1
1
  import {ApolloClient, from, InMemoryCache, NormalizedCacheObject} from '@apollo/client/core';
2
2
  import {formDataHttpLink, uploadLink} from './links';
3
3
 
4
- interface AuthMethod {
4
+ interface HostConfig {
5
5
  token?: string
6
6
  username?: string
7
- password?: string
7
+ password?: string,
8
+ url?: string
8
9
  }
9
10
 
10
11
  declare global {
@@ -12,7 +13,7 @@ declare global {
12
13
  namespace Cypress {
13
14
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
14
15
  interface Chainable<Subject> {
15
- apolloClient(authMethod?: AuthMethod): Chainable<ApolloClient<NormalizedCacheObject>>
16
+ apolloClient(config?: HostConfig): Chainable<ApolloClient<NormalizedCacheObject>>
16
17
  }
17
18
  }
18
19
  }
@@ -21,20 +22,29 @@ export type ApolloClientOptions = Cypress.Loggable & {
21
22
  setCurrentApolloClient: boolean
22
23
  }
23
24
 
24
- export const apolloClient = function (authMethod?: AuthMethod, options: ApolloClientOptions = {
25
+ export const switchApolloClient = function (config: HostConfig = {url: Cypress.config().baseUrl}, options: ApolloClientOptions = {
26
+ log: true,
27
+ setCurrentApolloClient: true
28
+ }): void {
29
+ // Switch context to apollo client
30
+ cy.visit(config.url, {failOnStatusCode: false});
31
+ return apolloClient(config, options);
32
+ };
33
+
34
+ export const apolloClient = function (config: HostConfig = {url: Cypress.config().baseUrl}, options: ApolloClientOptions = {
25
35
  log: true,
26
36
  setCurrentApolloClient: true
27
37
  }): void {
28
38
  const headers: { authorization?: string } = {};
29
- if (authMethod === undefined) {
39
+ if (config.token !== undefined) {
40
+ headers.authorization = `APIToken ${config.token}`;
41
+ } else if (config.username !== undefined && config.password !== undefined) {
42
+ headers.authorization = `Basic ${btoa(config.username + ':' + config.password)}`;
43
+ } else {
30
44
  headers.authorization = `Basic ${btoa('root:' + Cypress.env('SUPER_USER_PASSWORD'))}`;
31
- } else if (authMethod.token !== undefined) {
32
- headers.authorization = `APIToken ${authMethod.token}`;
33
- } else if (authMethod.username !== undefined && authMethod.password !== undefined) {
34
- headers.authorization = `Basic ${btoa(authMethod.username + ':' + authMethod.password)}`;
35
45
  }
36
46
 
37
- const links = [uploadLink, formDataHttpLink(Cypress.config().baseUrl, headers)];
47
+ const links = [uploadLink, formDataHttpLink(config.url, headers)];
38
48
 
39
49
  const client = new ApolloClient({
40
50
  link: from(links),
@@ -53,7 +63,7 @@ export const apolloClient = function (authMethod?: AuthMethod, options: ApolloCl
53
63
  message: 'Create new apollo client',
54
64
  consoleProps: () => {
55
65
  return {
56
- Auth: authMethod,
66
+ Config: config,
57
67
  Yielded: client
58
68
  };
59
69
  }
@@ -13,7 +13,7 @@ declare global {
13
13
  }
14
14
  }
15
15
 
16
- export const login = (username = 'root', password: string = Cypress.env('SUPER_USER_PASSWORD')): void => {
16
+ export const login = (username = 'root', password: string = Cypress.env('SUPER_USER_PASSWORD'), url = '/cms/login'): void => {
17
17
  Cypress.log({
18
18
  name: 'login',
19
19
  message: `Login with ${username}`,
@@ -26,11 +26,11 @@ export const login = (username = 'root', password: string = Cypress.env('SUPER_U
26
26
 
27
27
  cy.request({
28
28
  method: 'POST',
29
- url: '/cms/login',
30
29
  form: true,
31
30
  body: {username, password},
32
31
  followRedirect: false,
33
- log: false
32
+ log: false,
33
+ url
34
34
  }).then(res => {
35
35
  expect(res.status, 'Login result').to.eq(302);
36
36
  });
@@ -1,4 +1,15 @@
1
- export const waitUntilSAMStatusGreen = (severity = 'MEDIUM', timeout = 60000, interval = 1000) : void => {
1
+ /*
2
+ When Jahia is starting or performing provisioning operations
3
+ it is expected for the SAM probe to alternate beween GREEN, YELLOW and RED statuses.
4
+
5
+ The primary use of this method is to wait until a Jahia platform stabilizes after a startup or
6
+ provisioning operation.
7
+
8
+ Instead of waiting only for one occurence of a GREEN status, this function will wait until the a
9
+ GREEN status was returned a number of consecutive times (greenMatchCount).
10
+ */
11
+ export const waitUntilSAMStatusGreen = (severity = 'MEDIUM', timeout = 60000, interval = 500, greenMatchCount = 10) : void => {
12
+ let greenCount = 0;
2
13
  cy.waitUntil(() =>
3
14
  cy.apollo({
4
15
  fetchPolicy: 'no-cache',
@@ -9,7 +20,8 @@ export const waitUntilSAMStatusGreen = (severity = 'MEDIUM', timeout = 60000, in
9
20
  }).then(result => {
10
21
  const healthStatus = result?.data?.admin?.jahia?.healthCheck?.status;
11
22
  if (healthStatus) {
12
- return healthStatus.health === 'GREEN';
23
+ greenCount = healthStatus.health === 'GREEN' ? greenCount + 1 : 0;
24
+ return greenCount >= greenMatchCount;
13
25
  }
14
26
  }),
15
27
  {
@@ -1,25 +1,27 @@
1
+ import {JahiaServer} from '../support';
1
2
 
2
- export const createSite = (siteKey: string, config: {languages?: string, templateSet: string, serverName: string, locale: string} = {templateSet: 'dx-base-demo-templates', serverName: 'localhost', locale: 'en'}): void => {
3
+ // eslint-disable-next-line default-param-last
4
+ export const createSite = (siteKey: string, config: {languages?: string, templateSet: string, serverName: string, locale: string} = {templateSet: 'dx-base-demo-templates', serverName: 'localhost', locale: 'en'}, jahiaServer?: JahiaServer): void => {
3
5
  cy.executeGroovy('groovy/admin/createSite.groovy', {
4
6
  SITEKEY: siteKey,
5
7
  TEMPLATES_SET: config.templateSet,
6
8
  SERVERNAME: config.serverName,
7
9
  LOCALE: config.locale,
8
10
  LANGUAGES: config.languages || config.locale
9
- });
11
+ }, jahiaServer);
10
12
  };
11
13
 
12
- export const deleteSite = (siteKey: string): void => {
14
+ export const deleteSite = (siteKey: string, jahiaServer?: JahiaServer): void => {
13
15
  cy.executeGroovy('groovy/admin/deleteSite.groovy', {
14
16
  SITEKEY: siteKey
15
- });
17
+ }, jahiaServer);
16
18
  };
17
19
 
18
- export const enableModule = (moduleName: string, siteKey: string): void => {
20
+ export const enableModule = (moduleName: string, siteKey: string, jahiaServer?: JahiaServer): void => {
19
21
  cy.runProvisioningScript({
20
22
  fileContent: '- enable: "' + moduleName + '"\n site: "' + siteKey + '"',
21
23
  type: 'application/yaml'
22
- });
24
+ }, undefined, jahiaServer);
23
25
  };
24
26
 
25
27
  export const disableModule = (moduleName: string, siteKey: string): void => {
@@ -29,9 +31,10 @@ export const disableModule = (moduleName: string, siteKey: string): void => {
29
31
  });
30
32
  };
31
33
 
32
- export const editSite = (siteKey: string, config: {serverName: string} = {serverName: 'localhost'}): void => {
34
+ // eslint-disable-next-line default-param-last
35
+ export const editSite = (siteKey: string, config: {serverName: string} = {serverName: 'localhost'}, jahiaServer?: JahiaServer): void => {
33
36
  cy.executeGroovy('groovy/admin/editSite.groovy', {
34
37
  SITEKEY: siteKey,
35
38
  SERVERNAME: config.serverName
36
- });
39
+ }, jahiaServer);
37
40
  };