@jahia/cypress 8.1.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @jahia/cypress Changelog
2
2
 
3
+ ## 8.1.1
4
+
5
+ * Use default Jahia ref. while fetching version; fail safe when version can't be fetched.
6
+
3
7
  ## 8.1.0
4
8
 
5
9
  ### New Features
@@ -56,8 +56,13 @@ var skipReason = function (scope, title, required, current) {
56
56
  */
57
57
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
58
58
  var initializeVersionSupport = function () {
59
+ var cachedVersion = Cypress.env(exports.JAHIA_VERSION_ENV_VAR);
60
+ if (typeof cachedVersion === 'string' && cachedVersion.trim() !== '') {
61
+ return cy.wrap(cachedVersion, { log: false });
62
+ }
59
63
  return (0, JahiaPlatformHelper_1.getJahiaVersion)().then(function (jahiaVersion) {
60
- var version = jahiaVersion.release.replace('-SNAPSHOT', '');
64
+ var _a;
65
+ var version = ((_a = jahiaVersion === null || jahiaVersion === void 0 ? void 0 : jahiaVersion.release) === null || _a === void 0 ? void 0 : _a.replace('-SNAPSHOT', '')) || '0.0.0.1';
61
66
  Cypress.env(exports.JAHIA_VERSION_ENV_VAR, version);
62
67
  return version;
63
68
  });
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Fetches the Jahia version using a GraphQL query.
3
+ * @returns Cypress.Chainable that resolves to the Jahia version record (e.g., release: "8.0.0", ...).
4
+ * @note In rare cases tests might override baseUrl (e.g. when Jahia is configured with custom context path,
5
+ * but spec want to use just a host, without the context path), e.g.:
6
+ * it('Crawl pages', {baseUrl: serverURL.origin}, () => { ... })
7
+ * In such case(s) this call will fail because the GraphQL endpoint will not be found at the root of the host.
8
+ * To prevent such failure, we ensure GraphQL client uses full Jahia url as configured in env variable.
9
+ */
1
10
  export declare const getJahiaVersion: () => Cypress.Chainable;
2
11
  export declare const getStartedModulesVersion: () => Cypress.Chainable;
3
12
  export declare const getStartedModuleVersion: (moduleId: string) => Cypress.Chainable;
@@ -1,13 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getStartedModuleVersion = exports.getStartedModulesVersion = exports.getJahiaVersion = void 0;
4
+ /**
5
+ * Fetches the Jahia version using a GraphQL query.
6
+ * @returns Cypress.Chainable that resolves to the Jahia version record (e.g., release: "8.0.0", ...).
7
+ * @note In rare cases tests might override baseUrl (e.g. when Jahia is configured with custom context path,
8
+ * but spec want to use just a host, without the context path), e.g.:
9
+ * it('Crawl pages', {baseUrl: serverURL.origin}, () => { ... })
10
+ * In such case(s) this call will fail because the GraphQL endpoint will not be found at the root of the host.
11
+ * To prevent such failure, we ensure GraphQL client uses full Jahia url as configured in env variable.
12
+ */
4
13
  var getJahiaVersion = function () {
5
- return cy.apollo({
6
- fetchPolicy: 'no-cache',
7
- queryFile: 'graphql/jcr/query/getJahiaVersion.graphql'
8
- }).then(function (result) {
9
- var _a;
10
- return (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.admin.jahia.version;
14
+ return cy.apolloClient({ url: Cypress.env('JAHIA_URL') || Cypress.config().baseUrl }).then(function () {
15
+ return cy.apollo({
16
+ fetchPolicy: 'no-cache',
17
+ queryFile: 'graphql/jcr/query/getJahiaVersion.graphql'
18
+ }).then(function (result) {
19
+ var _a;
20
+ return (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.admin.jahia.version;
21
+ });
11
22
  });
12
23
  };
13
24
  exports.getJahiaVersion = getJahiaVersion;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jahia/cypress",
3
- "version": "8.1.0",
3
+ "version": "8.1.1",
4
4
  "scripts": {
5
5
  "build": "tsc",
6
6
  "lint": "eslint src -c .eslintrc.json --ext .ts --max-warnings=0"
@@ -90,12 +90,19 @@ const skipReason = (scope: string, title: string, required: string, current?: st
90
90
  * and caches the result in `Cypress.env(JAHIA_VERSION_ENV_VAR)`.
91
91
  */
92
92
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
93
- export const initializeVersionSupport = (): Cypress.Chainable<any> =>
94
- getJahiaVersion().then(jahiaVersion => {
95
- const version = jahiaVersion.release.replace('-SNAPSHOT', '');
93
+ export const initializeVersionSupport = (): Cypress.Chainable<any> => {
94
+ const cachedVersion = Cypress.env(JAHIA_VERSION_ENV_VAR);
95
+
96
+ if (typeof cachedVersion === 'string' && cachedVersion.trim() !== '') {
97
+ return cy.wrap(cachedVersion, {log: false});
98
+ }
99
+
100
+ return getJahiaVersion().then(jahiaVersion => {
101
+ const version = jahiaVersion?.release?.replace('-SNAPSHOT', '') || '0.0.0.1';
96
102
  Cypress.env(JAHIA_VERSION_ENV_VAR, version);
97
103
  return version;
98
104
  });
105
+ };
99
106
 
100
107
  /**
101
108
  * Attaches `.since()` to `it`, `it.only`, `it.skip`, `describe`, `describe.only`,
@@ -1,9 +1,20 @@
1
+ /**
2
+ * Fetches the Jahia version using a GraphQL query.
3
+ * @returns Cypress.Chainable that resolves to the Jahia version record (e.g., release: "8.0.0", ...).
4
+ * @note In rare cases tests might override baseUrl (e.g. when Jahia is configured with custom context path,
5
+ * but spec want to use just a host, without the context path), e.g.:
6
+ * it('Crawl pages', {baseUrl: serverURL.origin}, () => { ... })
7
+ * In such case(s) this call will fail because the GraphQL endpoint will not be found at the root of the host.
8
+ * To prevent such failure, we ensure GraphQL client uses full Jahia url as configured in env variable.
9
+ */
1
10
  export const getJahiaVersion = (): Cypress.Chainable => {
2
- return cy.apollo({
3
- fetchPolicy: 'no-cache',
4
- queryFile: 'graphql/jcr/query/getJahiaVersion.graphql'
5
- }).then(result => {
6
- return result?.data?.admin.jahia.version;
11
+ return cy.apolloClient({url: Cypress.env('JAHIA_URL') || Cypress.config().baseUrl}).then(() => {
12
+ return cy.apollo({
13
+ fetchPolicy: 'no-cache',
14
+ queryFile: 'graphql/jcr/query/getJahiaVersion.graphql'
15
+ }).then(result => {
16
+ return result?.data?.admin.jahia.version;
17
+ });
7
18
  });
8
19
  };
9
20
 
@@ -1,11 +1,19 @@
1
1
  import '../../../src/support/apollo/apollo';
2
+ import '../../../src/support/apollo/apolloClient';
2
3
  import {modSince, initializeVersionSupport, JAHIA_VERSION_ENV_VAR} from '../../../src/support/modSince';
3
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
+
4
8
  // Enable version gating
5
9
  modSince.enable();
6
10
 
7
11
  // Stub apollo command
8
- Cypress.Commands.add('apollo', {prevSubject: 'optional'}, () => {
12
+ Cypress.Commands.add('apolloClient', (() => {
13
+ return cy.wrap({} as unknown);
14
+ }) as Cypress.CommandFn<'apolloClient'>);
15
+
16
+ Cypress.Commands.add('apollo', (() => {
9
17
  return cy.wrap({
10
18
  data: {
11
19
  admin: {
@@ -17,7 +25,7 @@ Cypress.Commands.add('apollo', {prevSubject: 'optional'}, () => {
17
25
  }
18
26
  }
19
27
  });
20
- });
28
+ }) as Cypress.CommandFn<'apollo'>);
21
29
 
22
30
  describe('itSince support', () => {
23
31
  describe('registration', () => {
@@ -38,7 +46,7 @@ describe('itSince support', () => {
38
46
 
39
47
  it('throws clear error when it.since args are swapped', () => {
40
48
  expect(() => {
41
- (it.since as unknown as (requiredVersion: string, title: string, fn?: Mocha.Func) => Mocha.Test)(
49
+ (it.since as unknown as ItSinceCall)(
42
50
  'my test title',
43
51
  '8.2.0',
44
52
  () => {
@@ -100,7 +108,7 @@ describe('itSince support', () => {
100
108
  let compatItRan = false;
101
109
  let compatDescribeRan = false;
102
110
 
103
- const compatIt = (it.skip as unknown as (requiredVersion: string, title: string, fn?: Mocha.Func) => Mocha.Test)(
111
+ const compatIt = (it.skip as unknown as ItSinceCall)(
104
112
  '8.3.5.0',
105
113
  compatItTitle,
106
114
  () => {
@@ -108,7 +116,7 @@ describe('itSince support', () => {
108
116
  }
109
117
  );
110
118
 
111
- const compatDescribe = (describe.skip as unknown as (requiredVersion: string, title: string, fn: (this: Mocha.Suite) => void) => Mocha.Suite)(
119
+ const compatDescribe = (describe.skip as unknown as DescribeSinceCall)(
112
120
  '8.3.5.0',
113
121
  compatDescribeTitle,
114
122
  () => {
@@ -136,6 +144,26 @@ describe('itSince support', () => {
136
144
  });
137
145
 
138
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
+
139
167
  it('stores normalized Jahia version in Cypress.env', () => {
140
168
  return initializeVersionSupport().then(version => {
141
169
  expect(version).to.equal('8.2.0');