@jseeio/jsee 0.2.8 → 0.3.0
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 -3
- package/README.md +42 -11
- package/dist/jsee.js +1 -1
- package/dist/jsee.runtime.js +1 -1
- package/jest.config.js +1 -0
- package/package.json +28 -25
- package/src/app.js +26 -16
- package/src/main.js +678 -0
- package/src/utils.js +91 -12
- package/src/worker.js +56 -60
- package/templates/bulma-app.vue +32 -7
- package/templates/bulma-input.vue +11 -5
- package/templates/common-inputs.js +3 -0
- package/test/class.html +22 -0
- package/test/importw.html +28 -0
- package/test/minimal.html +1 -1
- package/test/minimal4.html +1 -1
- package/test/pipeline.html +52 -0
- package/test/python.html +41 -0
- package/{test.js → test/test-basic.test.js} +94 -17
- package/test/test-python.test.js +26 -0
- package/webpack.config.js +2 -1
- package/main.js +0 -621
- package/test/example-async-function.js +0 -0
- package/test/example-async-init.js +0 -0
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
require('expect-puppeteer')
|
|
2
2
|
|
|
3
|
-
page.setDefaultTimeout(
|
|
3
|
+
page.setDefaultTimeout(10000)
|
|
4
|
+
|
|
5
|
+
// Tests require a server to be running on port 8080
|
|
6
|
+
// If you have php installed: php -S localhost:8080
|
|
7
|
+
// Python: python -m http.server 8080
|
|
8
|
+
// Node: npm install -g http-server && http-server -p 8080
|
|
4
9
|
|
|
5
10
|
const port = 8080
|
|
6
11
|
const urlSchema = (name) => `http://localhost:${port}/load/?s=/test/${name}.schema.json`
|
|
@@ -12,21 +17,21 @@ describe('Initial test', () => {
|
|
|
12
17
|
await page.goto(urlSchema('sum'))
|
|
13
18
|
})
|
|
14
19
|
test('Title', async () => {
|
|
15
|
-
await expect(page).
|
|
20
|
+
await expect(page).toMatchTextContent('title')
|
|
16
21
|
})
|
|
17
22
|
test('Description', async () => {
|
|
18
|
-
await expect(page).
|
|
23
|
+
await expect(page).toMatchTextContent('description')
|
|
19
24
|
})
|
|
20
25
|
test('Run button is active', async () => {
|
|
21
26
|
await expect(page).toClick('button', { text: 'Run' })
|
|
22
27
|
})
|
|
23
28
|
test('Default result is right', async () => {
|
|
24
|
-
await expect(page).
|
|
29
|
+
await expect(page).toMatchTextContent('142')
|
|
25
30
|
})
|
|
26
31
|
test('Changing inputs', async () => {
|
|
27
32
|
await expect(page).toFill('#a', '200')
|
|
28
33
|
await expect(page).toClick('button', { text: 'Run' })
|
|
29
|
-
await expect(page).
|
|
34
|
+
await expect(page).toMatchTextContent('242')
|
|
30
35
|
// await jestPuppeteer.debug()
|
|
31
36
|
})
|
|
32
37
|
})
|
|
@@ -40,7 +45,7 @@ describe('Initial test (worker)', () => {
|
|
|
40
45
|
await expect(page).toFill('#a', '8')
|
|
41
46
|
await expect(page).toFill('#b', '7')
|
|
42
47
|
await expect(page).toClick('button', { text: 'Run' })
|
|
43
|
-
await expect(page).
|
|
48
|
+
await expect(page).toMatchTextContent('15')
|
|
44
49
|
})
|
|
45
50
|
})
|
|
46
51
|
|
|
@@ -56,28 +61,28 @@ describe('Minimal examples', () => {
|
|
|
56
61
|
await expect(page).toFill('#a', '100')
|
|
57
62
|
await expect(page).toFill('#b', '4')
|
|
58
63
|
await expect(page).toClick('button', { text: 'Run' })
|
|
59
|
-
await expect(page).
|
|
64
|
+
await expect(page).toMatchTextContent('25')
|
|
60
65
|
})
|
|
61
66
|
test('Code instead of schema (function)', async () => {
|
|
62
67
|
await page.goto(urlHTML('minimal1'))
|
|
63
68
|
await expect(page).toFill('#a', '100')
|
|
64
69
|
await expect(page).toFill('#b', '4')
|
|
65
70
|
await expect(page).toClick('button', { text: 'Run' })
|
|
66
|
-
await expect(page).
|
|
71
|
+
await expect(page).toMatchTextContent('400')
|
|
67
72
|
})
|
|
68
73
|
test('Code instead of model (function)', async () => {
|
|
69
74
|
await page.goto(urlHTML('minimal2'))
|
|
70
75
|
await expect(page).toFill('#a', '100')
|
|
71
76
|
await expect(page).toFill('#b', '4')
|
|
72
77
|
await expect(page).toClick('button', { text: 'Run' })
|
|
73
|
-
await expect(page).
|
|
78
|
+
await expect(page).toMatchTextContent('400')
|
|
74
79
|
})
|
|
75
80
|
test('Code instead of schema (anonymous function)', async () => {
|
|
76
81
|
await page.goto(urlHTML('minimal3'))
|
|
77
82
|
await expect(page).toFill('#a', '100')
|
|
78
83
|
await expect(page).toFill('#b', '4')
|
|
79
84
|
await expect(page).toClick('button', { text: 'Run' })
|
|
80
|
-
await expect(page).
|
|
85
|
+
await expect(page).toMatchTextContent('400')
|
|
81
86
|
})
|
|
82
87
|
})
|
|
83
88
|
|
|
@@ -87,28 +92,28 @@ describe('Load code directly', () => {
|
|
|
87
92
|
await expect(page).toFill('#a', '8')
|
|
88
93
|
await expect(page).toFill('#b', '7')
|
|
89
94
|
await expect(page).toClick('button', { text: 'Run' })
|
|
90
|
-
await expect(page).
|
|
95
|
+
await expect(page).toMatchTextContent('15')
|
|
91
96
|
})
|
|
92
97
|
test('Window (string with eval)', async () => {
|
|
93
98
|
await page.goto(urlHTML('string'))
|
|
94
99
|
await expect(page).toFill('#a', '8')
|
|
95
100
|
await expect(page).toFill('#b', '7')
|
|
96
101
|
await expect(page).toClick('button', { text: 'Run' })
|
|
97
|
-
await expect(page).
|
|
102
|
+
await expect(page).toMatchTextContent('15')
|
|
98
103
|
})
|
|
99
104
|
test('Worker', async () => {
|
|
100
105
|
await page.goto(urlHTML('codew'))
|
|
101
106
|
await expect(page).toFill('#a', '8')
|
|
102
107
|
await expect(page).toFill('#b', '7')
|
|
103
108
|
await expect(page).toClick('button', { text: 'Run' })
|
|
104
|
-
await expect(page).
|
|
109
|
+
await expect(page).toMatchTextContent('15')
|
|
105
110
|
})
|
|
106
111
|
test('Worker (string)', async () => {
|
|
107
112
|
await page.goto(urlHTML('stringw'))
|
|
108
113
|
await expect(page).toFill('#a', '8')
|
|
109
114
|
await expect(page).toFill('#b', '7')
|
|
110
115
|
await expect(page).toClick('button', { text: 'Run' })
|
|
111
|
-
await expect(page).
|
|
116
|
+
await expect(page).toMatchTextContent('15')
|
|
112
117
|
})
|
|
113
118
|
})
|
|
114
119
|
|
|
@@ -130,14 +135,14 @@ describe('Classes', () => {
|
|
|
130
135
|
schema.model.worker = false
|
|
131
136
|
await page.goto(urlQuery(schema))
|
|
132
137
|
await expect(page).toClick('button', { text: 'Run' })
|
|
133
|
-
await expect(page).
|
|
138
|
+
await expect(page).toMatchTextContent('200')
|
|
134
139
|
})
|
|
135
140
|
|
|
136
141
|
test('Worker', async () => {
|
|
137
142
|
schema.model.worker = true
|
|
138
143
|
await page.goto(urlQuery(schema))
|
|
139
144
|
await expect(page).toClick('button', { text: 'Run' })
|
|
140
|
-
await expect(page).
|
|
145
|
+
await expect(page).toMatchTextContent('200')
|
|
141
146
|
})
|
|
142
147
|
})
|
|
143
148
|
|
|
@@ -153,8 +158,80 @@ describe('Some edge cases', () => {
|
|
|
153
158
|
await expect(page).toFill('#a', '0')
|
|
154
159
|
await expect(page).toFill('#b', '0')
|
|
155
160
|
await expect(page).toClick('button', { text: 'Run' })
|
|
156
|
-
await expect(page).
|
|
161
|
+
await expect(page).toMatchTextContent('Copy')
|
|
157
162
|
})
|
|
158
163
|
})
|
|
159
164
|
|
|
165
|
+
describe('Imports', () => {
|
|
166
|
+
const schema = {
|
|
167
|
+
'model': {
|
|
168
|
+
'name': 'kebab',
|
|
169
|
+
'type': 'function',
|
|
170
|
+
'container': 'args',
|
|
171
|
+
'code': `
|
|
172
|
+
function kebab (str) {
|
|
173
|
+
return _.kebabCase(str)
|
|
174
|
+
}
|
|
175
|
+
`
|
|
176
|
+
},
|
|
177
|
+
'imports': 'lodash@4.17.21/lodash.min.js',
|
|
178
|
+
'inputs': [
|
|
179
|
+
{ 'name': 'str', 'type': 'string', 'default': 'FooBar' },
|
|
180
|
+
]
|
|
181
|
+
}
|
|
182
|
+
test('Window', async () => {
|
|
183
|
+
schema.model.worker = false
|
|
184
|
+
await page.goto(urlQuery(schema))
|
|
185
|
+
await expect(page).toClick('button', { text: 'Run' })
|
|
186
|
+
await expect(page).toMatchTextContent('foo-bar')
|
|
187
|
+
})
|
|
188
|
+
test('Worker', async () => {
|
|
189
|
+
schema.model.worker = true
|
|
190
|
+
await page.goto(urlQuery(schema))
|
|
191
|
+
await expect(page).toClick('button', { text: 'Run' })
|
|
192
|
+
await expect(page).toMatchTextContent('foo-bar')
|
|
193
|
+
// await (new Promise(resolve => setTimeout(resolve, 1000)))
|
|
194
|
+
})
|
|
195
|
+
})
|
|
160
196
|
|
|
197
|
+
describe('Buttons, button titles and caller', () => {
|
|
198
|
+
const schema = {
|
|
199
|
+
'model': {
|
|
200
|
+
'name': 'callerRepeater',
|
|
201
|
+
'type': 'function',
|
|
202
|
+
'code': `function callerRepeater (inputs) {
|
|
203
|
+
return inputs.caller
|
|
204
|
+
}`
|
|
205
|
+
},
|
|
206
|
+
'inputs': [
|
|
207
|
+
{ 'name': 'test_button', 'type': 'button', 'title': 'Test Button' },
|
|
208
|
+
]
|
|
209
|
+
}
|
|
210
|
+
test('Window', async () => {
|
|
211
|
+
schema.model.worker = false
|
|
212
|
+
await page.goto(urlQuery(schema))
|
|
213
|
+
await expect(page).toMatchTextContent('Test Button')
|
|
214
|
+
await expect(page).toClick('button', { text: 'Test Button' })
|
|
215
|
+
await expect(page).toMatchTextContent('test_button')
|
|
216
|
+
})
|
|
217
|
+
test('Worker', async () => {
|
|
218
|
+
schema.model.worker = true
|
|
219
|
+
await page.goto(urlQuery(schema))
|
|
220
|
+
await expect(page).toClick('button', { text: 'Test Button' })
|
|
221
|
+
await expect(page).toMatchTextContent('test_button')
|
|
222
|
+
})
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
describe('Pipeline', () => {
|
|
226
|
+
test('Multiple models', async () => {
|
|
227
|
+
let a = 3
|
|
228
|
+
let b = 4
|
|
229
|
+
await page.goto(urlHTML('pipeline'))
|
|
230
|
+
await expect(page).toFill('#a', a.toString())
|
|
231
|
+
await expect(page).toFill('#b', b.toString())
|
|
232
|
+
await expect(page).toClick('button', { text: 'Run' })
|
|
233
|
+
await expect(page).toMatchTextContent((Math.pow((a + b), 2) + 1).toString())
|
|
234
|
+
await expect(page).toClick('button', { text: 'Run' })
|
|
235
|
+
await expect(page).toMatchTextContent((Math.pow((a + b), 2) + 2).toString())
|
|
236
|
+
})
|
|
237
|
+
})
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require('expect-puppeteer')
|
|
2
|
+
|
|
3
|
+
page.setDefaultTimeout(30000)
|
|
4
|
+
|
|
5
|
+
// Tests require a server to be running on port 8080
|
|
6
|
+
// If you have php installed: php -S localhost:8080
|
|
7
|
+
// Python: python -m http.server 8080
|
|
8
|
+
// Node: npm install -g http-server && http-server -p 8080
|
|
9
|
+
|
|
10
|
+
const port = 8080
|
|
11
|
+
const urlSchema = (name) => `http://localhost:${port}/load/?s=/test/${name}.schema.json`
|
|
12
|
+
const urlHTML = (name) => `http://localhost:${port}/test/${name}.html`
|
|
13
|
+
const urlQuery = (schema) => `http://localhost:${port}/load/?s=${JSON.stringify(schema)}`
|
|
14
|
+
|
|
15
|
+
describe('Python', () => {
|
|
16
|
+
test('Window', async () => {
|
|
17
|
+
await page.goto(urlHTML('python'))
|
|
18
|
+
// Wait for pyodide to load
|
|
19
|
+
await (new Promise(resolve => setTimeout(resolve, 10000)))
|
|
20
|
+
await expect(page).toFill('#a', '4')
|
|
21
|
+
await expect(page).toFill('#b', '2')
|
|
22
|
+
await expect(page).toClick('button', { text: 'Run' })
|
|
23
|
+
await (new Promise(resolve => setTimeout(resolve, 5000)))
|
|
24
|
+
await expect(page).toMatchTextContent('3')
|
|
25
|
+
})
|
|
26
|
+
})
|
package/webpack.config.js
CHANGED
|
@@ -6,7 +6,7 @@ const package = require('./package.json')
|
|
|
6
6
|
|
|
7
7
|
module.exports = (env) => {
|
|
8
8
|
const config = {
|
|
9
|
-
entry: './main.js',
|
|
9
|
+
entry: './src/main.js',
|
|
10
10
|
output: {
|
|
11
11
|
filename: env.RUNTIME ? 'jsee.runtime.js' : 'jsee.js',
|
|
12
12
|
path: path.resolve(__dirname, 'dist'),
|
|
@@ -16,6 +16,7 @@ module.exports = (env) => {
|
|
|
16
16
|
export: 'default',
|
|
17
17
|
},
|
|
18
18
|
},
|
|
19
|
+
// Define loaders
|
|
19
20
|
module: {
|
|
20
21
|
rules: [
|
|
21
22
|
{
|