@applitools/visual-grid-cli-utils 1.21.42 → 1.21.44

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applitools/visual-grid-cli-utils",
3
- "version": "1.21.42",
3
+ "version": "1.21.44",
4
4
  "description": "",
5
5
  "main": "src/visual-grid-cli-utils.js",
6
6
  "engines": {
@@ -0,0 +1,27 @@
1
+ 'use strict'
2
+
3
+ function buildSafariEmulationInfo({
4
+ safariEmulationDeviceName,
5
+ safariEmulationOrientation,
6
+ safariEmulationViewport,
7
+ safariEmulationPixelRatio,
8
+ safariEmulationUserAgent,
9
+ }) {
10
+ const anyFlagSet = !!(
11
+ safariEmulationDeviceName ||
12
+ safariEmulationViewport ||
13
+ safariEmulationPixelRatio !== undefined ||
14
+ safariEmulationUserAgent
15
+ )
16
+ if (!anyFlagSet) return undefined
17
+
18
+ const info = {}
19
+ if (safariEmulationDeviceName) info.deviceName = safariEmulationDeviceName
20
+ if (safariEmulationViewport) info.viewport = safariEmulationViewport
21
+ if (safariEmulationPixelRatio !== undefined) info.pixelRatio = safariEmulationPixelRatio
22
+ if (safariEmulationUserAgent) info.userAgent = safariEmulationUserAgent
23
+ info.screenOrientation = safariEmulationOrientation || 'portrait'
24
+ return info
25
+ }
26
+
27
+ module.exports = buildSafariEmulationInfo
@@ -0,0 +1,11 @@
1
+ 'use strict'
2
+
3
+ function parseViewport(arg) {
4
+ const match = /^(\d+)x(\d+)$/i.exec(arg)
5
+ if (!match) {
6
+ throw new Error(`invalid viewport "${arg}". Expected format: WIDTHxHEIGHT (e.g., 393x695)`)
7
+ }
8
+ return {width: parseInt(match[1], 10), height: parseInt(match[2], 10)}
9
+ }
10
+
11
+ module.exports = parseViewport
package/src/job-info.js CHANGED
@@ -3,6 +3,7 @@ const {fetchAsJsonWithJsonBody} = require('@applitools/http-commons')
3
3
  const createSession = require('./commons/create-session')
4
4
  const {convertBrowserNameToCanary} = require('./commons/parse-browser')
5
5
  const parseJson = require('./commons/parse-json.js')
6
+ const buildSafariEmulationInfo = require('./commons/build-safari-emulation-info')
6
7
 
7
8
  async function main({
8
9
  apiKey,
@@ -13,6 +14,11 @@ async function main({
13
14
  native,
14
15
  deviceEmulation,
15
16
  deviceOrientation,
17
+ safariEmulationDeviceName,
18
+ safariEmulationOrientation,
19
+ safariEmulationViewport,
20
+ safariEmulationPixelRatio,
21
+ safariEmulationUserAgent,
16
22
  iosDeviceName,
17
23
  iosDeviceOrientation,
18
24
  androidDeviceName,
@@ -29,6 +35,14 @@ async function main({
29
35
  options.chromeHeadless = headless
30
36
  const vgUrl = process.env.VG_URL || 'https://render-wus.applitools.com'
31
37
 
38
+ const safariEmulationInfo = buildSafariEmulationInfo({
39
+ safariEmulationDeviceName,
40
+ safariEmulationOrientation,
41
+ safariEmulationViewport,
42
+ safariEmulationPixelRatio,
43
+ safariEmulationUserAgent,
44
+ })
45
+
32
46
  const {webhook, authToken} = await createSession(apiKey, serverUrl)
33
47
 
34
48
  const renderInfoUrl = new URL('./job-info', vgUrl)
@@ -38,9 +52,11 @@ async function main({
38
52
  accountOverride,
39
53
  webhook,
40
54
  renderInfo: {
41
- emulationInfo: deviceEmulation
42
- ? {deviceName: deviceEmulation, screenOrientation: deviceOrientation}
43
- : undefined,
55
+ emulationInfo:
56
+ safariEmulationInfo ||
57
+ (deviceEmulation
58
+ ? {deviceName: deviceEmulation, screenOrientation: deviceOrientation}
59
+ : undefined),
44
60
  iosDeviceInfo: iosDeviceName
45
61
  ? {
46
62
  name: iosDeviceName,
@@ -56,8 +72,8 @@ async function main({
56
72
  }
57
73
  : undefined,
58
74
  vhsType: androidDeviceName ? androidVhsType : undefined,
59
- width: deviceEmulation || iosDeviceName ? undefined : width,
60
- height: deviceEmulation || iosDeviceName ? undefined : height,
75
+ width: deviceEmulation || iosDeviceName || safariEmulationInfo ? undefined : width,
76
+ height: deviceEmulation || iosDeviceName || safariEmulationInfo ? undefined : height,
61
77
  target: 'full-page',
62
78
  },
63
79
  agentId: `visual-grid-cli-utils/${require('../package.json').version}`,
package/src/rerender.js CHANGED
@@ -12,6 +12,7 @@ const {convertBrowserNameToCanary} = require('./commons/parse-browser')
12
12
  const parseJson = require('./commons/parse-json.js')
13
13
  const normalizeChainedSelectorsArray = require('./commons/normalizeChainedSelectorsArray')
14
14
  const normalizeChainedSelectorsToFindRegionsForArray = require('./commons/normalizeChainedSelectorsToFindRegionsForArray')
15
+ const buildSafariEmulationInfo = require('./commons/build-safari-emulation-info')
15
16
 
16
17
  async function main({
17
18
  apiKey,
@@ -26,6 +27,11 @@ async function main({
26
27
  headless,
27
28
  deviceEmulation,
28
29
  deviceOrientation,
30
+ safariEmulationDeviceName,
31
+ safariEmulationOrientation,
32
+ safariEmulationViewport,
33
+ safariEmulationPixelRatio,
34
+ safariEmulationUserAgent,
29
35
  androidDeviceName,
30
36
  androidVersion,
31
37
  androidDeviceOrientation,
@@ -64,6 +70,14 @@ async function main({
64
70
  options.chromeHeadless = headless
65
71
  const vgUrl = process.env.VG_URL || 'https://render-wus.applitools.com'
66
72
 
73
+ const safariEmulationInfo = buildSafariEmulationInfo({
74
+ safariEmulationDeviceName,
75
+ safariEmulationOrientation,
76
+ safariEmulationViewport,
77
+ safariEmulationPixelRatio,
78
+ safariEmulationUserAgent,
79
+ })
80
+
67
81
  const finalOutputFile = outputFile || path.join(fs.mkdtempSync(os.tmpdir() + '/'), 'rerender.png')
68
82
  const domSnapshotOutputFile = finalOutputFile.replace(/\.[a-zA-Z0-0]+$/, '.json')
69
83
  const domSnapshotHtml = finalOutputFile.replace(/\.[a-zA-Z0-0]+$/, '.html')
@@ -75,9 +89,11 @@ async function main({
75
89
  accountOverride,
76
90
  webhook,
77
91
  renderInfo: {
78
- emulationInfo: deviceEmulation
79
- ? {deviceName: deviceEmulation, screenOrientation: deviceOrientation}
80
- : undefined,
92
+ emulationInfo:
93
+ safariEmulationInfo ||
94
+ (deviceEmulation
95
+ ? {deviceName: deviceEmulation, screenOrientation: deviceOrientation}
96
+ : undefined),
81
97
  iosDeviceInfo: iosDeviceName
82
98
  ? {
83
99
  name: iosDeviceName,
@@ -99,8 +115,8 @@ async function main({
99
115
  }
100
116
  : undefined,
101
117
  vhsType: androidDeviceName ? androidVhsType : undefined,
102
- width: deviceEmulation || iosDeviceName ? undefined : width,
103
- height: deviceEmulation || iosDeviceName ? undefined : height,
118
+ width: deviceEmulation || iosDeviceName || safariEmulationInfo ? undefined : width,
119
+ height: deviceEmulation || iosDeviceName || safariEmulationInfo ? undefined : height,
104
120
  target,
105
121
  selector: selector
106
122
  ? {selector, type: selector.startsWith('//') ? 'xpath' : 'css'}
@@ -148,8 +148,8 @@ async function main({
148
148
  console.log('\n✓ Successfully generated view URL via new endpoint')
149
149
  viewRenderingUrl = result.url
150
150
  } else {
151
- console.log('\n⚠ New endpoint unavailable, using legacy method')
152
- console.log(` Reason: ${result.error}`)
151
+ console.debug(` (${result.error})`)
152
+ console.log('\n⚠ Legacy method used: Render ID predates SSA refactor.')
153
153
  viewRenderingUrl = calculateViewRenderingUrl(renderId, finalAuthToken, accountOverride)
154
154
  }
155
155
 
@@ -2,6 +2,7 @@
2
2
  const yargs = require('yargs')
3
3
  const {parseBrowser} = require('./commons/parse-browser')
4
4
  const parseRegion = require('./commons/parse-region')
5
+ const parseViewport = require('./commons/parse-viewport')
5
6
  const splitApiKey = require('./commons/split-api-key')
6
7
 
7
8
  async function main(argv, {shouldExitOnError = false} = {}) {
@@ -128,6 +129,29 @@ async function main(argv, {shouldExitOnError = false} = {}) {
128
129
  choices: ['portrait', 'landscape'],
129
130
  default: 'portrait',
130
131
  })
132
+ .option('safari-emulation-device-name', {
133
+ describe: 'the device name to use for Safari emulation (e.g., "iPhone 16")',
134
+ type: 'string',
135
+ })
136
+ .option('safari-emulation-orientation', {
137
+ describe: 'portrait or landscape for Safari emulation',
138
+ type: 'string',
139
+ choices: ['portrait', 'landscape'],
140
+ default: 'portrait',
141
+ })
142
+ .option('safari-emulation-viewport', {
143
+ describe: 'viewport for Safari emulation, in WIDTHxHEIGHT format (e.g., 393x695)',
144
+ type: 'string',
145
+ coerce: parseViewport,
146
+ })
147
+ .option('safari-emulation-pixel-ratio', {
148
+ describe: 'device pixel ratio for Safari emulation (e.g., 3)',
149
+ type: 'number',
150
+ })
151
+ .option('safari-emulation-user-agent', {
152
+ describe: 'user-agent string for Safari emulation',
153
+ type: 'string',
154
+ })
131
155
  .option('android-device-name', {
132
156
  describe: 'the name of the Android device to use',
133
157
  type: 'string',
@@ -491,6 +515,29 @@ async function main(argv, {shouldExitOnError = false} = {}) {
491
515
  choices: ['portrait', 'landscape'],
492
516
  default: 'portrait',
493
517
  })
518
+ .option('safari-emulation-device-name', {
519
+ describe: 'the device name to use for Safari emulation (e.g., "iPhone 16")',
520
+ type: 'string',
521
+ })
522
+ .option('safari-emulation-orientation', {
523
+ describe: 'portrait or landscape for Safari emulation',
524
+ type: 'string',
525
+ choices: ['portrait', 'landscape'],
526
+ default: 'portrait',
527
+ })
528
+ .option('safari-emulation-viewport', {
529
+ describe: 'viewport for Safari emulation, in WIDTHxHEIGHT format (e.g., 393x695)',
530
+ type: 'string',
531
+ coerce: parseViewport,
532
+ })
533
+ .option('safari-emulation-pixel-ratio', {
534
+ describe: 'device pixel ratio for Safari emulation (e.g., 3)',
535
+ type: 'number',
536
+ })
537
+ .option('safari-emulation-user-agent', {
538
+ describe: 'user-agent string for Safari emulation',
539
+ type: 'string',
540
+ })
494
541
  .option('ios-device-name', {
495
542
  describe: 'the name of the iOS device to use',
496
543
  type: 'string',
@@ -810,7 +857,7 @@ async function main(argv, {shouldExitOnError = false} = {}) {
810
857
 
811
858
  const args = /**@type {object}*/ (commandLineOptions.parse())
812
859
 
813
- if (args._ && args._[0]) {
860
+ if (args._ && args._[0] && !args.help) {
814
861
  try {
815
862
  return await require(`./${args._[0]}`)(normalizeArgs(args))
816
863
  } catch (err) {