JsApiReporter reports nested suites correctly.

Runner#topLevelSuites() returns only top level suites.
Suite#specs(), Suite#suites(), and Suite#children() return immediate children.
This commit is contained in:
Lee Byrd & Christian Williams
2010-06-22 10:18:22 -07:00
parent c187adc096
commit e30b99e7b3
8 changed files with 191 additions and 100 deletions

View File

@@ -3,55 +3,69 @@ describe('jasmine.jsApiReporter', function() {
describe('results', function () {
var reporter, spec1, spec2, spec3, expectedSpec1Results, expectedSpec2Results;
var env;
var suite, nestedSuite, nestedSpec;
beforeEach(function() {
var env = new jasmine.Env();
env = new jasmine.Env();
env.updateInterval = 0;
var suite = new jasmine.Suite(env);
spec1 = new jasmine.Spec(env, suite, 'spec 1');
spec1.runs(function () {
this.expect(true).toEqual(true);
});
expectedSpec1Results = {
messages: spec1.results().getItems(),
result: "passed"
};
spec2 = new jasmine.Spec(env, suite, 'spec 2');
spec2.runs(function () {
this.expect(true).toEqual(false);
});
expectedSpec2Results = {
messages: spec2.results().getItems(),
result: "failed"
};
spec3 = new jasmine.Spec(env, suite, 'spec 3');
spec3.runs(function () {
this.log('some debug message')
});
suite = env.describe("top-level suite", function() {
spec1 = env.it("spec 1", function() {
this.expect(true).toEqual(true);
spec1.execute();
spec2.execute();
spec3.execute();
});
spec2 = env.it("spec 2", function() {
this.expect(true).toEqual(false);
});
nestedSuite = env.describe("nested suite", function() {
nestedSpec = env.it("nested spec", function() {
expect(true).toEqual(true);
})
});
spec3 = env.it("spec 3", function() {
this.log('some debug message');
});
});
reporter = new jasmine.JsApiReporter();
reporter.reportSpecResults(spec1);
reporter.reportSpecResults(spec2);
reporter.reportSpecResults(spec3);
env.addReporter(reporter);
env.execute();
});
it('resultForSpec() should return the result for the given spec', function () {
xit('resultForSpec() should return the result for the given spec', function () {
expect(reporter.resultsForSpec(spec1.id)).toEqual(expectedSpec1Results);
expect(reporter.resultsForSpec(spec2.id)).toEqual(expectedSpec2Results);
});
it('results() should return a hash of all results, indexed by spec id', function () {
xit('results() should return a hash of all results, indexed by spec id', function () {
expect(reporter.results()[spec1.id]).toEqual(expectedSpec1Results);
expect(reporter.results()[spec2.id]).toEqual(expectedSpec2Results);
});
describe("#summarizeResult_", function() {
it("should return nested suites as children of their parents", function() {
expect(reporter.suites()).toEqual([
{ id: 0, name: 'top-level suite', type: 'suite',
children: [
{ id: 0, name: 'spec 1', type: 'spec', children: [ ] },
{ id: 1, name: 'spec 2', type: 'spec', children: [ ] },
{ id: 1, name: 'nested suite', type: 'suite',
children: [
{ id: 2, name: 'nested spec', type: 'spec', children: [ ] }
]
},
{ id: 3, name: 'spec 3', type: 'spec', children: [ ] }
]
}
]);
});
xdescribe("#summarizeResult_", function() {
it("should summarize a passing result", function() {
var result = reporter.results()[spec1.id];
var summarizedResult = reporter.summarizeResult_(result);