@jseeio/jsee 0.2.3 → 0.2.7
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/CHANGELOG.md +13 -0
- package/README.md +53 -28
- package/dist/jsee.js +1 -1
- package/dist/jsee.runtime.js +1 -1
- package/dist/worker_bundle.js +1 -0
- package/jest-puppeteer.config.js +12 -0
- package/jest.config.js +7 -0
- package/load/index.html +40 -0
- package/main.js +323 -173
- package/package.json +12 -7
- package/src/app.js +22 -7
- package/src/utils.js +52 -0
- package/src/worker.js +65 -58
- package/templates/bulma-app.vue +76 -7
- package/templates/bulma-output.vue +1 -7
- package/test/code.html +25 -0
- package/test/codew.html +25 -0
- package/test/example-async-function.js +0 -0
- package/test/example-async-init.js +0 -0
- package/test/example-class.js +8 -0
- package/test/example-sum.js +3 -0
- package/test/minimal.html +14 -0
- package/test/minimal1.html +13 -0
- package/test/minimal2.html +15 -0
- package/test/minimal3.html +10 -0
- package/test/minimal4.html +22 -0
- package/test/string.html +26 -0
- package/test/stringw.html +29 -0
- package/test/sum.schema.json +17 -0
- package/test/sumw.schema.json +15 -0
- package/test.js +160 -0
- package/webpack.config.js +5 -1
- package/404.html +0 -22
- package/load.html +0 -31
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"model": {
|
|
3
|
+
"name": "sum",
|
|
4
|
+
"type": "function",
|
|
5
|
+
"container": "args",
|
|
6
|
+
"url": "example-sum.js",
|
|
7
|
+
"autorun": true,
|
|
8
|
+
"worker": true
|
|
9
|
+
},
|
|
10
|
+
"inputs": [
|
|
11
|
+
{ "name": "a", "type": "int", "default": 100 },
|
|
12
|
+
{ "name": "b", "type": "int", "default": 42 }
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
|
package/test.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
require('expect-puppeteer')
|
|
2
|
+
|
|
3
|
+
page.setDefaultTimeout(1000)
|
|
4
|
+
|
|
5
|
+
const port = 8080
|
|
6
|
+
const urlSchema = (name) => `http://localhost:${port}/load/?s=/test/${name}.schema.json`
|
|
7
|
+
const urlHTML = (name) => `http://localhost:${port}/test/${name}.html`
|
|
8
|
+
const urlQuery = (schema) => `http://localhost:${port}/load/?s=${JSON.stringify(schema)}`
|
|
9
|
+
|
|
10
|
+
describe('Initial test', () => {
|
|
11
|
+
beforeAll(async () => {
|
|
12
|
+
await page.goto(urlSchema('sum'))
|
|
13
|
+
})
|
|
14
|
+
test('Title', async () => {
|
|
15
|
+
await expect(page).toMatch('title')
|
|
16
|
+
})
|
|
17
|
+
test('Description', async () => {
|
|
18
|
+
await expect(page).toMatch('description')
|
|
19
|
+
})
|
|
20
|
+
test('Run button is active', async () => {
|
|
21
|
+
await expect(page).toClick('button', { text: 'Run' })
|
|
22
|
+
})
|
|
23
|
+
test('Default result is right', async () => {
|
|
24
|
+
await expect(page).toMatch('142')
|
|
25
|
+
})
|
|
26
|
+
test('Changing inputs', async () => {
|
|
27
|
+
await expect(page).toFill('#a', '200')
|
|
28
|
+
await expect(page).toClick('button', { text: 'Run' })
|
|
29
|
+
await expect(page).toMatch('242')
|
|
30
|
+
// await jestPuppeteer.debug()
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
describe('Initial test (worker)', () => {
|
|
36
|
+
beforeAll(async () => {
|
|
37
|
+
await page.goto(urlSchema('sumw'))
|
|
38
|
+
})
|
|
39
|
+
test('Result is right', async () => {
|
|
40
|
+
await expect(page).toFill('#a', '8')
|
|
41
|
+
await expect(page).toFill('#b', '7')
|
|
42
|
+
await expect(page).toClick('button', { text: 'Run' })
|
|
43
|
+
await expect(page).toMatch('15')
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
describe('Minimal examples', () => {
|
|
48
|
+
const schema = {
|
|
49
|
+
'model': {
|
|
50
|
+
'code': 'function (a, b) { return a / b }', // TODO: check '+'
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
test('Code only (text) (main window)', async () => {
|
|
54
|
+
schema.model.worker = false
|
|
55
|
+
await page.goto(urlQuery(schema))
|
|
56
|
+
await expect(page).toFill('#a', '100')
|
|
57
|
+
await expect(page).toFill('#b', '4')
|
|
58
|
+
await expect(page).toClick('button', { text: 'Run' })
|
|
59
|
+
await expect(page).toMatch('25')
|
|
60
|
+
})
|
|
61
|
+
test('Code instead of schema (function)', async () => {
|
|
62
|
+
await page.goto(urlHTML('minimal1'))
|
|
63
|
+
await expect(page).toFill('#a', '100')
|
|
64
|
+
await expect(page).toFill('#b', '4')
|
|
65
|
+
await expect(page).toClick('button', { text: 'Run' })
|
|
66
|
+
await expect(page).toMatch('400')
|
|
67
|
+
})
|
|
68
|
+
test('Code instead of model (function)', async () => {
|
|
69
|
+
await page.goto(urlHTML('minimal2'))
|
|
70
|
+
await expect(page).toFill('#a', '100')
|
|
71
|
+
await expect(page).toFill('#b', '4')
|
|
72
|
+
await expect(page).toClick('button', { text: 'Run' })
|
|
73
|
+
await expect(page).toMatch('400')
|
|
74
|
+
})
|
|
75
|
+
test('Code instead of schema (anonymous function)', async () => {
|
|
76
|
+
await page.goto(urlHTML('minimal3'))
|
|
77
|
+
await expect(page).toFill('#a', '100')
|
|
78
|
+
await expect(page).toFill('#b', '4')
|
|
79
|
+
await expect(page).toClick('button', { text: 'Run' })
|
|
80
|
+
await expect(page).toMatch('400')
|
|
81
|
+
})
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
describe('Load code directly', () => {
|
|
85
|
+
test('Window', async () => {
|
|
86
|
+
await page.goto(urlHTML('code'))
|
|
87
|
+
await expect(page).toFill('#a', '8')
|
|
88
|
+
await expect(page).toFill('#b', '7')
|
|
89
|
+
await expect(page).toClick('button', { text: 'Run' })
|
|
90
|
+
await expect(page).toMatch('15')
|
|
91
|
+
})
|
|
92
|
+
test('Window (string with eval)', async () => {
|
|
93
|
+
await page.goto(urlHTML('string'))
|
|
94
|
+
await expect(page).toFill('#a', '8')
|
|
95
|
+
await expect(page).toFill('#b', '7')
|
|
96
|
+
await expect(page).toClick('button', { text: 'Run' })
|
|
97
|
+
await expect(page).toMatch('15')
|
|
98
|
+
})
|
|
99
|
+
test('Worker', async () => {
|
|
100
|
+
await page.goto(urlHTML('codew'))
|
|
101
|
+
await expect(page).toFill('#a', '8')
|
|
102
|
+
await expect(page).toFill('#b', '7')
|
|
103
|
+
await expect(page).toClick('button', { text: 'Run' })
|
|
104
|
+
await expect(page).toMatch('15')
|
|
105
|
+
})
|
|
106
|
+
test('Worker (string)', async () => {
|
|
107
|
+
await page.goto(urlHTML('stringw'))
|
|
108
|
+
await expect(page).toFill('#a', '8')
|
|
109
|
+
await expect(page).toFill('#b', '7')
|
|
110
|
+
await expect(page).toClick('button', { text: 'Run' })
|
|
111
|
+
await expect(page).toMatch('15')
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
describe('Classes', () => {
|
|
116
|
+
const schema = {
|
|
117
|
+
'model': {
|
|
118
|
+
'name': 'Doubler',
|
|
119
|
+
'method': 'double',
|
|
120
|
+
'type': 'class',
|
|
121
|
+
'container': 'args',
|
|
122
|
+
'url': '/test/example-class.js',
|
|
123
|
+
},
|
|
124
|
+
'inputs': [
|
|
125
|
+
{ 'name': 'b', 'type': 'int', 'default': 100 }
|
|
126
|
+
]
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
test('Window', async () => {
|
|
130
|
+
schema.model.worker = false
|
|
131
|
+
await page.goto(urlQuery(schema))
|
|
132
|
+
await expect(page).toClick('button', { text: 'Run' })
|
|
133
|
+
await expect(page).toMatch('200')
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
test('Worker', async () => {
|
|
137
|
+
schema.model.worker = true
|
|
138
|
+
await page.goto(urlQuery(schema))
|
|
139
|
+
await expect(page).toClick('button', { text: 'Run' })
|
|
140
|
+
await expect(page).toMatch('200')
|
|
141
|
+
})
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
describe('Some edge cases', () => {
|
|
145
|
+
test('Result is zero', async () => {
|
|
146
|
+
const schema = {
|
|
147
|
+
'model': {
|
|
148
|
+
'code': 'function mul (a, b) { return a * b }',
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
schema.model.worker = false
|
|
152
|
+
await page.goto(urlQuery(schema))
|
|
153
|
+
await expect(page).toFill('#a', '0')
|
|
154
|
+
await expect(page).toFill('#b', '0')
|
|
155
|
+
await expect(page).toClick('button', { text: 'Run' })
|
|
156
|
+
await expect(page).toMatch('Copy')
|
|
157
|
+
})
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
|
package/webpack.config.js
CHANGED
package/404.html
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<title>Port</title>
|
|
6
|
-
<script type="text/javascript">
|
|
7
|
-
var segmentCount = 1;
|
|
8
|
-
|
|
9
|
-
var l = window.location;
|
|
10
|
-
l.replace(
|
|
11
|
-
l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') +
|
|
12
|
-
l.pathname.split('/').slice(0, 1 + segmentCount).join('/') + '/?s=' +
|
|
13
|
-
l.pathname.slice(1).split('/').slice(segmentCount).join('').replace(/&/g, '~and~') +
|
|
14
|
-
(l.search ? '&q=' + l.search.slice(1).replace(/&/g, '~and~') : '') +
|
|
15
|
-
l.hash
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
</script>
|
|
19
|
-
</head>
|
|
20
|
-
<body>
|
|
21
|
-
</body>
|
|
22
|
-
</html>
|
package/load.html
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8" />
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
|
6
|
-
<title>JSEE Schema Loader</title>
|
|
7
|
-
</head>
|
|
8
|
-
<body>
|
|
9
|
-
<div id="jsee-container"></div>
|
|
10
|
-
<div id="txt-container">
|
|
11
|
-
<p>You can use this script for testing purposes. Placing your apps in the <b>apps</b> folder (e.g. <code>./apps/myapp</code> will make it possible to load it with <code>load.html?s=myapp</code> </p>
|
|
12
|
-
</div>
|
|
13
|
-
<script src="dist/jsee.js" type="text/javascript"></script>
|
|
14
|
-
<script>
|
|
15
|
-
var params = new URLSearchParams(window.location.search)
|
|
16
|
-
var schema = params.get('s')
|
|
17
|
-
if (schema) {
|
|
18
|
-
if (typeof schema === 'string') {
|
|
19
|
-
schema = schema.includes('/') ? schema : '/apps/' + schema + '/schema.json'
|
|
20
|
-
}
|
|
21
|
-
const env = new JSEE({
|
|
22
|
-
container: document.getElementById('jsee-container'),
|
|
23
|
-
schema: schema
|
|
24
|
-
})
|
|
25
|
-
} else {
|
|
26
|
-
document.getElementById('port-container').style.display = 'none'
|
|
27
|
-
document.getElementById('txt-container').style.display = 'block'
|
|
28
|
-
}
|
|
29
|
-
</script>
|
|
30
|
-
</body>
|
|
31
|
-
</html>
|