forked from Khan/khan-exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise-runner.js
More file actions
63 lines (51 loc) · 1.6 KB
/
exercise-runner.js
File metadata and controls
63 lines (51 loc) · 1.6 KB
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
var Khan = Khan || {};
jQuery.extend(Khan, {
testExercise: function( json ) {
var exerciseName = json.exercise;
var iframe;
var makeProblem;
var testsRemaining = json.problems.length;
module( exerciseName, {
setup: function() {
if ( typeof iframe === "undefined" ) {
iframe = jQuery( "<iframe>" ).hide().appendTo( "body" );
// Wait for the first problem to be made but throw it out
stop();
jQuery( document ).one( "problemLoaded", function( e, mp ) {
makeProblem = mp;
start();
} );
iframe.attr( "src", "../exercises/" + exerciseName + ".html" );
}
},
teardown: function() {
if ( --testsRemaining <= 0 ) {
iframe.remove();
}
}
});
jQuery.each( json.problems, function( index, problem, next ) {
asyncTest( problem.type + " / " + problem.seed, function() {
var iwindow = iframe[0].contentWindow;
var iKhan = iwindow.Khan;
var varCount = 0;
for ( var key in problem.VARS ) {
varCount++;
}
expect( varCount + 2 );
jQuery( document ).one( "problemLoaded", function( e, mp, solution ) {
var VARS = iwindow.jQuery.tmpl.VARS;
for ( var key in problem.VARS ) {
// Removes unserializable properties like functions (e.g., on polynomial objects)
var vark = VARS[key] == null ? VARS[key] : JSON.parse( JSON.stringify( VARS[key] ) );
deepEqual( vark, problem.VARS[key], "var " + key );
}
deepEqual( solution, problem.solution, "solution" );
strictEqual( problem.pass, true, "pass" );
start();
} );
makeProblem( problem.type, problem.seed );
} );
} );
}
});