dwf/rva: adding a little bit of suite-ness to make async testing more readable.
This commit is contained in:
parent
29a0e1f519
commit
7a95f3344c
20
jasmine.iws
20
jasmine.iws
|
@ -92,7 +92,7 @@
|
||||||
<file leaf-file-name="bootstrap.js" pinned="false" current="true" current-in-tab="true">
|
<file leaf-file-name="bootstrap.js" pinned="false" current="true" current-in-tab="true">
|
||||||
<entry file="file://$PROJECT_DIR$/test/bootstrap.js">
|
<entry file="file://$PROJECT_DIR$/test/bootstrap.js">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state line="230" column="37" selection-start="6830" selection-end="6830" vertical-scroll-proportion="0.74496645">
|
<state line="239" column="43" selection-start="6804" selection-end="6804" vertical-scroll-proportion="0.28954938">
|
||||||
<folding />
|
<folding />
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
|
@ -110,7 +110,7 @@
|
||||||
<file leaf-file-name="jasmine.js" pinned="false" current="false" current-in-tab="false">
|
<file leaf-file-name="jasmine.js" pinned="false" current="false" current-in-tab="false">
|
||||||
<entry file="file://$PROJECT_DIR$/lib/jasmine.js">
|
<entry file="file://$PROJECT_DIR$/lib/jasmine.js">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state line="63" column="6" selection-start="1593" selection-end="1593" vertical-scroll-proportion="0.40661478">
|
<state line="88" column="0" selection-start="2048" selection-end="2048" vertical-scroll-proportion="0.2422179">
|
||||||
<folding />
|
<folding />
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
|
@ -522,13 +522,6 @@
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
<entry file="file://$PROJECT_DIR$/lib/jasmine.js">
|
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
|
||||||
<state line="63" column="6" selection-start="1593" selection-end="1593" vertical-scroll-proportion="0.40661478">
|
|
||||||
<folding />
|
|
||||||
</state>
|
|
||||||
</provider>
|
|
||||||
</entry>
|
|
||||||
<entry file="file://$PROJECT_DIR$/test/bootstrap.html">
|
<entry file="file://$PROJECT_DIR$/test/bootstrap.html">
|
||||||
<provider editor-type-id="HtmlPreview">
|
<provider editor-type-id="HtmlPreview">
|
||||||
<state />
|
<state />
|
||||||
|
@ -539,9 +532,16 @@
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
|
<entry file="file://$PROJECT_DIR$/lib/jasmine.js">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state line="88" column="0" selection-start="2048" selection-end="2048" vertical-scroll-proportion="0.2422179">
|
||||||
|
<folding />
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
<entry file="file://$PROJECT_DIR$/test/bootstrap.js">
|
<entry file="file://$PROJECT_DIR$/test/bootstrap.js">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state line="230" column="37" selection-start="6830" selection-end="6830" vertical-scroll-proportion="0.74496645">
|
<state line="239" column="43" selection-start="6804" selection-end="6804" vertical-scroll-proportion="0.28954938">
|
||||||
<folding />
|
<folding />
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
|
|
|
@ -83,7 +83,8 @@ var it = function (description) {
|
||||||
description: description,
|
description: description,
|
||||||
queue: [],
|
queue: [],
|
||||||
currentTimeout: 0,
|
currentTimeout: 0,
|
||||||
done: false,
|
finished: false,
|
||||||
|
suite: {next:function() {}},
|
||||||
results: [],
|
results: [],
|
||||||
|
|
||||||
expects_that: function (actual) {
|
expects_that: function (actual) {
|
||||||
|
@ -100,7 +101,7 @@ var it = function (description) {
|
||||||
},
|
},
|
||||||
|
|
||||||
finish: function() {
|
finish: function() {
|
||||||
that.done = true;
|
that.finished = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
execute: function () {
|
execute: function () {
|
||||||
|
@ -150,8 +151,8 @@ var Jasmine = jasmine_init();
|
||||||
/*
|
/*
|
||||||
* TODO:
|
* TODO:
|
||||||
* - add spec or description to results
|
* - add spec or description to results
|
||||||
* - spec.execute needs to wait until the spec is done
|
//* - spec.execute needs to wait until the spec is done
|
||||||
* - an async test will be killed after X ms if not done and then listed as failed with an "async fail" message of some sort
|
//* - an async test will be killed after X ms if not done and then listed as failed with an "async fail" message of some sort
|
||||||
* - Suite to run tests in order, constructed with a function called describe
|
* - Suite to run tests in order, constructed with a function called describe
|
||||||
* - Suite supports before
|
* - Suite supports before
|
||||||
* - Suite supports after
|
* - Suite supports after
|
||||||
|
|
|
@ -54,7 +54,7 @@ var testMatchersComparisons = function () {
|
||||||
reporter.test(expected.should_not_equal(false),
|
reporter.test(expected.should_not_equal(false),
|
||||||
'expects_that(true).should_not_equal(false) retruned false');
|
'expects_that(true).should_not_equal(false) retruned false');
|
||||||
|
|
||||||
expected = new Matchers(true);
|
expected = new Matchers(true);
|
||||||
reporter.test(!(expected.should_not_equal(true)),
|
reporter.test(!(expected.should_not_equal(true)),
|
||||||
'expects_that(true).should_not_equal(false) retruned true');
|
'expects_that(true).should_not_equal(false) retruned true');
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ var testSpecs = function () {
|
||||||
reporter.test((yet_another_spec.results[0].passed == false),
|
reporter.test((yet_another_spec.results[0].passed == false),
|
||||||
"Expectation that failed, passed");
|
"Expectation that failed, passed");
|
||||||
|
|
||||||
var yet_yet_another_spec = it('spec with multiple assertions').runs( function () {
|
var yet_yet_another_spec = it('spec with multiple assertions').runs(function () {
|
||||||
var foo = 'bar';
|
var foo = 'bar';
|
||||||
var baz = 'quux';
|
var baz = 'quux';
|
||||||
|
|
||||||
|
@ -162,78 +162,124 @@ var testAsyncSpecs = function () {
|
||||||
foo = 0;
|
foo = 0;
|
||||||
a_spec = it('spec w/ queued statments').
|
a_spec = it('spec w/ queued statments').
|
||||||
runs(function () {
|
runs(function () {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
foo++
|
foo++
|
||||||
}, 500);
|
}, 500);
|
||||||
}).waits(1000).
|
}).waits(1000).
|
||||||
then(function() {
|
then(function() {
|
||||||
this.expects_that(foo).should_equal(1);
|
this.expects_that(foo).should_equal(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var mockSuite = {
|
||||||
|
next: function() {
|
||||||
|
reporter.test((a_spec.results.length === 1),
|
||||||
|
'Calling waits(): Spec queue did not run all functions');
|
||||||
|
|
||||||
|
reporter.test((a_spec.results[0].passed === true),
|
||||||
|
'Calling waits(): Queued expectation failed');
|
||||||
|
}
|
||||||
|
};
|
||||||
a_spec.execute();
|
a_spec.execute();
|
||||||
setTimeout(function(){
|
waitForDone(a_spec, mockSuite);
|
||||||
reporter.test((a_spec.results.length === 1),
|
|
||||||
'Calling waits(): Spec queue did not run all functions');
|
|
||||||
|
|
||||||
reporter.test((a_spec.results[0].passed === true),
|
var bar = 0;
|
||||||
'Calling waits(): Queued expectation failed');
|
var another_spec = it('spec w/ queued statments').
|
||||||
}, 1250);
|
runs(function () {
|
||||||
|
setTimeout(function() {
|
||||||
setTimeout(function() {
|
bar++;
|
||||||
var bar = 0;
|
}, 250);
|
||||||
var another_spec = it('spec w/ queued statments').
|
}).
|
||||||
runs(function () {
|
waits(500).
|
||||||
setTimeout(function() {
|
then(function () {
|
||||||
bar++;
|
setTimeout(function() {
|
||||||
}, 250);
|
bar++;
|
||||||
}).
|
}, 250);
|
||||||
waits(500).
|
}).
|
||||||
then(function () {
|
waits(1500).
|
||||||
setTimeout(function() {
|
then(function() {
|
||||||
bar++;
|
this.expects_that(bar).should_equal(2);
|
||||||
}, 250);
|
});
|
||||||
}).
|
mockSuite = {
|
||||||
waits(1500).
|
next: function() {
|
||||||
then(function() {
|
|
||||||
this.expects_that(bar).should_equal(2);
|
|
||||||
});
|
|
||||||
|
|
||||||
another_spec.execute();
|
|
||||||
setTimeout(function(){
|
|
||||||
reporter.test((another_spec.queue.length === 3),
|
reporter.test((another_spec.queue.length === 3),
|
||||||
'Calling 2 waits(): Spec queue was less than expected length');
|
'Calling 2 waits(): Spec queue was less than expected length');
|
||||||
reporter.test((another_spec.results.length === 1),
|
reporter.test((another_spec.results.length === 1),
|
||||||
'Calling 2 waits(): Spec queue did not run all functions');
|
'Calling 2 waits(): Spec queue did not run all functions');
|
||||||
reporter.test((another_spec.results[0].passed === true),
|
reporter.test((another_spec.results[0].passed === true),
|
||||||
'Calling 2 waits(): Queued expectation failed');
|
'Calling 2 waits(): Queued expectation failed');
|
||||||
}, 2500);
|
}
|
||||||
}, 1500);
|
};
|
||||||
|
another_spec.execute();
|
||||||
|
waitForDone(another_spec, mockSuite);
|
||||||
|
|
||||||
setTimeout(function() {
|
var baz = 0;
|
||||||
var baz = 0;
|
var yet_another_spec = it('spec w/ async fail').
|
||||||
var yet_another_spec = it('spec w/ async fail').
|
runs(function () {
|
||||||
runs(function () {
|
setTimeout(function() {
|
||||||
setTimeout(function() {
|
baz++;
|
||||||
baz++;
|
}, 250);
|
||||||
}, 250);
|
}).
|
||||||
}).
|
waits(100).
|
||||||
waits(100).
|
then(function() {
|
||||||
then(function() {
|
this.expects_that(baz).should_equal(1);
|
||||||
this.expects_that(baz).should_equal(1);
|
});
|
||||||
});
|
|
||||||
|
mockSuite = {
|
||||||
|
next: function() {
|
||||||
|
|
||||||
yet_another_spec.execute();
|
|
||||||
setTimeout(function(){
|
|
||||||
reporter.test((yet_another_spec.queue.length === 2),
|
reporter.test((yet_another_spec.queue.length === 2),
|
||||||
'Calling 2 waits(): Spec queue was less than expected length');
|
'Calling 2 waits(): Spec queue was less than expected length');
|
||||||
reporter.test((yet_another_spec.results.length === 1),
|
reporter.test((yet_another_spec.results.length === 1),
|
||||||
'Calling 2 waits(): Spec queue did not run all functions');
|
'Calling 2 waits(): Spec queue did not run all functions');
|
||||||
reporter.test((yet_another_spec.results[0].passed === false),
|
reporter.test((yet_another_spec.results[0].passed === false),
|
||||||
'Calling 2 waits(): Queued expectation failed');
|
'Calling 2 waits(): Queued expectation failed');
|
||||||
}, 2500);
|
}
|
||||||
}, 5000);
|
};
|
||||||
|
|
||||||
|
yet_another_spec.execute();
|
||||||
|
waitForDone(yet_another_spec, mockSuite);
|
||||||
|
}
|
||||||
|
|
||||||
|
var testAsyncSpecsWithMockSuite = function () {
|
||||||
|
var bar = 0;
|
||||||
|
var another_spec = it('spec w/ queued statments').
|
||||||
|
runs(function () {
|
||||||
|
setTimeout(function() {
|
||||||
|
bar++;
|
||||||
|
}, 250);
|
||||||
|
}).
|
||||||
|
waits(500).
|
||||||
|
then(function () {
|
||||||
|
setTimeout(function() {
|
||||||
|
bar++;
|
||||||
|
}, 250);
|
||||||
|
}).
|
||||||
|
waits(1500).
|
||||||
|
then(function() {
|
||||||
|
this.expects_that(bar).should_equal(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
var mockSuite = {
|
||||||
|
next: function () {
|
||||||
|
reporter.test((another_spec.queue.length === 3),
|
||||||
|
'Calling 2 waits(): Spec queue was less than expected length');
|
||||||
|
reporter.test((another_spec.results.length === 1),
|
||||||
|
'Calling 2 waits(): Spec queue did not run all functions');
|
||||||
|
reporter.test((another_spec.results[0].passed === true),
|
||||||
|
'Calling 2 waits(): Queued expectation failed');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
another_spec.execute();
|
||||||
|
waitForDone(another_spec, mockSuite);
|
||||||
|
}
|
||||||
|
|
||||||
|
var waitForDone = function(spec, mockSuite) {
|
||||||
|
var id = setInterval(function () {
|
||||||
|
if (spec.finished) {
|
||||||
|
clearInterval(id);
|
||||||
|
mockSuite.next();
|
||||||
|
}
|
||||||
|
}, 150);
|
||||||
}
|
}
|
||||||
|
|
||||||
var runTests = function () {
|
var runTests = function () {
|
||||||
|
@ -243,7 +289,8 @@ var runTests = function () {
|
||||||
testMatchersReporting();
|
testMatchersReporting();
|
||||||
testSpecs();
|
testSpecs();
|
||||||
testAsyncSpecs();
|
testAsyncSpecs();
|
||||||
|
testAsyncSpecsWithMockSuite();
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
$('spinner').hide();
|
$('spinner').hide();
|
||||||
reporter.summary();
|
reporter.summary();
|
||||||
|
|
Loading…
Reference in New Issue