This repository was archived by the owner on Sep 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpyscriptSpec.js
81 lines (71 loc) · 2.63 KB
/
pyscriptSpec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
It has been a while since I've used Jasmine, so some of these tests are likely
unidiomatic... but it's a start.
TODO: Complete coverage of test suite...
TODO: Read the damn docs to figure out how to do some of the (async-ish) tests
I need to do.
*/
describe("In the PyScript project,", function() {
beforeEach(function() {
pyscript = main();
});
it("main() should return an object representing PyScript ���", function() {
expect(pyscript).toBeDefined();
});
describe("With the PyScript object, returned by main,", function() {
var pyConfigElement = null;
beforeEach(function() {
pyConfigElement = document.createElement("py-config");
pyConfigElement.innerText = '{"runtime": "micropython","mp_memory":65536}';
const body = document.getElementsByTagName('body')[0];
body.appendChild(pyConfigElement);
});
afterEach(function(){
pyConfigElement.remove();
form = null;
});
it("loadConfig should put JSON from the <py-config> tag into config", function() {
let result = undefined;
function checkEvent(e) {
result = e.detail;
};
document.addEventListener("py-configured", checkEvent);
pyscript.start();
expect(result.runtime).toEqual("micropython");
expect(result.mp_memory).toEqual(65536);
});
it("loadConfig should dispatch the py-configured event", function() {
let result = undefined;
function checkEvent(e) {
result = e.detail;
};
document.addEventListener("py-configured", checkEvent);
pyscript.start();
expect(result).toBeDefined()
});
it("splashOn should display the 'PyScript loading...' splash screen, splashOff should remove it", function() {
pyscript.splashOn();
let body = document.getElementsByTagName('body')[0];
expect(body.innerText).toContain('Loading PyScript...');
pyscript.splashOff();
body = document.getElementsByTagName('body')[0];
expect(body.innerText).not.toContain('Loading PyScript...');
});
it("registerPlugin should configure the passed-in plugins, startPlugins should start them", function() {
let configureFlag = false;
let startFlag = false;
const TestPlugin = {
configure: function(config) {
configureFlag = true;
},
start: function(config) {
startFlag = true;
}
}
pyscript.registerPlugin(TestPlugin);
expect(configureFlag).toEqual(true);
pyscript.startPlugins();
expect(startFlag).toEqual(true);
});
});
});