@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.
- package/CHANGELOG +14 -0
- package/README.md +4 -4
- package/dist/modules/constants.js +2 -2
- package/dist/modules/constraints/abstract.js +1 -1
- package/dist/modules/constraints/abstractoperator.js +1 -1
- package/dist/modules/constraints/andoperator.js +1 -1
- package/dist/modules/constraints/invalid.js +1 -1
- package/dist/modules/constraints/isarray.js +1 -1
- package/dist/modules/constraints/isobject.js +1 -1
- package/dist/modules/constraints/namespace.js +1 -1
- package/dist/modules/constraints/oroperator.js +1 -1
- package/dist/modules/constraints/valid.js +1 -1
- package/dist/modules/data/buildmap.js +1 -1
- package/dist/modules/data/datasource/namespace.js +1 -1
- package/dist/modules/data/datasource/restapi/writeerror.js +1 -1
- package/dist/modules/data/datasource/restapi.js +1 -1
- package/dist/modules/data/datasource/storage/localstorage.js +1 -1
- package/dist/modules/data/datasource/storage/namespace.js +1 -1
- package/dist/modules/data/datasource/storage/sessionstorage.js +1 -1
- package/dist/modules/data/datasource/storage.js +1 -1
- package/dist/modules/data/datasource.js +1 -1
- package/dist/modules/data/diff.js +1 -1
- package/dist/modules/data/extend.js +1 -1
- package/dist/modules/data/namespace.js +1 -1
- package/dist/modules/data/pathfinder.js +1 -1
- package/dist/modules/data/pipe.js +1 -1
- package/dist/modules/data/transformer.js +2 -2
- package/dist/modules/dom/assembler.js +1 -1
- package/dist/modules/dom/attributes.js +1 -1
- package/dist/modules/dom/constants.js +2 -2
- package/dist/modules/dom/customcontrol.js +1 -1
- package/dist/modules/dom/customelement.js +1 -1
- package/dist/modules/dom/events.js +1 -1
- package/dist/modules/dom/focusmanager.js +2 -0
- package/dist/modules/dom/locale.js +1 -1
- package/dist/modules/dom/namespace.js +1 -1
- package/dist/modules/dom/resource/data.js +2 -0
- package/dist/modules/dom/resource/link/stylesheet.js +2 -0
- package/dist/modules/dom/resource/link.js +2 -0
- package/dist/modules/dom/resource/script.js +2 -0
- package/dist/modules/dom/resource.js +2 -0
- package/dist/modules/dom/resourcemanager.js +2 -0
- package/dist/modules/dom/template.js +1 -1
- package/dist/modules/dom/theme.js +1 -1
- package/dist/modules/dom/updater.js +1 -1
- package/dist/modules/dom/util.js +1 -1
- package/dist/modules/dom/worker/factory.js +2 -0
- package/dist/modules/i18n/locale.js +1 -1
- package/dist/modules/i18n/namespace.js +1 -1
- package/dist/modules/i18n/provider.js +1 -1
- package/dist/modules/i18n/providers/fetch.js +1 -1
- package/dist/modules/i18n/providers/namespace.js +1 -1
- package/dist/modules/i18n/translations.js +1 -1
- package/dist/modules/logging/handler/console.js +1 -1
- package/dist/modules/logging/handler/namespace.js +1 -1
- package/dist/modules/logging/handler.js +1 -1
- package/dist/modules/logging/logentry.js +1 -1
- package/dist/modules/logging/logger.js +1 -1
- package/dist/modules/logging/namespace.js +1 -1
- package/dist/modules/math/namespace.js +1 -1
- package/dist/modules/math/random.js +2 -2
- package/dist/modules/monster.js +1 -1
- package/dist/modules/namespace.js +1 -1
- package/dist/modules/text/formatter.js +1 -1
- package/dist/modules/text/namespace.js +1 -1
- package/dist/modules/types/base.js +1 -1
- package/dist/modules/types/basewithoptions.js +1 -1
- package/dist/modules/types/binary.js +1 -1
- package/dist/modules/types/dataurl.js +1 -1
- package/dist/modules/types/global.js +1 -1
- package/dist/modules/types/id.js +1 -1
- package/dist/modules/types/is.js +1 -1
- package/dist/modules/types/mediatype.js +1 -1
- package/dist/modules/types/namespace.js +1 -1
- package/dist/modules/types/observer.js +1 -1
- package/dist/modules/types/observerlist.js +1 -1
- package/dist/modules/types/proxyobserver.js +1 -1
- package/dist/modules/types/queue.js +1 -1
- package/dist/modules/types/randomid.js +1 -1
- package/dist/modules/types/stack.js +1 -1
- package/dist/modules/types/tokenlist.js +1 -1
- package/dist/modules/types/typeof.js +1 -1
- package/dist/modules/types/uniquequeue.js +1 -1
- package/dist/modules/types/uuid.js +2 -0
- package/dist/modules/types/validate.js +1 -1
- package/dist/modules/types/version.js +2 -2
- package/dist/modules/util/clone.js +1 -1
- package/dist/modules/util/comparator.js +1 -1
- package/dist/modules/util/freeze.js +1 -1
- package/dist/modules/util/namespace.js +1 -1
- package/dist/modules/util/processing.js +1 -1
- package/dist/modules/util/trimspaces.js +1 -1
- package/dist/monster.dev.js +549 -249
- package/dist/monster.dev.js.map +1 -1
- package/dist/monster.js +2 -2
- package/package.json +1 -1
- package/source/constants.js +11 -2
- package/source/constraints/andoperator.js +5 -5
- package/source/constraints/invalid.js +3 -3
- package/source/constraints/isarray.js +3 -3
- package/source/constraints/isobject.js +3 -3
- package/source/constraints/oroperator.js +5 -5
- package/source/constraints/valid.js +3 -3
- package/source/data/buildmap.js +4 -4
- package/source/data/datasource/restapi.js +3 -3
- package/source/data/datasource/storage/localstorage.js +2 -2
- package/source/data/datasource/storage/sessionstorage.js +2 -2
- package/source/data/datasource/storage.js +3 -3
- package/source/data/datasource.js +3 -3
- package/source/data/diff.js +3 -3
- package/source/data/extend.js +2 -2
- package/source/data/pathfinder.js +4 -4
- package/source/data/pipe.js +3 -3
- package/source/data/transformer.js +7 -5
- package/source/dom/assembler.js +2 -2
- package/source/dom/attributes.js +24 -24
- package/source/dom/constants.js +278 -9
- package/source/dom/customcontrol.js +1 -1
- package/source/dom/customelement.js +1 -1
- package/source/dom/events.js +4 -4
- package/source/dom/focusmanager.js +251 -0
- package/source/dom/locale.js +4 -3
- package/source/dom/resource/data.js +170 -0
- package/source/dom/resource/link/stylesheet.js +54 -0
- package/source/dom/resource/link.js +125 -0
- package/source/dom/resource/script.js +112 -0
- package/source/dom/resource.js +268 -0
- package/source/dom/resourcemanager.js +214 -0
- package/source/dom/template.js +40 -10
- package/source/dom/theme.js +3 -3
- package/source/dom/updater.js +7 -7
- package/source/dom/util.js +6 -6
- package/source/dom/worker/factory.js +134 -0
- package/source/i18n/locale.js +4 -4
- package/source/i18n/provider.js +2 -2
- package/source/i18n/providers/fetch.js +2 -2
- package/source/i18n/translations.js +3 -3
- package/source/logging/handler/console.js +2 -2
- package/source/logging/handler.js +2 -2
- package/source/logging/logentry.js +2 -2
- package/source/logging/logger.js +2 -2
- package/source/math/random.js +9 -5
- package/source/namespace.js +1 -1
- package/source/text/formatter.js +3 -3
- package/source/types/base.js +4 -4
- package/source/types/basewithoptions.js +2 -2
- package/source/types/binary.js +4 -4
- package/source/types/dataurl.js +4 -4
- package/source/types/global.js +4 -4
- package/source/types/id.js +2 -2
- package/source/types/is.js +23 -23
- package/source/types/mediatype.js +4 -4
- package/source/types/observer.js +3 -3
- package/source/types/observerlist.js +2 -2
- package/source/types/proxyobserver.js +5 -5
- package/source/types/queue.js +3 -3
- package/source/types/randomid.js +2 -2
- package/source/types/stack.js +2 -2
- package/source/types/tokenlist.js +2 -2
- package/source/types/typeof.js +3 -3
- package/source/types/uniquequeue.js +2 -2
- package/source/types/uuid.js +102 -0
- package/source/types/validate.js +20 -20
- package/source/types/version.js +6 -6
- package/source/util/clone.js +2 -2
- package/source/util/comparator.js +4 -4
- package/source/util/freeze.js +5 -5
- package/source/util/processing.js +3 -3
- package/source/util/trimspaces.js +3 -3
- package/test/cases/data/datasource/restapi.js +1 -1
- package/test/cases/data/transformer.js +2 -0
- package/test/cases/dom/customelement.js +0 -3
- package/test/cases/dom/focusmanager.js +111 -0
- package/test/cases/dom/locale.js +1 -4
- package/test/cases/dom/resource/data.js +129 -0
- package/test/cases/dom/resource/link/stylesheet.js +101 -0
- package/test/cases/dom/resource/link.js +101 -0
- package/test/cases/dom/resource/script.js +115 -0
- package/test/cases/dom/resourcemanager.js +118 -0
- package/test/cases/dom/worker/factory.js +63 -0
- package/test/cases/monster.js +1 -1
- package/test/cases/types/uuid.js +42 -0
- package/test/cases/util/freeze.js +30 -4
- package/test/util/cleanupdom.js +48 -0
- package/test/util/jsdom.js +23 -9
- package/test/web/import.js +8 -0
- package/test/web/monster-dev.html +3 -3
- package/test/web/monster.html +2 -2
- package/test/web/test.html +3 -3
- 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
|
+
});
|
package/test/cases/monster.js
CHANGED
@@ -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
|
-
|
18
|
-
|
19
|
-
|
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
|
+
}
|