ui5-test-runner 5.2.0 → 5.3.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.
@@ -9,14 +9,17 @@
9
9
  const base = window['ui5-test-runner/base-host'] || ''
10
10
 
11
11
  let lastPost = Promise.resolve()
12
- let UI5Object
12
+
13
+ function isUI5Object (obj) {
14
+ return typeof obj === 'object' &&
15
+ obj !== null &&
16
+ typeof obj.getId === 'function' &&
17
+ typeof obj.getMetadata === 'function'
18
+ }
13
19
 
14
20
  function stringify (data) {
15
21
  const objects = []
16
22
  const referenced = []
17
- if (!UI5Object && window.sap && window.sap.ui && window.sap.ui.base) {
18
- UI5Object = window.sap.ui.base.Object
19
- }
20
23
  const ui5Summary = obj => {
21
24
  const id = obj.getId && obj.getId()
22
25
  const className = obj.getMetadata && obj.getMetadata() && obj.getMetadata().getName()
@@ -27,7 +30,7 @@
27
30
  }
28
31
  const simple = JSON.stringify(data, function (key, value) {
29
32
  if (typeof value === 'object' && value) {
30
- if (UI5Object && value instanceof UI5Object) {
33
+ if (isUI5Object(value)) {
31
34
  return ui5Summary(value)
32
35
  }
33
36
  const id = objects.indexOf(value)
@@ -45,7 +48,7 @@
45
48
  const stringified = []
46
49
  return JSON.stringify(data, function (key, value) {
47
50
  if (typeof value === 'object' && value) {
48
- if (UI5Object && value instanceof UI5Object) {
51
+ if (isUI5Object(value)) {
49
52
  return ui5Summary(value)
50
53
  }
51
54
  const id = objects.indexOf(value)
@@ -71,6 +74,8 @@
71
74
 
72
75
  window['ui5-test-runner/stringify'] = stringify
73
76
 
77
+ const xPageUrl = top.location.toString()
78
+
74
79
  window[MODULE] = function post (url, data) {
75
80
  function request () {
76
81
  return new Promise(function (resolve, reject) {
@@ -82,18 +87,20 @@
82
87
  reject(xhr.statusText)
83
88
  })
84
89
  xhr.open('POST', base + '/_/' + url)
85
- xhr.setRequestHeader('x-page-url', top.location)
90
+ xhr.setRequestHeader('x-page-url', xPageUrl)
86
91
  xhr.setRequestHeader('content-type', 'application/json')
87
92
  const json = stringify(data)
88
93
  xhr.setRequestHeader('content-length', json.length)
89
94
  xhr.send(json)
90
95
  })
91
96
  }
92
- lastPost = lastPost
93
- .then(request)
94
- .then(undefined, function (reason) {
95
- console.error('Failed to POST to ' + url + '\nreason: ' + reason.toString())
96
- })
97
+ lastPost = lastPost.then(request)
98
+ if (!window.__unsafe__) {
99
+ lastPost = lastPost
100
+ .then(undefined, function (reason) {
101
+ console.error('Failed to POST to ' + url + '\nreason: ' + reason.toString())
102
+ })
103
+ }
97
104
  return lastPost
98
105
  }
99
106
  }())
@@ -29,7 +29,9 @@
29
29
  set: function (value) {
30
30
  QUnit = value
31
31
  Object.keys(callbacks).forEach(property => {
32
- QUnit[property](callbacks[property])
32
+ if (typeof QUnit[property] === 'function') {
33
+ QUnit[property](callbacks[property])
34
+ }
33
35
  })
34
36
  }
35
37
  })
@@ -33,20 +33,23 @@
33
33
  QUnit = value
34
34
 
35
35
  const { test } = QUnit
36
- QUnit.test = (label) => test(label, (assert) => assert.ok(true, label))
36
+ if (typeof test === 'function') {
37
+ QUnit.test = (label) => test(label, (assert) => assert.ok(true, label))
37
38
 
38
- let timeoutId
39
- QUnit.moduleDone(function () {
40
- if (timeoutId) {
41
- clearTimeout(timeoutId)
42
- }
43
- timeoutId = setTimeout(notify, 10)
44
- })
39
+ let timeoutId
40
+ QUnit.moduleDone(function () {
41
+ if (timeoutId) {
42
+ clearTimeout(timeoutId)
43
+ }
44
+ timeoutId = setTimeout(notify, 10)
45
+ })
45
46
 
46
- function notify () {
47
- const modules = QUnit.config.modules.map(({ moduleId }) => moduleId)
48
- const opa = !!window?.sap?.ui?.test?.Opa5
49
- post('addTestPages', { type: 'qunit', opa, modules, page: location.toString() })
47
+ function notify () {
48
+ const moduleIds = QUnit.config.modules.map(({ moduleId }) => moduleId).filter(moduleId => !!moduleId)
49
+ const moduleNames = QUnit.config.modules.map(({ name }) => name)
50
+ const opa = !!window?.sap?.ui?.test?.Opa5
51
+ post('addTestPages', { type: 'qunit', opa, module: { ids: moduleIds.length ? moduleIds : undefined, names: moduleNames }, page: location.toString() })
52
+ }
50
53
  }
51
54
  }
52
55
  })