ui5-test-runner 3.3.5 → 4.0.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.
package/README.md CHANGED
@@ -20,7 +20,7 @@ A self-sufficient test runner for UI5 applications enabling parallel execution o
20
20
 
21
21
  ## 💿 How to install
22
22
 
23
- * Works with [Node.js](https://nodejs.org/en/download/) >= 16
23
+ * Works with [Node.js](https://nodejs.org/en/download/) >= 18
24
24
  * Local installation
25
25
  * `npm install --save-dev ui5-test-runner`
26
26
  * Trigger either with `npx ui5-test-runner` or through an npm script invoking `ui5-test-runner`
@@ -49,6 +49,9 @@ A self-sufficient test runner for UI5 applications enabling parallel execution o
49
49
 
50
50
  ## ⚠️ Breaking changes
51
51
 
52
+ ### v4
53
+ * Dropping support of Node.js 16
54
+
52
55
  ### v3
53
56
  * Dropping support of Node.js 14
54
57
 
@@ -58,3 +61,8 @@ A self-sufficient test runner for UI5 applications enabling parallel execution o
58
61
  * Dependencies are installed **on demand**
59
62
  * Browser instantiation command evolved in an **incompatible way** (see [documentation](https://arnaudbuchholz.github.io/ui5-test-runner/browser.html)).
60
63
  * Output is different (report, traces)
64
+
65
+ ## ✒ Contributors
66
+
67
+ * [Marian Zeis](https://github.com/marianfoo): Documentation page revamp [PR #54](https://github.com/ArnaudBuchholz/ui5-test-runner/pull/54)
68
+ * [Raj Singh](https://github.com/rajxsingh): Basic HTTP Authentication in Puppeteer [PR #71](https://github.com/ArnaudBuchholz/ui5-test-runner/pull/71)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ui5-test-runner",
3
- "version": "3.3.5",
3
+ "version": "4.0.0",
4
4
  "description": "Standalone test runner for UI5",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -12,15 +12,16 @@
12
12
  "ui5-test-runner": "./index.js"
13
13
  },
14
14
  "engines": {
15
- "node": ">=16"
15
+ "node": ">=18"
16
16
  },
17
17
  "scripts": {
18
18
  "lint": "standard --fix",
19
19
  "test": "npm run test:unit && npm run test:browsers && npm run test:samples",
20
20
  "test:browsers": "npm run test:integration:jsdom && npm run test:integration:puppeteer && npm run test:integration:selenium-webdriver-chrome && npm run test:integration:playwright",
21
- "test:samples": "npm run test:samples:js && npm run test:samples:ts",
21
+ "test:samples": "npm run test:samples:js && npm run test:samples:ts && npm run test:auth-sample",
22
22
  "test:samples:js": "npm run test:sample:js:legacy && npm run test:sample:js:coverage:legacy && npm run test:sample:js:legacy-remote && npm run test:sample:js:coverage:legacy-remote && npm run test:sample:js:remote && npm run test:sample:js:coverage:remote",
23
23
  "test:samples:ts": "npm run test:sample:ts:remote && npm run test:sample:ts:coverage:remote",
24
+ "test:auth-sample": "npm run test:auth-sample:remote",
24
25
  "test:coverall": "rimraf .nyc_output && jest --coverageDirectory .nyc_output --coverageReporters json && nyc --silent --no-clean npm run test:integration:jsdom && nyc --silent --no-clean npm run test:integration:puppeteer && nyc --silent --no-clean npm run test:integration:selenium-webdriver-chrome && nyc --silent --no-clean npm run test:integration:playwright && nyc merge .nyc_output .nyc_output/final/coverage.json && nyc report --temp-dir .nyc_output/final/ --report-dir coverage --branches 80 --functions 80 --lines 80 --statements 80",
25
26
  "test:unit": "jest",
26
27
  "test:unit:debug": "jest --runInBand",
@@ -41,7 +42,10 @@
41
42
  "serve:sample:ts": "cd ./test/sample.ts && node ui5.cjs serve",
42
43
  "test:sample:ts:coverage:remote": "start-server-and-test 'npm run serve:sample:ts:coverage' http://localhost:8080 'node . --url http://localhost:8080/test/testsuite.qunit.html --coverage --coverage-check-statements 67'",
43
44
  "serve:sample:ts:coverage": "cd ./test/sample.ts && node ui5.cjs serve --config ui5-coverage.yaml",
44
- "build:doc": "node build/doc"
45
+ "test:auth-sample:remote": "start-server-and-test 'npm run serve:auth-sample' http://localhost:8080 'node . --url http://localhost:8080/test/testsuite.qunit.html --browser $/puppeteer.js --browser-args --basic-auth-username testUsername --browser-args --basic-auth-password testPassword'",
46
+ "serve:auth-sample": "cd ./test/auth_sample.js && reserve --config ./reserve.json",
47
+ "build:doc": "node build/doc",
48
+ "clean": "npm uninstall -g ui5-test-runner puppeteer nyc selenium-webdriver playwright webdriverio"
45
49
  },
46
50
  "repository": {
47
51
  "type": "git",
@@ -63,23 +67,23 @@
63
67
  },
64
68
  "homepage": "https://github.com/ArnaudBuchholz/ui5-test-runner#readme",
65
69
  "dependencies": {
66
- "commander": "^11.0.0",
70
+ "commander": "^12.0.0",
67
71
  "mime": "^3.0.0",
68
72
  "punybind": "^1.2.1",
69
73
  "punyexpr": "^1.0.4",
70
- "reserve": "^1.15.4"
74
+ "reserve": "^1.15.6"
71
75
  },
72
76
  "devDependencies": {
73
- "@openui5/types": "^1.119.0",
74
- "@ui5/cli": "^3.6.1",
75
- "@ui5/middleware-code-coverage": "^1.1.0",
77
+ "@openui5/types": "^1.120.6",
78
+ "@ui5/cli": "^3.9.0",
79
+ "@ui5/middleware-code-coverage": "^1.1.1",
76
80
  "jest": "^29.7.0",
77
- "nock": "^13.3.3",
81
+ "nock": "^13.5.1",
78
82
  "nyc": "^15.1.0",
79
83
  "standard": "^17.1.0",
80
- "start-server-and-test": "^2.0.1",
81
- "typescript": "^5.2.2",
82
- "ui5-tooling-transpile": "^3.2.6"
84
+ "start-server-and-test": "^2.0.3",
85
+ "typescript": "^5.3.3",
86
+ "ui5-tooling-transpile": "^3.3.3"
83
87
  },
84
88
  "optionalDependencies": {
85
89
  "fsevents": "^2.3.3"
package/src/browsers.js CHANGED
@@ -214,13 +214,16 @@ async function screenshot (job, url, filename) {
214
214
  if (!job.browserCapabilities.screenshot) {
215
215
  throw UTRError.BROWSER_SCREENSHOT_NOT_SUPPORTED()
216
216
  }
217
+ const output = getOutput(job)
218
+ const id = ++lastScreenshotId
217
219
  try {
218
220
  const { childProcess, reportDir } = job[$browsers][url]
219
221
  const absoluteFilename = join(reportDir, filename + job.browserCapabilities.screenshot)
220
222
  if (childProcess.connected) {
221
- const id = ++lastScreenshotId
223
+ output.debug('screenshot', id, url, absoluteFilename)
222
224
  const { promise, resolve, reject } = allocPromise()
223
225
  screenshots[id] = resolve
226
+ output.debug('screenshot', id, 'sending command')
224
227
  childProcess.send({
225
228
  id,
226
229
  command: 'screenshot',
@@ -229,15 +232,20 @@ async function screenshot (job, url, filename) {
229
232
  const timeoutId = setTimeout(() => {
230
233
  reject(UTRError.BROWSER_SCREENSHOT_TIMEOUT())
231
234
  }, job.screenshotTimeout)
235
+ output.debug('screenshot', id, 'command sent, waiting for answer')
232
236
  await promise
237
+ output.debug('screenshot', id, 'answer received')
233
238
  clearTimeout(timeoutId)
234
239
  const result = await stat(absoluteFilename)
240
+ output.debug('screenshot', id, 'file size :', result.size)
235
241
  if (!result.isFile() || result.size === 0) {
236
242
  throw new Error('File expected')
237
243
  }
244
+ output.debug('screenshot', id, 'done')
238
245
  return absoluteFilename
239
246
  }
240
247
  } catch (e) {
248
+ output.debug('screenshot', id, e.message)
241
249
  if (e.code === UTRError.BROWSER_SCREENSHOT_TIMEOUT_CODE) {
242
250
  throw e
243
251
  }
@@ -4,7 +4,6 @@ const { check, serve, body } = require('reserve')
4
4
  const { probe, start, stop } = require('../browsers')
5
5
  const { join } = require('path')
6
6
  const { getOutput } = require('../output')
7
- const EventEmitter = require('events')
8
7
  const { performance } = require('perf_hooks')
9
8
  const { cleanDir, allocPromise, filename } = require('../tools')
10
9
  const { $browsers } = require('../symbols')
@@ -60,13 +59,16 @@ async function capabilities (job) {
60
59
  const { referer, 'x-page-url': xPageUrl } = request.headers
61
60
  const listenerIndex = (xPageUrl || referer).match(/\blistener=(\d+)/)[1]
62
61
  const listener = listeners[listenerIndex]
63
- listener.emit('endpoint', {
62
+ await listener({
64
63
  endpoint,
65
64
  body: JSON.parse(await body(request))
66
65
  })
67
66
  response.writeHead(200)
68
67
  response.end()
69
68
  }
69
+ }, {
70
+ match: '^/inject/(.*)',
71
+ file: join(__dirname, '../inject/$1')
70
72
  }, {
71
73
  match: '^/(.*)',
72
74
  file: join(__dirname, '$1')
@@ -105,8 +107,6 @@ async function capabilities (job) {
105
107
  const { label, url, scripts, endpoint = () => { } } = filteredTests.shift()
106
108
 
107
109
  const listenerIndex = listeners.length
108
- const listener = new EventEmitter()
109
- listeners.push(listener)
110
110
  let pageUrl
111
111
  if (url.startsWith('http')) {
112
112
  pageUrl = url
@@ -151,7 +151,7 @@ async function capabilities (job) {
151
151
  const context = {
152
152
  job
153
153
  }
154
- listener.on('endpoint', async data => {
154
+ listeners[listenerIndex] = async data => {
155
155
  try {
156
156
  if (await endpoint.call(context, data, pageUrl) !== false) {
157
157
  done()
@@ -159,7 +159,7 @@ async function capabilities (job) {
159
159
  } catch (e) {
160
160
  done(e)
161
161
  }
162
- })
162
+ }
163
163
 
164
164
  start(job, pageUrl, scripts)
165
165
  .catch(reason => done(reason))
@@ -3,11 +3,21 @@
3
3
  <body>
4
4
  <H1>screenshot</H1>
5
5
  <p>Checks if the browser supports screenshot</p>
6
+ <input type="text" id="first" value="first">
7
+ <input type="text" id="second" value="second">
6
8
  <span style="font-size: 32rem;">&#128521;</span>
9
+ <script src="/inject/post.js"></script>
7
10
  <script>
8
- const xhr = new XMLHttpRequest()
9
- xhr.open('POST', '/_/log')
10
- xhr.send('{}')
11
+ document.getElementById('first').focus()
12
+ const post = window['ui5-test-runner/post']
13
+ post('/_/log', { step:'screenshot' })
14
+ .then(() => {
15
+ const current = document.activeElement
16
+ return post('/_/log', {
17
+ step: 'focus',
18
+ current: current ? current.id : ''
19
+ })
20
+ })
11
21
  </script>
12
22
  </body>
13
23
  </html>
@@ -8,11 +8,17 @@ module.exports = {
8
8
  label: 'Screenshot',
9
9
  for: capabilities => !!capabilities.screenshot,
10
10
  url: 'screenshot/index.html',
11
- endpoint: async function (_, url) {
11
+ endpoint: async function ({ body: { step, current } }, url) {
12
12
  const { job } = this
13
- const fileName = await screenshot(job, url, 'screenshot')
14
- const fileInfo = await stat(fileName)
15
- assert.ok(fileInfo.isFile(), 'The file was generated')
16
- assert.ok(fileInfo.size > 1024, 'The file contains something')
13
+ if (step === 'screenshot') {
14
+ const fileName = await screenshot(job, url, 'screenshot')
15
+ const fileInfo = await stat(fileName)
16
+ assert.ok(fileInfo.isFile(), 'The file was generated')
17
+ assert.ok(fileInfo.size > 1024, 'The file contains something')
18
+ return false
19
+ } else {
20
+ assert.strictEqual(current, 'first')
21
+ return true
22
+ }
17
23
  }
18
24
  }
@@ -17,7 +17,7 @@ const expectedLogs = [{
17
17
  type: 'log',
18
18
  text: /^"?complex parameters"? 1 true / // Not sure how objects are handled
19
19
  }, {
20
- type: 'warning',
20
+ type: /warning|warn/,
21
21
  text: 'A warning'
22
22
  }, {
23
23
  type: 'error',
@@ -11,27 +11,13 @@ require('./browser')({
11
11
  ['-w, --viewport-width <width>', 'Viewport width', 1920],
12
12
  ['-h, --viewport-height <height>', 'Viewport height', 1080],
13
13
  ['-l, --language <lang...>', 'Language(s)', ['en-US']],
14
- ['-u, --unsecure', 'Disable security features', false]
15
- ] // ,
16
- // TODO restore when Node16 is no more supported
17
- // capabilities: {
18
- // modules: ['puppeteer'],
19
- // screenshot: '.png',
20
- // scripts: true,
21
- // traces: ['console', 'network']
22
- // }
23
- },
24
-
25
- // TODO remove when Node16 is no more supported
26
- async capabilities () {
27
- const version = process.version.match(/^v(\d+\.\d+)/)[1]
28
- let screenshot
29
- if (!version.startsWith('16')) {
30
- screenshot = '.png'
31
- }
32
- return {
14
+ ['-u, --unsecure', 'Disable security features', false],
15
+ ['--basic-auth-username <username>', 'Username for basic authentication', ''],
16
+ ['--basic-auth-password <password>', 'Password for basic authentication', '']
17
+ ],
18
+ capabilities: {
33
19
  modules: ['puppeteer'],
34
- screenshot,
20
+ screenshot: '.png',
35
21
  scripts: true,
36
22
  traces: ['console', 'network']
37
23
  }
@@ -94,6 +80,10 @@ require('./browser')({
94
80
  await page.setBypassCSP(true)
95
81
  }
96
82
 
83
+ if (options.basicAuthUsername || options.basicAuthPassword) {
84
+ await page.authenticate({ username: options.basicAuthUsername, password: options.basicAuthPassword })
85
+ }
86
+
97
87
  page
98
88
  .on('console', message => consoleWriter.append({
99
89
  type: message.type(),
package/src/job.js CHANGED
@@ -7,7 +7,7 @@ const { name, description, version } = require(join(__dirname, '../package.json'
7
7
  const { getOutput } = require('./output')
8
8
  const { $valueSources, $remoteOnLegacy } = require('./symbols')
9
9
  const { buildAndCheckMode } = require('./job-mode')
10
- const { boolean, integer, timeout, url, arrayOf, regex, percent } = require('./options')
10
+ const { boolean, integer, timeout, url, arrayOf, regex, percent, string } = require('./options')
11
11
 
12
12
  const $status = Symbol('status')
13
13
 
@@ -115,7 +115,7 @@ function getCommand (cwd) {
115
115
  .option('--no-screenshot', '[💻🔗] Disable screenshots')
116
116
  .option('-st, --screenshot-timeout <timeout>', '[💻🔗] Maximum waiting time for browser screenshot', timeout, 5000)
117
117
  .option('-rg, --report-generator <path...>', '[💻🔗] Report generator paths (relative to cwd or use $/ for provided ones)', ['$/report.js'])
118
- .option('-pp, --progress-page <path>', '[💻🔗] progress page path (relative to cwd or use $/ for provided ones)', '$/report/default.html')
118
+ .option('--progress-page <path>', '[💻🔗] progress page path (relative to cwd or use $/ for provided ones)', '$/report/default.html')
119
119
 
120
120
  .option('--coverage [flag]', '[💻🔗] Enable or disable code coverage', boolean)
121
121
  .option('--no-coverage', '[💻🔗] Disable code coverage')
@@ -136,7 +136,7 @@ function getCommand (cwd) {
136
136
  .option('--mappings <mapping...>', '[💻] Custom mapping (<match>=<file|url>(<config>))', arrayOf(mapping))
137
137
  .option('--cache <path>', '[💻] Cache UI5 resources locally in the given folder (empty to disable)')
138
138
  .option('--webapp <path>', '[💻] Base folder of the web application (relative to cwd)', 'webapp')
139
- .option('--testsuite <path>', '[💻] Path of the testsuite file (relative to webapp)', 'test/testsuite.qunit.html')
139
+ .option('--testsuite <path>', '[💻] Path of the testsuite file (relative to webapp, URL parameters are supported)', 'test/testsuite.qunit.html')
140
140
  .option('-w, --watch [flag]', '[💻] Monitor the webapp folder and re-execute tests on change', boolean, false)
141
141
 
142
142
  // Specific to coverage in url mode (experimental)
@@ -152,6 +152,7 @@ function getCommand (cwd) {
152
152
  .addOption(new Option('--debug-capabilities-no-timeout', DEBUG_OPTION, boolean).hideHelp())
153
153
  .addOption(new Option('--debug-coverage', DEBUG_OPTION, boolean).hideHelp())
154
154
  .addOption(new Option('--debug-coverage-no-custom-fs', DEBUG_OPTION, boolean).hideHelp())
155
+ .addOption(new Option('--debug-verbose <module...>', DEBUG_OPTION, arrayOf(string), []).hideHelp())
155
156
 
156
157
  return command
157
158
  }
@@ -227,7 +228,9 @@ function finalize (job) {
227
228
  job.mode = buildAndCheckMode(job)
228
229
  if (job.mode === 'legacy') {
229
230
  checkAccess({ path: job.webapp, label: 'webapp folder' })
230
- const testsuitePath = toAbsolute(job.testsuite, job.webapp)
231
+
232
+ const [, testsuiteFile] = job.testsuite.match(/([^?]*)(\?.*)?$/)
233
+ const testsuitePath = toAbsolute(testsuiteFile, job.webapp)
231
234
  checkAccess({ path: testsuitePath, label: 'testsuite', file: true })
232
235
  } else if (job.mode === 'url') {
233
236
  if (job[$valueSources].coverage !== 'cli') {
package/src/job.spec.js CHANGED
@@ -211,6 +211,12 @@ describe('job', () => {
211
211
  })).toThrow()
212
212
  })
213
213
 
214
+ it('supports parameters for testsuite (stripping ?)', () => {
215
+ expect(() => buildJob({
216
+ testsuite: 'test/testsuite.qunit.html?a=b'
217
+ })).not.toThrow()
218
+ })
219
+
214
220
  it('fails on a missing file (points to a folder)', () => {
215
221
  expect(() => buildJob({
216
222
  testsuite: 'lib'
package/src/options.js CHANGED
@@ -41,6 +41,10 @@ module.exports = {
41
41
 
42
42
  integer,
43
43
 
44
+ string (value) {
45
+ return value
46
+ },
47
+
44
48
  timeout (value) {
45
49
  const int = integer(value)
46
50
  if (value.endsWith('ms')) {
package/src/output.js CHANGED
@@ -225,6 +225,12 @@ function build (job) {
225
225
  log(job, p80()`Server running at ${pad.lt(url)}`)
226
226
  },
227
227
 
228
+ debug: wrap((module, ...args) => {
229
+ if (job.debugVerbose && job.debugVerbose.includes(module)) {
230
+ console.log(`🐞${module}`, ...args)
231
+ }
232
+ }),
233
+
228
234
  redirected: wrap(({ method, url, statusCode, timeSpent }) => {
229
235
  if (url.startsWith('/_/progress')) {
230
236
  return // avoids pollution