dceky 1.4.1 → 1.4.2

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/README.md CHANGED
@@ -89,6 +89,29 @@ But, developers should run tests using `npm run ky:dev` because each time the te
89
89
 
90
90
  There are three types of globals: `/cypress/globals/GlobalCredentials` (secure values must go here), `/cypress/globals/GlobalResources` (videos, links, resources), and `/cypress/globals/GlobalValues` (everything else).
91
91
 
92
+ ### Controlling the Viewport
93
+
94
+ Each profile can set the viewport that tests run in via two optional variables:
95
+
96
+ | Variable | Description |
97
+ | --- | --- |
98
+ | `viewport` | A generic alias — `desktop` (a 4k monitor, the default), `macbook`, `ipad`, or `iphone` — or any [Cypress viewport preset](https://docs.cypress.io/api/commands/viewport) such as `iphone-x`, `ipad-2`, or `macbook-16`. Defaults to `desktop`. |
99
+ | `orientation` | `landscape` or `portrait`. Defaults to `landscape`, except `iphone` viewports which default to `portrait`. |
100
+
101
+ The generic aliases map to specific devices: `iphone` → `iphone-x`, `ipad` → `ipad-2`, `macbook` → `macbook-16`, and `desktop` → a 4k monitor (3840×2160).
102
+
103
+ Ky applies the viewport automatically before each test.
104
+
105
+ ```ts
106
+ const StageProfile = {
107
+ baseURL: 'stage.example.harvard.edu',
108
+ viewport: 'iphone',
109
+ orientation: 'portrait',
110
+ };
111
+
112
+ export default StageProfile;
113
+ ```
114
+
92
115
  ### Writing Your Own Custom Commands
93
116
 
94
117
  Custom commands are called using Ky (e.g. `ky.myCustomCommand()`), and you define them in the `commands` folder generated when you first setup Ky.
@@ -45,6 +45,14 @@ const genEmptyProfileFile = (name) => {
45
45
  ' // Static Value Examples:',
46
46
  ' // loginSystem: \'HarvardKey\'',
47
47
  '',
48
+ ' // Viewport Example (default: desktop):',
49
+ ' // Generic aliases: desktop, macbook, ipad, iphone',
50
+ ' // ...or any Cypress preset (e.g. iphone-x, ipad-2, macbook-16)',
51
+ ' // viewport: \'desktop\',',
52
+ '',
53
+ ' // Orientation Example (default: landscape, or portrait for iphone):',
54
+ ' // orientation: \'landscape\',',
55
+ '',
48
56
  ' // Dependent Value Example:',
49
57
  ' // loginHost: {',
50
58
  ' // dependsOn: \'loginSystem\',',
@@ -1 +1 @@
1
- {"version":3,"file":"genEmptyProfileFile.js","sourceRoot":"","sources":["../../../setup/checkRequiredFiles/genEmptyProfileFile.ts"],"names":[],"mappings":";;;;;AAAA,4CAAoB;AACpB,gDAAwB;AAExB,wBAAwB;AACxB,yEAAiD;AAEjD;;;;GAIG;AACH,MAAM,mBAAmB,GAAG,CAAC,IAAY,EAAU,EAAE;IACnD,MAAM,IAAI,GAAG,IAAA,qBAAW,GAAE,CAAC;IAE3B,uCAAuC;IACvC,MAAM,gBAAgB,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,SAAS,CAAC,CAAC;IAE5D,iBAAiB;IACjB,sCAAsC;IACtC,OAAO,CAAC,GAAG,CAAC,gCAAgC,IAAI,aAAa,CAAC,CAAC;IAE/D,MAAM,WAAW,GAAG,cAAI,CAAC,IAAI,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC;IACxD,MAAM,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,IAAI,aAAa,CAAC,CAAC;IAEhE,gCAAgC;IAChC,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;QAChC,uBAAuB;QACvB,YAAE,CAAC,SAAS,CAAC,WAAW,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACjD,CAAC;IAED,sDAAsD;IACtD,MAAM,YAAY,GAAG,CACnB,gBAAgB;QACd,CAAC,CAAC;YACA,+CAA+C;YAC/C,6CAA6C;YAC7C,EAAE;SACH;QACD,CAAC,CAAC,EAAE,CACP,CAAC;IAEF,sCAAsC;IACtC,MAAM,YAAY,GAAG;QACnB,KAAK;QACL,MAAM,IAAI,UAAU;QACpB,KAAK;QACL,EAAE;QACF,SAAS,IAAI,aAAa;QAC1B,GAAG,YAAY;QACf,6BAA6B;QAC7B,kCAAkC;QAClC,EAAE;QACF,+BAA+B;QAC/B,mBAAmB;QACnB,oCAAoC;QACpC,2CAA2C;QAC3C,sDAAsD;QACtD,SAAS;QACT,EAAE;QACF,4CAA4C;QAC5C,iBAAiB;QACjB,gCAAgC;QAChC,0CAA0C;QAC1C,mEAAmE;QACnE,SAAS;QACT,IAAI;QACJ,EAAE;QACF,kBAAkB,IAAI,UAAU;QAChC,EAAE;KACH,CAAC;IACF,YAAE,CAAC,aAAa,CAAC,UAAU,EAAE,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC;IAE9D,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAEF,kBAAe,mBAAmB,CAAC"}
1
+ {"version":3,"file":"genEmptyProfileFile.js","sourceRoot":"","sources":["../../../setup/checkRequiredFiles/genEmptyProfileFile.ts"],"names":[],"mappings":";;;;;AAAA,4CAAoB;AACpB,gDAAwB;AAExB,wBAAwB;AACxB,yEAAiD;AAEjD;;;;GAIG;AACH,MAAM,mBAAmB,GAAG,CAAC,IAAY,EAAU,EAAE;IACnD,MAAM,IAAI,GAAG,IAAA,qBAAW,GAAE,CAAC;IAE3B,uCAAuC;IACvC,MAAM,gBAAgB,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,SAAS,CAAC,CAAC;IAE5D,iBAAiB;IACjB,sCAAsC;IACtC,OAAO,CAAC,GAAG,CAAC,gCAAgC,IAAI,aAAa,CAAC,CAAC;IAE/D,MAAM,WAAW,GAAG,cAAI,CAAC,IAAI,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC;IACxD,MAAM,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,IAAI,aAAa,CAAC,CAAC;IAEhE,gCAAgC;IAChC,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;QAChC,uBAAuB;QACvB,YAAE,CAAC,SAAS,CAAC,WAAW,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACjD,CAAC;IAED,sDAAsD;IACtD,MAAM,YAAY,GAAG,CACnB,gBAAgB;QACd,CAAC,CAAC;YACA,+CAA+C;YAC/C,6CAA6C;YAC7C,EAAE;SACH;QACD,CAAC,CAAC,EAAE,CACP,CAAC;IAEF,sCAAsC;IACtC,MAAM,YAAY,GAAG;QACnB,KAAK;QACL,MAAM,IAAI,UAAU;QACpB,KAAK;QACL,EAAE;QACF,SAAS,IAAI,aAAa;QAC1B,GAAG,YAAY;QACf,6BAA6B;QAC7B,kCAAkC;QAClC,EAAE;QACF,2CAA2C;QAC3C,sDAAsD;QACtD,mEAAmE;QACnE,6BAA6B;QAC7B,EAAE;QACF,wEAAwE;QACxE,kCAAkC;QAClC,EAAE;QACF,+BAA+B;QAC/B,mBAAmB;QACnB,oCAAoC;QACpC,2CAA2C;QAC3C,sDAAsD;QACtD,SAAS;QACT,EAAE;QACF,4CAA4C;QAC5C,iBAAiB;QACjB,gCAAgC;QAChC,0CAA0C;QAC1C,mEAAmE;QACnE,SAAS;QACT,IAAI;QACJ,EAAE;QACF,kBAAkB,IAAI,UAAU;QAChC,EAAE;KACH,CAAC;IACF,YAAE,CAAC,aAAa,CAAC,UAAU,EAAE,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC;IAE9D,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAEF,kBAAe,mBAAmB,CAAC"}
@@ -0,0 +1,20 @@
1
+ type ResolvedViewport = ({
2
+ preset: Cypress.ViewportPreset;
3
+ orientation: Cypress.ViewportOrientation;
4
+ } | {
5
+ width: number;
6
+ height: number;
7
+ });
8
+ /**
9
+ * Resolve the "viewport" and "orientation" profile variables into arguments
10
+ * for cy.viewport. Generic aliases (iphone, ipad, macbook, desktop) are mapped
11
+ * to specific devices, and a sensible default orientation is chosen
12
+ * @author Yuen Ler Chow
13
+ * @param rawViewport the "viewport" profile variable (a preset name or generic
14
+ * alias). Defaults to "desktop" if not provided
15
+ * @param rawOrientation the "orientation" profile variable ("landscape" or
16
+ * "portrait"). Defaults to "landscape", or "portrait" for iphone viewports
17
+ * @returns resolved arguments for cy.viewport
18
+ */
19
+ declare const resolveViewport: (rawViewport?: string, rawOrientation?: string) => ResolvedViewport;
20
+ export default resolveViewport;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ /// <reference types="cypress" />
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ /*----------------------------------------*/
5
+ /* -------------- Constants ------------- */
6
+ /*----------------------------------------*/
7
+ // Generic viewport aliases that map to a specific Cypress device preset
8
+ const GENERIC_VIEWPORT_ALIASES = {
9
+ iphone: 'iphone-x',
10
+ ipad: 'ipad-2',
11
+ macbook: 'macbook-16',
12
+ };
13
+ // Special "desktop" preset: dimensions of a 4k monitor
14
+ const DESKTOP_VIEWPORT = { width: 3840, height: 2160 };
15
+ // Preset to use when no viewport is specified in the profile
16
+ const DEFAULT_VIEWPORT = 'desktop';
17
+ /*----------------------------------------*/
18
+ /* --------------- Helper --------------- */
19
+ /*----------------------------------------*/
20
+ /**
21
+ * Resolve the "viewport" and "orientation" profile variables into arguments
22
+ * for cy.viewport. Generic aliases (iphone, ipad, macbook, desktop) are mapped
23
+ * to specific devices, and a sensible default orientation is chosen
24
+ * @author Yuen Ler Chow
25
+ * @param rawViewport the "viewport" profile variable (a preset name or generic
26
+ * alias). Defaults to "desktop" if not provided
27
+ * @param rawOrientation the "orientation" profile variable ("landscape" or
28
+ * "portrait"). Defaults to "landscape", or "portrait" for iphone viewports
29
+ * @returns resolved arguments for cy.viewport
30
+ */
31
+ const resolveViewport = (rawViewport, rawOrientation) => {
32
+ var _a;
33
+ // Normalize the requested viewport (default to desktop)
34
+ const requested = (rawViewport !== null && rawViewport !== void 0 ? rawViewport : DEFAULT_VIEWPORT).trim().toLowerCase();
35
+ // Resolve generic aliases (e.g. "iphone" => "iphone-x")
36
+ const viewport = ((_a = GENERIC_VIEWPORT_ALIASES[requested]) !== null && _a !== void 0 ? _a : requested);
37
+ // Determine orientation (default landscape, but portrait for iphones)
38
+ const isIphone = viewport.startsWith('iphone');
39
+ const defaultOrientation = (isIphone ? 'portrait' : 'landscape');
40
+ const orientation = (rawOrientation
41
+ ? rawOrientation.trim().toLowerCase()
42
+ : defaultOrientation);
43
+ // Validate orientation
44
+ if (orientation !== 'landscape' && orientation !== 'portrait') {
45
+ throw new Error(`dceky: Invalid "orientation" profile variable "${rawOrientation}". Expected "landscape" or "portrait".`);
46
+ }
47
+ // Handle the special "desktop" preset (a 4k monitor)
48
+ if (viewport === 'desktop') {
49
+ const { width, height } = DESKTOP_VIEWPORT;
50
+ // Swap dimensions for portrait
51
+ return (orientation === 'portrait'
52
+ ? { width: height, height: width }
53
+ : { width, height });
54
+ }
55
+ return {
56
+ preset: viewport,
57
+ orientation: orientation,
58
+ };
59
+ };
60
+ exports.default = resolveViewport;
61
+ //# sourceMappingURL=resolveViewport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveViewport.js","sourceRoot":"","sources":["../../../../src/commands/helpers/resolveViewport.ts"],"names":[],"mappings":";AAAA,iCAAiC;;AAEjC,4CAA4C;AAC5C,4CAA4C;AAC5C,4CAA4C;AAE5C,wEAAwE;AACxE,MAAM,wBAAwB,GAAgD;IAC5E,MAAM,EAAE,UAAU;IAClB,IAAI,EAAE,QAAQ;IACd,OAAO,EAAE,YAAY;CACtB,CAAC;AAEF,uDAAuD;AACvD,MAAM,gBAAgB,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AAEvD,6DAA6D;AAC7D,MAAM,gBAAgB,GAAG,SAAS,CAAC;AAmBnC,4CAA4C;AAC5C,4CAA4C;AAC5C,4CAA4C;AAE5C;;;;;;;;;;GAUG;AACH,MAAM,eAAe,GAAG,CACtB,WAAoB,EACpB,cAAuB,EACL,EAAE;;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importDefault(require("./getCredentialValue"));
39
39
  const getCredentialValues_1 = __importDefault(require("./getCredentialValues"));
40
40
  const sendRequest_1 = __importDefault(require("./sendRequest"));
41
+ const setupViewport_1 = __importDefault(require("./setupViewport"));
41
42
  /**
42
43
  * Initialize custom commands
43
44
  * @author Gabe Abrams
@@ -78,6 +79,7 @@ const commands = () => {
78
79
  (0, getCredentialValue_1.default)();
79
80
  (0, getCredentialValues_1.default)();
80
81
  (0, sendRequest_1.default)();
82
+ (0, setupViewport_1.default)();
81
83
  };
82
84
  exports.default = commands;
83
85
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/index.ts"],"names":[],"mappings":";;;;;AAAA,sBAAsB;AACtB,sFAA8D;AAC9D,sEAA8C;AAC9C,4EAAoD;AACpD,kFAA0D;AAC1D,kFAA0D;AAC1D,sGAA8E;AAC9E,wEAAgD;AAChD,kEAA0C;AAC1C,kEAA0C;AAC1C,8EAAsD;AACtD,oDAA4B;AAC5B,wDAAgC;AAChC,sEAA8C;AAC9C,wEAAgD;AAChD,0DAAkC;AAClC,0EAAkD;AAClD,0DAAkC;AAClC,0EAAkD;AAClD,0EAAkD;AAClD,kEAA0C;AAC1C,sEAA8C;AAC9C,kEAA0C;AAC1C,4DAAoC;AACpC,gDAAwB;AACxB,gEAAwC;AACxC,0DAAkC;AAClC,0DAAkC;AAClC,gFAAwD;AACxD,wGAAgF;AAChF,oFAA4D;AAC5D,wEAAgD;AAChD,8EAAsD;AACtD,gFAAwD;AACxD,gEAAwC;AAExC;;;GAGG;AACH,MAAM,QAAQ,GAAG,GAAG,EAAE;IACpB,6BAA6B;IAC7B,IAAA,gCAAsB,GAAE,CAAC;IACzB,IAAA,wBAAc,GAAE,CAAC;IACjB,IAAA,2BAAiB,GAAE,CAAC;IACpB,IAAA,8BAAoB,GAAE,CAAC;IACvB,IAAA,8BAAoB,GAAE,CAAC;IACvB,IAAA,wCAA8B,GAAE,CA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GAAE,CAAC;IACtB,IAAA,yCAA+B,GAAE,CAAC;IAClC,IAAA,+BAAqB,GAAE,CAAC;IACxB,IAAA,yBAAe,GAAE,CAAC;IAClB,IAAA,4BAAkB,GAAE,CAAC;IACrB,IAAA,6BAAmB,GAAE,CAAC;IACtB,IAAA,qBAAW,GAAE,CAAC;IACd,IAAA,uBAAa,GAAE,CAAC;AAClB,CAAC,CAAC;AAEF,kBAAe,QAAQ,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Register a global beforeEach hook that sets the Cypress viewport based on the
3
+ * "viewport" and "orientation" profile variables
4
+ * @author Yuen Ler Chow
5
+ */
6
+ declare const setupViewport: () => void;
7
+ export default setupViewport;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ /// <reference types="cypress" />
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ // Import helpers
8
+ const resolveViewport_1 = __importDefault(require("./helpers/resolveViewport"));
9
+ /*----------------------------------------*/
10
+ /* --------------- Command -------------- */
11
+ /*----------------------------------------*/
12
+ /**
13
+ * Register a global beforeEach hook that sets the Cypress viewport based on the
14
+ * "viewport" and "orientation" profile variables
15
+ * @author Yuen Ler Chow
16
+ */
17
+ const setupViewport = () => {
18
+ beforeEach(() => {
19
+ // Read the viewport settings from the current profile
20
+ const rawViewport = Cypress.expose('viewport');
21
+ const rawOrientation = Cypress.expose('orientation');
22
+ // Resolve the profile variables into cy.viewport arguments
23
+ const resolved = (0, resolveViewport_1.default)(rawViewport, rawOrientation);
24
+ // Apply the viewport
25
+ if ('preset' in resolved) {
26
+ cy.viewport(resolved.preset, resolved.orientation);
27
+ }
28
+ else {
29
+ cy.viewport(resolved.width, resolved.height);
30
+ }
31
+ });
32
+ };
33
+ /*----------------------------------------*/
34
+ /* --------------- Export --------------- */
35
+ /*----------------------------------------*/
36
+ exports.default = setupViewport;
37
+ //# sourceMappingURL=setupViewport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setupViewport.js","sourceRoot":"","sources":["../../../src/commands/setupViewport.ts"],"names":[],"mappings":";AAAA,iCAAiC;;;;;AAEjC,iBAAiB;AACjB,gFAAwD;AAExD,4CAA4C;AAC5C,4CAA4C;AAC5C,4CAA4C;AAE5C;;;;GAIG;AACH,MAAM,aAAa,GAAG,GAAG,EAAE;IACzB,UAAU,CAAC,GAAG,EAAE;QACd,sDAAsD;QACtD,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,UAAU,CAAuB,CAAC;QACrE,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,aAAa,CAAuB,CAAC;QAE3E,2DAA2D;QAC3D,MAAM,QAAQ,GAAG,IAAA,yBAAe,EAAC,WAAW,EAAE,cAAc,CAAC,CAAC;QAE9D,qBAAqB;QACrB,IAAI,QAAQ,IAAI,QAAQ,EAAE,CAAC;YACzB,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;QACrD,CAAC;aAAM,CAAC;YACN,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,4CAA4C;AAC5C,4CAA4C;AAC5C,4CAA4C;AAE5C,kBAAe,aAAa,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dceky",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
4
4
  "description": "Cypress toolkit for Harvard DCE",
5
5
  "main": "./lib/src/index.js",
6
6
  "types": "./lib/src/index.d.ts",
@@ -50,6 +50,14 @@ const genEmptyProfileFile = (name: string): string => {
50
50
  ' // Static Value Examples:',
51
51
  ' // loginSystem: \'HarvardKey\'',
52
52
  '',
53
+ ' // Viewport Example (default: desktop):',
54
+ ' // Generic aliases: desktop, macbook, ipad, iphone',
55
+ ' // ...or any Cypress preset (e.g. iphone-x, ipad-2, macbook-16)',
56
+ ' // viewport: \'desktop\',',
57
+ '',
58
+ ' // Orientation Example (default: landscape, or portrait for iphone):',
59
+ ' // orientation: \'landscape\',',
60
+ '',
53
61
  ' // Dependent Value Example:',
54
62
  ' // loginHost: {',
55
63
  ' // dependsOn: \'loginSystem\',',
@@ -0,0 +1,95 @@
1
+ /// <reference types="cypress" />
2
+
3
+ /*----------------------------------------*/
4
+ /* -------------- Constants ------------- */
5
+ /*----------------------------------------*/
6
+
7
+ // Generic viewport aliases that map to a specific Cypress device preset
8
+ const GENERIC_VIEWPORT_ALIASES: { [alias: string]: Cypress.ViewportPreset } = {
9
+ iphone: 'iphone-x',
10
+ ipad: 'ipad-2',
11
+ macbook: 'macbook-16',
12
+ };
13
+
14
+ // Special "desktop" preset: dimensions of a 4k monitor
15
+ const DESKTOP_VIEWPORT = { width: 3840, height: 2160 };
16
+
17
+ // Preset to use when no viewport is specified in the profile
18
+ const DEFAULT_VIEWPORT = 'desktop';
19
+
20
+ /*----------------------------------------*/
21
+ /* ----------------- Type --------------- */
22
+ /*----------------------------------------*/
23
+
24
+ type ResolvedViewport = (
25
+ // A native Cypress device preset...
26
+ | {
27
+ preset: Cypress.ViewportPreset,
28
+ orientation: Cypress.ViewportOrientation,
29
+ }
30
+ // ...or explicit dimensions (used for the "desktop" preset)
31
+ | {
32
+ width: number,
33
+ height: number,
34
+ }
35
+ );
36
+
37
+ /*----------------------------------------*/
38
+ /* --------------- Helper --------------- */
39
+ /*----------------------------------------*/
40
+
41
+ /**
42
+ * Resolve the "viewport" and "orientation" profile variables into arguments
43
+ * for cy.viewport. Generic aliases (iphone, ipad, macbook, desktop) are mapped
44
+ * to specific devices, and a sensible default orientation is chosen
45
+ * @author Yuen Ler Chow
46
+ * @param rawViewport the "viewport" profile variable (a preset name or generic
47
+ * alias). Defaults to "desktop" if not provided
48
+ * @param rawOrientation the "orientation" profile variable ("landscape" or
49
+ * "portrait"). Defaults to "landscape", or "portrait" for iphone viewports
50
+ * @returns resolved arguments for cy.viewport
51
+ */
52
+ const resolveViewport = (
53
+ rawViewport?: string,
54
+ rawOrientation?: string,
55
+ ): ResolvedViewport => {
56
+ // Normalize the requested viewport (default to desktop)
57
+ const requested = (rawViewport ?? DEFAULT_VIEWPORT).trim().toLowerCase();
58
+
59
+ // Resolve generic aliases (e.g. "iphone" => "iphone-x")
60
+ const viewport = (GENERIC_VIEWPORT_ALIASES[requested] ?? requested);
61
+
62
+ // Determine orientation (default landscape, but portrait for iphones)
63
+ const isIphone = viewport.startsWith('iphone');
64
+ const defaultOrientation = (isIphone ? 'portrait' : 'landscape');
65
+ const orientation = (
66
+ rawOrientation
67
+ ? rawOrientation.trim().toLowerCase()
68
+ : defaultOrientation
69
+ );
70
+
71
+ // Validate orientation
72
+ if (orientation !== 'landscape' && orientation !== 'portrait') {
73
+ throw new Error(
74
+ `dceky: Invalid "orientation" profile variable "${rawOrientation}". Expected "landscape" or "portrait".`,
75
+ );
76
+ }
77
+
78
+ // Handle the special "desktop" preset (a 4k monitor)
79
+ if (viewport === 'desktop') {
80
+ const { width, height } = DESKTOP_VIEWPORT;
81
+ // Swap dimensions for portrait
82
+ return (
83
+ orientation === 'portrait'
84
+ ? { width: height, height: width }
85
+ : { width, height }
86
+ );
87
+ }
88
+
89
+ return {
90
+ preset: viewport as Cypress.ViewportPreset,
91
+ orientation: orientation as Cypress.ViewportOrientation,
92
+ };
93
+ };
94
+
95
+ export default resolveViewport;
@@ -33,6 +33,7 @@ import getProfileValue from './getProfileValue';
33
33
  import getCredentialValue from './getCredentialValue';
34
34
  import getCredentialValues from './getCredentialValues';
35
35
  import sendRequest from './sendRequest';
36
+ import setupViewport from './setupViewport';
36
37
 
37
38
  /**
38
39
  * Initialize custom commands
@@ -74,6 +75,7 @@ const commands = () => {
74
75
  getCredentialValue();
75
76
  getCredentialValues();
76
77
  sendRequest();
78
+ setupViewport();
77
79
  };
78
80
 
79
81
  export default commands;
@@ -0,0 +1,37 @@
1
+ /// <reference types="cypress" />
2
+
3
+ // Import helpers
4
+ import resolveViewport from './helpers/resolveViewport';
5
+
6
+ /*----------------------------------------*/
7
+ /* --------------- Command -------------- */
8
+ /*----------------------------------------*/
9
+
10
+ /**
11
+ * Register a global beforeEach hook that sets the Cypress viewport based on the
12
+ * "viewport" and "orientation" profile variables
13
+ * @author Yuen Ler Chow
14
+ */
15
+ const setupViewport = () => {
16
+ beforeEach(() => {
17
+ // Read the viewport settings from the current profile
18
+ const rawViewport = Cypress.expose('viewport') as string | undefined;
19
+ const rawOrientation = Cypress.expose('orientation') as string | undefined;
20
+
21
+ // Resolve the profile variables into cy.viewport arguments
22
+ const resolved = resolveViewport(rawViewport, rawOrientation);
23
+
24
+ // Apply the viewport
25
+ if ('preset' in resolved) {
26
+ cy.viewport(resolved.preset, resolved.orientation);
27
+ } else {
28
+ cy.viewport(resolved.width, resolved.height);
29
+ }
30
+ });
31
+ };
32
+
33
+ /*----------------------------------------*/
34
+ /* --------------- Export --------------- */
35
+ /*----------------------------------------*/
36
+
37
+ export default setupViewport;