-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.test.js
95 lines (89 loc) · 3.46 KB
/
index.test.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { interpretErrorMessage, loadEngine, runCode, setEngine } from './index';
test('interpret skulpt error', () => {
const message = interpretErrorMessage(
`NameError: name 'undefinedvariable' is not defined on line 1`,
'undefinedvariable',
'skulpt'
);
expect(message.code).toBe('undefinedvariable');
expect(message.columnNumber).toBe(null);
expect(message.engine).toBe('skulpt');
expect(message.error).toBe(
"NameError: name 'undefinedvariable' is not defined on line 1"
);
expect(typeof message.getNLinesAbove).toBe('function');
expect(typeof message.getNLinesBelow).toBe('function');
expect(message.line).toBe('undefinedvariable');
expect(message.lineNumber).toBe(1);
expect(message.message).toBe("name 'undefinedvariable' is not defined");
expect(message.type).toBe('NameError');
});
test('interpret pyodide error', () => {
const message = interpretErrorMessage(
{
message: `Traceback (most recent call last):
File "/lib/python3.8/site-packages/pyodide/_base.py", line 344, in eval_code
return CodeRunner(
File "/lib/python3.8/site-packages/pyodide/_base.py", line 242, in run
return eval(last_expr, self.globals, self.locals)
File "<exec>", line 1, in <module>
NameError: name 'undefinedvariable' is not defined
`,
},
'undefinedvariable',
'pyodide'
);
expect(message.code).toBe('undefinedvariable');
expect(message.columnNumber).toBe(null);
expect(message.engine).toBe('pyodide');
expect(message.error.message).toBe(
`Traceback (most recent call last):
File "/lib/python3.8/site-packages/pyodide/_base.py", line 344, in eval_code
return CodeRunner(
File "/lib/python3.8/site-packages/pyodide/_base.py", line 242, in run
return eval(last_expr, self.globals, self.locals)
File "<exec>", line 1, in <module>
NameError: name 'undefinedvariable' is not defined
`
);
expect(typeof message.getNLinesAbove).toBe('function');
expect(typeof message.getNLinesBelow).toBe('function');
expect(message.line).toBe('undefinedvariable');
expect(message.lineNumber).toBe(1);
expect(message.message).toBe("name 'undefinedvariable' is not defined");
expect(message.type).toBe('NameError');
});
test('interpret brython error', () => {
const message = interpretErrorMessage(
`Traceback (most recent call last):
File ./main.py line 1, in <module>
undefinedvariable
NameError: name 'undefinedvariable' is not defined`,
'undefinedvariable',
'brython'
);
expect(message.code).toBe('undefinedvariable');
expect(message.columnNumber).toBe(null);
expect(message.engine).toBe('brython');
expect(message.error).toBe(
`Traceback (most recent call last):
File ./main.py line 1, in <module>
undefinedvariable
NameError: name 'undefinedvariable' is not defined`
);
expect(typeof message.getNLinesAbove).toBe('function');
expect(typeof message.getNLinesBelow).toBe('function');
expect(message.line).toBe('undefinedvariable');
expect(message.lineNumber).toBe(1);
expect(message.message).toBe("name 'undefinedvariable' is not defined");
expect(message.type).toBe('NameError');
});
test('loadEngine on invalid engine should throw an error', () => {
return expect(loadEngine('invalid')).rejects.toThrowError();
});
test('setEngine on invalid engine should throw an error', () => {
return expect(setEngine('invalid')).rejects.toThrowError();
});
test('runCode on invalid engine should throw an error', () => {
return expect(runCode('a=1', { use: 'invalid' })).rejects.toThrowError();
});