@schukai/monster 1.24.0 → 1.25.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. package/CHANGELOG +14 -0
  2. package/README.md +4 -4
  3. package/dist/modules/constants.js +2 -2
  4. package/dist/modules/constraints/abstract.js +1 -1
  5. package/dist/modules/constraints/abstractoperator.js +1 -1
  6. package/dist/modules/constraints/andoperator.js +1 -1
  7. package/dist/modules/constraints/invalid.js +1 -1
  8. package/dist/modules/constraints/isarray.js +1 -1
  9. package/dist/modules/constraints/isobject.js +1 -1
  10. package/dist/modules/constraints/namespace.js +1 -1
  11. package/dist/modules/constraints/oroperator.js +1 -1
  12. package/dist/modules/constraints/valid.js +1 -1
  13. package/dist/modules/data/buildmap.js +1 -1
  14. package/dist/modules/data/datasource/namespace.js +1 -1
  15. package/dist/modules/data/datasource/restapi/writeerror.js +1 -1
  16. package/dist/modules/data/datasource/restapi.js +1 -1
  17. package/dist/modules/data/datasource/storage/localstorage.js +1 -1
  18. package/dist/modules/data/datasource/storage/namespace.js +1 -1
  19. package/dist/modules/data/datasource/storage/sessionstorage.js +1 -1
  20. package/dist/modules/data/datasource/storage.js +1 -1
  21. package/dist/modules/data/datasource.js +1 -1
  22. package/dist/modules/data/diff.js +1 -1
  23. package/dist/modules/data/extend.js +1 -1
  24. package/dist/modules/data/namespace.js +1 -1
  25. package/dist/modules/data/pathfinder.js +1 -1
  26. package/dist/modules/data/pipe.js +1 -1
  27. package/dist/modules/data/transformer.js +2 -2
  28. package/dist/modules/dom/assembler.js +1 -1
  29. package/dist/modules/dom/attributes.js +1 -1
  30. package/dist/modules/dom/constants.js +2 -2
  31. package/dist/modules/dom/customcontrol.js +1 -1
  32. package/dist/modules/dom/customelement.js +1 -1
  33. package/dist/modules/dom/events.js +1 -1
  34. package/dist/modules/dom/focusmanager.js +2 -0
  35. package/dist/modules/dom/locale.js +1 -1
  36. package/dist/modules/dom/namespace.js +1 -1
  37. package/dist/modules/dom/resource/data.js +2 -0
  38. package/dist/modules/dom/resource/link/stylesheet.js +2 -0
  39. package/dist/modules/dom/resource/link.js +2 -0
  40. package/dist/modules/dom/resource/script.js +2 -0
  41. package/dist/modules/dom/resource.js +2 -0
  42. package/dist/modules/dom/resourcemanager.js +2 -0
  43. package/dist/modules/dom/template.js +1 -1
  44. package/dist/modules/dom/theme.js +1 -1
  45. package/dist/modules/dom/updater.js +1 -1
  46. package/dist/modules/dom/util.js +1 -1
  47. package/dist/modules/dom/worker/factory.js +2 -0
  48. package/dist/modules/i18n/locale.js +1 -1
  49. package/dist/modules/i18n/namespace.js +1 -1
  50. package/dist/modules/i18n/provider.js +1 -1
  51. package/dist/modules/i18n/providers/fetch.js +1 -1
  52. package/dist/modules/i18n/providers/namespace.js +1 -1
  53. package/dist/modules/i18n/translations.js +1 -1
  54. package/dist/modules/logging/handler/console.js +1 -1
  55. package/dist/modules/logging/handler/namespace.js +1 -1
  56. package/dist/modules/logging/handler.js +1 -1
  57. package/dist/modules/logging/logentry.js +1 -1
  58. package/dist/modules/logging/logger.js +1 -1
  59. package/dist/modules/logging/namespace.js +1 -1
  60. package/dist/modules/math/namespace.js +1 -1
  61. package/dist/modules/math/random.js +2 -2
  62. package/dist/modules/monster.js +1 -1
  63. package/dist/modules/namespace.js +1 -1
  64. package/dist/modules/text/formatter.js +1 -1
  65. package/dist/modules/text/namespace.js +1 -1
  66. package/dist/modules/types/base.js +1 -1
  67. package/dist/modules/types/basewithoptions.js +1 -1
  68. package/dist/modules/types/binary.js +1 -1
  69. package/dist/modules/types/dataurl.js +1 -1
  70. package/dist/modules/types/global.js +1 -1
  71. package/dist/modules/types/id.js +1 -1
  72. package/dist/modules/types/is.js +1 -1
  73. package/dist/modules/types/mediatype.js +1 -1
  74. package/dist/modules/types/namespace.js +1 -1
  75. package/dist/modules/types/observer.js +1 -1
  76. package/dist/modules/types/observerlist.js +1 -1
  77. package/dist/modules/types/proxyobserver.js +1 -1
  78. package/dist/modules/types/queue.js +1 -1
  79. package/dist/modules/types/randomid.js +1 -1
  80. package/dist/modules/types/stack.js +1 -1
  81. package/dist/modules/types/tokenlist.js +1 -1
  82. package/dist/modules/types/typeof.js +1 -1
  83. package/dist/modules/types/uniquequeue.js +1 -1
  84. package/dist/modules/types/uuid.js +2 -0
  85. package/dist/modules/types/validate.js +1 -1
  86. package/dist/modules/types/version.js +2 -2
  87. package/dist/modules/util/clone.js +1 -1
  88. package/dist/modules/util/comparator.js +1 -1
  89. package/dist/modules/util/freeze.js +1 -1
  90. package/dist/modules/util/namespace.js +1 -1
  91. package/dist/modules/util/processing.js +1 -1
  92. package/dist/modules/util/trimspaces.js +1 -1
  93. package/dist/monster.dev.js +549 -249
  94. package/dist/monster.dev.js.map +1 -1
  95. package/dist/monster.js +2 -2
  96. package/package.json +1 -1
  97. package/source/constants.js +11 -2
  98. package/source/constraints/andoperator.js +5 -5
  99. package/source/constraints/invalid.js +3 -3
  100. package/source/constraints/isarray.js +3 -3
  101. package/source/constraints/isobject.js +3 -3
  102. package/source/constraints/oroperator.js +5 -5
  103. package/source/constraints/valid.js +3 -3
  104. package/source/data/buildmap.js +4 -4
  105. package/source/data/datasource/restapi.js +3 -3
  106. package/source/data/datasource/storage/localstorage.js +2 -2
  107. package/source/data/datasource/storage/sessionstorage.js +2 -2
  108. package/source/data/datasource/storage.js +3 -3
  109. package/source/data/datasource.js +3 -3
  110. package/source/data/diff.js +3 -3
  111. package/source/data/extend.js +2 -2
  112. package/source/data/pathfinder.js +4 -4
  113. package/source/data/pipe.js +3 -3
  114. package/source/data/transformer.js +7 -5
  115. package/source/dom/assembler.js +2 -2
  116. package/source/dom/attributes.js +24 -24
  117. package/source/dom/constants.js +278 -9
  118. package/source/dom/customcontrol.js +1 -1
  119. package/source/dom/customelement.js +1 -1
  120. package/source/dom/events.js +4 -4
  121. package/source/dom/focusmanager.js +251 -0
  122. package/source/dom/locale.js +4 -3
  123. package/source/dom/resource/data.js +170 -0
  124. package/source/dom/resource/link/stylesheet.js +54 -0
  125. package/source/dom/resource/link.js +125 -0
  126. package/source/dom/resource/script.js +112 -0
  127. package/source/dom/resource.js +268 -0
  128. package/source/dom/resourcemanager.js +214 -0
  129. package/source/dom/template.js +40 -10
  130. package/source/dom/theme.js +3 -3
  131. package/source/dom/updater.js +7 -7
  132. package/source/dom/util.js +6 -6
  133. package/source/dom/worker/factory.js +134 -0
  134. package/source/i18n/locale.js +4 -4
  135. package/source/i18n/provider.js +2 -2
  136. package/source/i18n/providers/fetch.js +2 -2
  137. package/source/i18n/translations.js +3 -3
  138. package/source/logging/handler/console.js +2 -2
  139. package/source/logging/handler.js +2 -2
  140. package/source/logging/logentry.js +2 -2
  141. package/source/logging/logger.js +2 -2
  142. package/source/math/random.js +9 -5
  143. package/source/namespace.js +1 -1
  144. package/source/text/formatter.js +3 -3
  145. package/source/types/base.js +4 -4
  146. package/source/types/basewithoptions.js +2 -2
  147. package/source/types/binary.js +4 -4
  148. package/source/types/dataurl.js +4 -4
  149. package/source/types/global.js +4 -4
  150. package/source/types/id.js +2 -2
  151. package/source/types/is.js +23 -23
  152. package/source/types/mediatype.js +4 -4
  153. package/source/types/observer.js +3 -3
  154. package/source/types/observerlist.js +2 -2
  155. package/source/types/proxyobserver.js +5 -5
  156. package/source/types/queue.js +3 -3
  157. package/source/types/randomid.js +2 -2
  158. package/source/types/stack.js +2 -2
  159. package/source/types/tokenlist.js +2 -2
  160. package/source/types/typeof.js +3 -3
  161. package/source/types/uniquequeue.js +2 -2
  162. package/source/types/uuid.js +102 -0
  163. package/source/types/validate.js +20 -20
  164. package/source/types/version.js +6 -6
  165. package/source/util/clone.js +2 -2
  166. package/source/util/comparator.js +4 -4
  167. package/source/util/freeze.js +5 -5
  168. package/source/util/processing.js +3 -3
  169. package/source/util/trimspaces.js +3 -3
  170. package/test/cases/data/datasource/restapi.js +1 -1
  171. package/test/cases/data/transformer.js +2 -0
  172. package/test/cases/dom/customelement.js +0 -3
  173. package/test/cases/dom/focusmanager.js +111 -0
  174. package/test/cases/dom/locale.js +1 -4
  175. package/test/cases/dom/resource/data.js +129 -0
  176. package/test/cases/dom/resource/link/stylesheet.js +101 -0
  177. package/test/cases/dom/resource/link.js +101 -0
  178. package/test/cases/dom/resource/script.js +115 -0
  179. package/test/cases/dom/resourcemanager.js +118 -0
  180. package/test/cases/dom/worker/factory.js +63 -0
  181. package/test/cases/monster.js +1 -1
  182. package/test/cases/types/uuid.js +42 -0
  183. package/test/cases/util/freeze.js +30 -4
  184. package/test/util/cleanupdom.js +48 -0
  185. package/test/util/jsdom.js +23 -9
  186. package/test/web/import.js +8 -0
  187. package/test/web/monster-dev.html +3 -3
  188. package/test/web/monster.html +2 -2
  189. package/test/web/test.html +3 -3
  190. package/test/web/tests.js +7 -7
@@ -0,0 +1,101 @@
1
+ 'use strict';
2
+
3
+ import chai from "chai"
4
+ import {Stylesheet} from "../../../../../source/dom/resource/link/stylesheet.js";
5
+ import {DataUrl} from "../../../../../source/types/dataurl.js";
6
+ import {ID} from "../../../../../source/types/id.js";
7
+ import {chaiDom} from "../../../../util/chai-dom.js";
8
+ import {cleanupDOMFromTesting, initMutationObserverForTesting} from "../../../../util/cleanupdom.js";
9
+ import {initJSDOM} from "../../../../util/jsdom.js";
10
+
11
+ let expect = chai.expect;
12
+
13
+ chai.use(chaiDom);
14
+
15
+ let html1 = `
16
+
17
+ `;
18
+
19
+
20
+ describe('Stylesheet', function () {
21
+
22
+ before(function (done) {
23
+ initJSDOM({
24
+ runScripts: "dangerously",
25
+ resources: "usable"
26
+ }).then(() => {
27
+ done()
28
+ });
29
+ });
30
+
31
+ beforeEach(() => {
32
+ initMutationObserverForTesting()
33
+ })
34
+
35
+ afterEach(() => {
36
+ cleanupDOMFromTesting();
37
+ })
38
+
39
+ describe('Stylesheet()', function () {
40
+ it('connect().available()', function (done) {
41
+
42
+ const stylesheet = new Stylesheet({
43
+ href: new DataUrl('', 'text/css').toString(),
44
+ });
45
+
46
+ stylesheet.connect().available().then(() => {
47
+ const id = stylesheet.getOption('id')
48
+ done()
49
+ }).catch(e => done(e));
50
+
51
+ })
52
+ });
53
+
54
+ describe('External Stylesheet', () => {
55
+
56
+ let id = new ID('Stylesheet').toString();
57
+ let stylesheet, url = 'https://monsterjs.org/assets/empty.css?' + id;
58
+
59
+ beforeEach(() => {
60
+
61
+ stylesheet = new Stylesheet({
62
+ href: url,
63
+ id: id,
64
+ });
65
+
66
+ });
67
+
68
+ it('append and remove Stylesheet ', (done) => {
69
+
70
+ expect(stylesheet.isConnected()).to.be.false;
71
+
72
+ stylesheet.connect().available().then(() => {
73
+ expect(stylesheet.isConnected()).to.be.true;
74
+ expect(document.querySelector('[href="' + url + '"]')).to.exist;
75
+
76
+ document.getElementById(id).remove();
77
+ expect(stylesheet.isConnected()).to.be.false;
78
+ expect(document.querySelector('[href="' + url + '"]')).not.to.exist;
79
+
80
+ stylesheet.connect().available().then(() => {
81
+ expect(stylesheet.isConnected()).to.be.true;
82
+ expect(document.querySelector('[href="' + url + '"]')).to.exist;
83
+
84
+ document.getElementById(id).remove();
85
+ expect(document.querySelector('[href="' + url + '"]')).not.to.exist;
86
+ expect(stylesheet.isConnected()).to.be.false;
87
+
88
+ done()
89
+ }).catch(e => done(e));
90
+
91
+
92
+ }).catch(e => done(e));
93
+
94
+
95
+ });
96
+
97
+
98
+ });
99
+
100
+
101
+ });
@@ -0,0 +1,101 @@
1
+ 'use strict';
2
+
3
+ import chai from "chai"
4
+ import {Link} from "../../../../source/dom/resource/link.js";
5
+ import {DataUrl} from "../../../../source/types/dataurl.js";
6
+ import {ID} from "../../../../source/types/id.js";
7
+ import {chaiDom} from "../../../util/chai-dom.js";
8
+ import {cleanupDOMFromTesting, initMutationObserverForTesting} from "../../../util/cleanupdom.js";
9
+ import {initJSDOM} from "../../../util/jsdom.js";
10
+
11
+ let expect = chai.expect;
12
+
13
+ chai.use(chaiDom);
14
+
15
+ let html1 = `
16
+
17
+ `;
18
+
19
+
20
+ describe('Link', function () {
21
+
22
+ let mutationobserver, addedNodes=[];
23
+
24
+ before(function (done) {
25
+ initJSDOM().then(() => {
26
+ done()
27
+ });
28
+ });
29
+
30
+ beforeEach(() => {
31
+ initMutationObserverForTesting()
32
+ })
33
+
34
+ afterEach(() => {
35
+ cleanupDOMFromTesting();
36
+ })
37
+
38
+ describe('Link()', function () {
39
+ it('connect().available()', function (done) {
40
+
41
+ const link = new Link({
42
+ href: new DataUrl('', 'text/css').toString(),
43
+ rel: 'stylesheet'
44
+ });
45
+
46
+ link.connect().available().then(() => {
47
+ done()
48
+ }).catch(e => done(e));
49
+
50
+ })
51
+ });
52
+
53
+ describe('External Link', () => {
54
+
55
+ let id = new ID('link').toString();
56
+ let link, url = 'https://monsterjs.org/assets/empty.css?' + id;
57
+
58
+ beforeEach(() => {
59
+
60
+ link = new Link({
61
+ href: url,
62
+ id: id,
63
+ rel: 'stylesheet'
64
+ });
65
+
66
+ });
67
+
68
+ it('append and remove Link ', (done) => {
69
+
70
+ expect(link.isConnected()).to.be.false;
71
+
72
+ link.connect().available().then(() => {
73
+ expect(link.isConnected()).to.be.true;
74
+ expect(document.querySelector('[href="' + url + '"]')).to.exist;
75
+
76
+ document.getElementById(id).remove();
77
+ expect(link.isConnected()).to.be.false;
78
+ expect(document.querySelector('[href="' + url + '"]')).not.to.exist;
79
+
80
+ link.connect().available().then(() => {
81
+ expect(link.isConnected()).to.be.true;
82
+ expect(document.querySelector('[href="' + url + '"]')).to.exist;
83
+
84
+ document.getElementById(id).remove();
85
+ expect(document.querySelector('[href="' + url + '"]')).not.to.exist;
86
+ expect(link.isConnected()).to.be.false;
87
+
88
+ done()
89
+ }).catch(e => done(e));
90
+
91
+
92
+ }).catch(e => done(e));
93
+
94
+
95
+ });
96
+
97
+
98
+ });
99
+
100
+
101
+ });
@@ -0,0 +1,115 @@
1
+ 'use strict';
2
+
3
+ import chai from "chai"
4
+ import {Script} from "../../../../source/dom/resource/script.js";
5
+ import {DataUrl} from "../../../../source/types/dataurl.js";
6
+ import {ID} from "../../../../source/types/id.js";
7
+ import {chaiDom} from "../../../util/chai-dom.js";
8
+ import {cleanupDOMFromTesting, initMutationObserverForTesting} from "../../../util/cleanupdom.js";
9
+ import {initJSDOM} from "../../../util/jsdom.js";
10
+
11
+ let expect = chai.expect;
12
+
13
+ chai.use(chaiDom);
14
+
15
+ let html1 = `
16
+
17
+ `;
18
+
19
+
20
+ describe('Script', function () {
21
+
22
+ before(function (done) {
23
+ initJSDOM().then(() => {
24
+ done()
25
+ });
26
+ });
27
+
28
+ beforeEach(() => {
29
+ initMutationObserverForTesting()
30
+ })
31
+
32
+ afterEach(() => {
33
+ cleanupDOMFromTesting();
34
+ })
35
+
36
+ describe('Script()', function () {
37
+ it('setEventTypes()', function (done) {
38
+
39
+ const script = new Script({
40
+ src: new DataUrl('', 'text/javascript').toString(),
41
+ async: true,
42
+ crossOrigin: 'anonymous',
43
+ defer: false,
44
+ integrity: undefined,
45
+ nomodule: false,
46
+ nonce: undefined,
47
+ referrerpolicy: undefined,
48
+ type: 'text/javascript'
49
+ });
50
+
51
+ script.connect().available().then(() => {
52
+
53
+ const id = script.getOption('id')
54
+ done()
55
+ }).catch(e => done(e));
56
+
57
+ })
58
+ });
59
+
60
+ describe('External JS', () => {
61
+
62
+ let id = new ID('script').toString();
63
+ let server, script, url = 'https://monsterjs.org/assets/empty.js?' + id;
64
+
65
+ beforeEach(() => {
66
+
67
+ script = new Script({
68
+ src: url,
69
+ async: true,
70
+ crossOrigin: 'anonymous',
71
+ defer: false,
72
+ integrity: undefined,
73
+ nomodule: false,
74
+ nonce: undefined,
75
+ referrerpolicy: undefined,
76
+ type: 'text/javascript',
77
+ id: id
78
+ });
79
+
80
+ });
81
+
82
+ it('append and remove script ', (done) => {
83
+
84
+ expect(script.isConnected()).to.be.false;
85
+
86
+ script.connect().available().then(() => {
87
+ expect(script.isConnected()).to.be.true;
88
+ expect(document.querySelector('[src="' + url + '"]')).to.exist;
89
+
90
+ document.getElementById(id).remove();
91
+ expect(script.isConnected()).to.be.false;
92
+ expect(document.querySelector('[src="' + url + '"]')).not.to.exist;
93
+
94
+ script.connect().available().then(() => {
95
+ expect(script.isConnected()).to.be.true;
96
+ expect(document.querySelector('[src="' + url + '"]')).to.exist;
97
+
98
+ document.getElementById(id).remove();
99
+ expect(document.querySelector('[src="' + url + '"]')).not.to.exist;
100
+ expect(script.isConnected()).to.be.false;
101
+
102
+ done()
103
+ }).catch(e => done(e));
104
+
105
+
106
+ }).catch(e => done(e));
107
+
108
+
109
+ });
110
+
111
+
112
+ });
113
+
114
+
115
+ });
@@ -0,0 +1,118 @@
1
+ 'use strict';
2
+
3
+ import {expect} from "chai"
4
+
5
+ import {ResourceManager} from "../../../source/dom/resourcemanager.js";
6
+ import {cleanupDOMFromTesting, initMutationObserverForTesting} from "../../util/cleanupdom.js";
7
+ import {initJSDOM} from "../../util/jsdom.js";
8
+
9
+ describe('ResourceManager', function () {
10
+
11
+ let fetchReference, returnStatus;
12
+
13
+ before(function (done) {
14
+ initJSDOM().then(() => {
15
+ done()
16
+ }).catch(e => done(e));
17
+ });
18
+
19
+ afterEach(() => {
20
+ global['fetch'] = fetchReference;
21
+ cleanupDOMFromTesting();
22
+ })
23
+
24
+ beforeEach(() => {
25
+
26
+ initMutationObserverForTesting()
27
+
28
+ returnStatus = 200;
29
+ fetchReference = global['fetch'];
30
+ global['fetch'] = function (url, options) {
31
+
32
+ if (!url) throw new Error('missing url')
33
+
34
+ return new Promise((resolve, reject) => {
35
+ resolve({
36
+ text: function () {
37
+ return JSON.stringify({
38
+ a: "test"
39
+ })
40
+ },
41
+ status: returnStatus
42
+ });
43
+ })
44
+
45
+ };
46
+
47
+ })
48
+
49
+ describe('new', function () {
50
+ it('new ResourceManager() should return ResourceManager object', function () {
51
+ let d = new ResourceManager();
52
+ expect(d).to.be.instanceOf(ResourceManager);
53
+ });
54
+ });
55
+
56
+ describe('load resources', function () {
57
+
58
+ let manager;
59
+
60
+ beforeEach(() => {
61
+ manager = new ResourceManager();
62
+ })
63
+
64
+ it('add script should instance of ResourceManager', function () {
65
+ expect(manager.addScript('/example.js')).to.be.instanceOf(ResourceManager);
66
+ });
67
+
68
+ it('add style should instance of ResourceManager', function () {
69
+ expect(manager.addStylesheet('/style.js')).to.be.instanceOf(ResourceManager);
70
+ });
71
+
72
+ it('add data should instance of ResourceManager', function () {
73
+ expect(manager.addData('/data.json')).to.be.instanceOf(ResourceManager);
74
+ });
75
+
76
+ describe('connect resources', function () {
77
+ it('add script and connect should instance of ResourceManager', function () {
78
+ expect(manager.addScript('/example.js').connect()).to.be.instanceOf(ResourceManager);
79
+ });
80
+
81
+ it('add style and connect should instance of ResourceManager', function () {
82
+ expect(manager.addStylesheet('/style.js').connect()).to.be.instanceOf(ResourceManager);
83
+ });
84
+
85
+ it('add data and connect should instance of ResourceManager', function () {
86
+ expect(manager.addData('/data.json').connect()).to.be.instanceOf(ResourceManager);
87
+ });
88
+ })
89
+
90
+
91
+ describe('check availability resources', function () {
92
+ it('add script and check availability should return Promise', function () {
93
+ expect(manager.addScript('/example.js').available()).to.be.instanceOf(Promise);
94
+ });
95
+
96
+ it('add style and check availability should should return Promise', function () {
97
+ expect(manager.addStylesheet('/style.js').available()).to.be.instanceOf(Promise);
98
+ });
99
+
100
+ it('add data and check availability should should return Promise', function () {
101
+ expect(manager.addData('/data.json').available()).to.be.instanceOf(Promise);
102
+ });
103
+ })
104
+
105
+ describe('check availability example.json', function () {
106
+ it('add data and check content', function (done) {
107
+ manager.addData('https://example.com/example.json').connect().available().then(r => {
108
+ expect(document.querySelector('html').outerHTML).contains('>{"a":"test"}</script></head>');
109
+ done();
110
+ }).catch(e => done(e));
111
+ });
112
+
113
+ })
114
+
115
+ });
116
+
117
+
118
+ });
@@ -0,0 +1,63 @@
1
+ import {expect} from "chai"
2
+
3
+ import {Factory} from "../../../../source/dom/worker/factory.js";
4
+ import {getGlobal} from "../../../../source/types/global.js";
5
+ import {initJSDOM, isNode} from "../../../util/jsdom.js";
6
+
7
+ const global = getGlobal();
8
+
9
+ describe('Worker', function () {
10
+
11
+ before(function (done) {
12
+
13
+ if (isNode()) {
14
+ Object.defineProperty(global['URL'], 'createObjectURL', {
15
+ writable: true,
16
+ value: () => {
17
+ return "/example.js"
18
+ }
19
+ })
20
+
21
+ global['Worker'] = class {
22
+ terminate() {
23
+
24
+ }
25
+
26
+ onerror() {
27
+
28
+ }
29
+
30
+ onmessage() {
31
+
32
+ }
33
+ }
34
+
35
+ let a = typeof global['Worker'];
36
+ let a1 = typeof Worker;
37
+
38
+ }
39
+
40
+ const jsdom = initJSDOM().then(() => {
41
+ done();
42
+ });
43
+
44
+
45
+ })
46
+
47
+ describe('Factory', function () {
48
+
49
+ it('create worker', function () {
50
+
51
+ const factory = new Factory();
52
+ const worker = factory.createFromScript('console.log("hello world");')
53
+ expect(worker).is.instanceof(Worker);
54
+
55
+ expect(factory.terminate(worker)).is.instanceof(Factory)
56
+
57
+
58
+ });
59
+
60
+ });
61
+
62
+
63
+ });
@@ -9,7 +9,7 @@ describe('Monster', function () {
9
9
  let monsterVersion
10
10
 
11
11
  /**#@+ dont touch, replaced by make with package.json version */
12
- monsterVersion = new Version('1.24.0')
12
+ monsterVersion = new Version('1.25.0')
13
13
  /**#@-*/
14
14
 
15
15
  let m = Monster.getVersion();
@@ -0,0 +1,42 @@
1
+ import * as Crypto from "@peculiar/webcrypto";
2
+ import {expect} from "chai"
3
+ import {UUID} from "../../../source/types/uuid.js";
4
+
5
+ if (!global['crypto']) {
6
+ global['crypto'] = new Crypto.Crypto();
7
+ }
8
+
9
+
10
+ describe('UUID', function () {
11
+
12
+ describe('.toString()', function () {
13
+ let uuid = new UUID()
14
+ let result = uuid.toString();
15
+
16
+ it('should return a string', function () {
17
+ expect(result).is.a('string')
18
+ expect(result.length).is.equal(36)
19
+ });
20
+
21
+ it('test format', function (done) {
22
+
23
+ const regexExp = /^[A-F\d]{8}-[A-F\d]{4}-4[A-F\d]{3}-[89AB][A-F\d]{3}-[A-F\d]{12}$/i;
24
+
25
+ for (let i = 0; i < 2000; i++) {
26
+ const u = new UUID().toString();
27
+ const r = regexExp.test(u);
28
+
29
+ if (r !== true) {
30
+ done('no uuid ' + u + ' => ' + r);
31
+ return;
32
+ }
33
+ }
34
+
35
+ done();
36
+
37
+ });
38
+
39
+ });
40
+
41
+ });
42
+
@@ -10,13 +10,39 @@ describe('deepFreeze', function () {
10
10
 
11
11
  let obj1 = {
12
12
  a: {
13
- b: {}
13
+ b: {
14
+ c:1
15
+ }
14
16
  }
15
17
  };
16
18
 
17
- expect(() => obj1.a.b.c = 1).to.not.throw(TypeError);
18
- const obj2 = deepFreeze(obj1);
19
- expect(() => obj2.a.b.c = 1).to.throw(TypeError);
19
+ let obj2 = {
20
+ a: {
21
+ b: {
22
+ c:2
23
+ }
24
+ }
25
+ };
26
+
27
+ expect(obj2).to.not.eql(obj1)
28
+ obj1.a.b.c = 2;
29
+ expect(obj2).to.eql(obj1);
30
+
31
+ const obj1Freezed = deepFreeze(obj1);
32
+
33
+ expect(obj2).to.eql(obj1Freezed);
34
+
35
+ try {
36
+ // https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze
37
+ // no change to the object, exception depends on mode (strict ES 2015, etc)
38
+ obj1Freezed.a.b.c = 3
39
+ } catch (_) {
40
+
41
+ }
42
+
43
+ expect(obj2).to.eql(obj1Freezed);
44
+
45
+
20
46
  });
21
47
 
22
48
  });
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+
3
+
4
+ let addedNodes, mutationobserver;
5
+
6
+ function init() {
7
+
8
+ addedNodes = [];
9
+ mutationobserver = new MutationObserver(function (mutations) {
10
+ mutations.forEach(function (mutation) {
11
+ if (mutation.type === 'childList' && mutation.removedNodes) {
12
+
13
+ mutation.addedNodes.forEach((n) => {
14
+ if (n instanceof HTMLElement) {
15
+ addedNodes.push(n);
16
+ }
17
+ })
18
+ }
19
+
20
+ });
21
+ });
22
+
23
+
24
+ }
25
+
26
+
27
+ /**
28
+ *
29
+ */
30
+ export function initMutationObserverForTesting() {
31
+
32
+ if (mutationobserver === undefined) {
33
+ init()
34
+ }
35
+
36
+ mutationobserver.observe(document.querySelector('head'), {childList: true});
37
+ }
38
+
39
+ /**
40
+ *
41
+ */
42
+ export function cleanupDOMFromTesting() {
43
+ mutationobserver.disconnect();
44
+
45
+ for (const n of addedNodes) {
46
+ n.remove();
47
+ }
48
+ }