8000 Test library on a board · arduino/micropython.js@6369a40 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6369a40

Browse files
committed
Test library on a board
1 parent ae37e33 commit 6369a40

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

test.js

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
const Board = require('./micropython.js')
2+
3+
let out
4+
5+
function sleep(millis) {
6+
return new Promise((resolve, reject) => {
7+
setTimeout(() => {
8+
resolve()
9+
}, millis)
10+
})
11+
}
12+
13+
14+
async function main() {
15+
const board = new Board()
16+
await board.open(process.env.PORT || '/dev/ttyACM0')
17+
console.log('connected')
18+
19+
await board.get_prompt()
20+
console.log('has prompt')
21+
22+
const fn = async () => {
23+
let o = await board.serial.read()
24+
console.log('DATA', o.toString())
25+
}
26+
board.serial.on('readable', fn)
27+
await board.eval('pri')
28+
await sleep(10)
29+
await board.eval('nt(1')
30+
await sleep(10)
31+
await board.eval('23)')
32+
await board.eval('\r')
33+
await sleep(10)
34+
board.serial.removeListener('readable', fn)
35+
36+
await board.enter_raw_repl()
37+
console.log('in raw repl')
38+
39+
const code = `from time import sleep\nfor i in range(0, 10):\n print('.')\n sleep(0.1)\n`
40+
let i = 0
41+
out = await board.exec_raw(code, async (d) => {
42+
console.log('->', d)
43+
// i += 1; if (i > 3) await board.stop()
44+
})
45+
console.log('executed', out)
46+
47+
await board.exit_raw_repl()
48+
console.log('out raw repl')
49+
50+
out = await board.fs_exists('boot.py')
51+
console.log('boot.py exists', out)
52+
out = await board.fs_exists('this_is_not_a_file.py')
53+
console.log('nope.py exists', out)
54+
55+
out = await board.fs_ls('./')
56+
console.log('root files', out)
57+
out = await board.fs_ls('./lib')
58+
console.log('lib files', out)
59+
60+
out = await board.fs_ils('./')
61+
console.log('root files', out)
62+
out = await board.fs_ils('./lib')
63+
console.log('lib files', out)
64+
65+
out = await board.fs_put(
66+
'./examples/test.py', 'test.py', (d) => console.log('progress', d)
67+
)
68+
console.log('send file to board', out)
69+
70+
out = await board.fs_cat('test.py')
71+
console.log('get test.py content', out)
72+
73+
out = await board.fs_save(
74+
'# overrides test file', 'test.py', (d) => console.log('progress', d)
75+
)
76+
console.log('save test.py content', out)
77+
78+
out = await board.fs_cat('test.py')
79+
console.log('get test.py content', out)
80+
81+
out = await board.fs_rm('test.py')
82+
console.log('removing test.py', out)
83+
84+
out = await board.fs_mkdir('test_dir')
85+
console.log('created test_dir', out)
86+
out = await board.fs_ils()
87+
console.log('files at ./', out)
88+
89+
out = await board.fs_rmdir('test_dir')
90+
console.log('removed test_dir', out)
91+
out = await board.fs_ils()
92+
console.log('files at ./', out)
93+
94+
board.close()
95+
}
96+
97+
main()

0 commit comments

Comments
 (0)
0