Skip to content

Commit 62dbbf4

Browse files
committed
Introduced qunit setup extension for future test rewrites
1 parent 4678278 commit 62dbbf4

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

test/qunit_setup.coffee

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
setupFn = -> null
2+
window.setup = (fn) ->
3+
setupFn = fn
4+
window.moreSetup = (fn) ->
5+
origSetup = setupFn
6+
setup ->
7+
origSetup.call(this)
8+
fn.call(this)
9+
window.clearSetup = ->
10+
setup -> null
11+
12+
originalModule = window.module
13+
window.module = (description) ->
14+
clearSetup()
15+
originalModule(description)
16+
17+
originalTest = window.test
18+
window.test = (description, testFn) ->
19+
setupSnapshot = setupFn
20+
originalTest description, ->
21+
context = {}
22+
setupSnapshot.call(context)
23+
testFn.call(context)

test/qunit_setup.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
(function() {
2+
var originalModule, originalTest, setupFn;
3+
setupFn = function() {
4+
return null;
5+
};
6+
window.setup = function(fn) {
7+
return (setupFn = fn);
8+
};
9+
window.moreSetup = function(fn) {
10+
var origSetup;
11+
origSetup = setupFn;
12+
return setup(function() {
13+
origSetup.call(this);
14+
return fn.call(this);
15+
});
16+
};
17+
window.clearSetup = function() {
18+
return setup(function() {
19+
return null;
20+
});
21+
};
22+
originalModule = window.module;
23+
window.module = function(description) {
24+
clearSetup();
25+
return originalModule(description);
26+
};
27+
originalTest = window.test;
28+
window.test = function(description, testFn) {
29+
var setupSnapshot;
30+
setupSnapshot = setupFn;
31+
return originalTest(description, function() {
32+
var context;
33+
context = {};
34+
setupSnapshot.call(context);
35+
return testFn.call(context);
36+
});
37+
};
38+
}).call(this);

0 commit comments

Comments
 (0)