Re-arranged files so that lib represents a standalone drop-in of Jasmine. Killed JSON reporter because it has been succeeded by TrivialReporter.js. Using mock-timeout in src for mock-timeout functionality (instead of maintaining two copies

This commit is contained in:
ragaskar 2009-06-24 07:44:40 -07:00
parent c420c78517
commit 275b83cc52
8 changed files with 5 additions and 294 deletions

View File

@ -4,12 +4,12 @@
<head> <head>
<title>Jasmine Test Runner</title> <title>Jasmine Test Runner</title>
</head> </head>
<script type="text/javascript" src="../spec/lib/json2.js"></script> <script type="text/javascript" src="json2.js"></script>
<script type="text/javascript" src="../lib/jasmine.js"></script> <script type="text/javascript" src="jasmine.js"></script>
<script type="text/javascript" src="../lib/TrivialReporter.js"></script> <script type="text/javascript" src="TrivialReporter.js"></script>
<script type="text/javascript"> <script type="text/javascript">
jasmine.include('example.js', true); jasmine.include('example_suite.js', true);
</script> </script>
<style type="text/css"> <style type="text/css">

View File

@ -1,35 +0,0 @@
/*
* jasmine.Reporters.JSON --
* Basic reporter that keeps a JSON string of the most recent Spec, Suite or Runner
* result. Calling application can then do whatever it wants/needs with the string;
*/
jasmine.Reporters.JSON = function () {
var toJSON = function(object){
return JSON.stringify(object);
};
var that = jasmine.Reporters.reporter();
that.specJSON = '';
that.suiteJSON = '';
that.runnerJSON = '';
var saveSpecResults = function (spec) {
that.specJSON = toJSON(spec.getResults());
};
that.reportSpecResults = saveSpecResults;
var saveSuiteResults = function (suite) {
that.suiteJSON = toJSON(suite.getResults());
};
that.reportSuiteResults = saveSuiteResults;
var saveRunnerResults = function (runner) {
that.runnerJSON = toJSON(runner.getResults());
};
that.reportRunnerResults = saveRunnerResults;
this.log = function (str) {
console.log(str);
};
that.toJSON = toJSON;
return that;
};

View File

@ -19,8 +19,7 @@
<script type="text/javascript" src="../src/Runner.js"></script> <script type="text/javascript" src="../src/Runner.js"></script>
<script type="text/javascript" src="../src/Spec.js"></script> <script type="text/javascript" src="../src/Spec.js"></script>
<script type="text/javascript" src="../src/Suite.js"></script> <script type="text/javascript" src="../src/Suite.js"></script>
<script type="text/javascript" src="../lib/json_reporter.js"></script> <script type="text/javascript" src="../src/mock-timeout.js"></script>
<script type="text/javascript" src="lib/mock-timeout.js"></script>
<script type="text/javascript" src="bootstrap.js"></script> <script type="text/javascript" src="bootstrap.js"></script>

42
spec/bootstrap.js vendored
View File

@ -129,42 +129,6 @@ var testRunnerFinishCallback = function () {
"Runner finish callback was not called"); "Runner finish callback was not called");
}; };
var testHandlesBlankSpecs = function () {
var env = newJasmineEnv();
env.describe('Suite for handles blank specs', function () {
env.it('should be a test with a blank runs block', function() {
this.runs(function () {
});
});
env.it('should be a blank (empty function) test', function() {
});
});
var runner = env.currentRunner;
runner.execute();
reporter.test((runner.suites[0].results.getItems().length === 2),
'Should have found 2 spec results, got ' + runner.suites[0].results.getItems().length);
reporter.test((runner.suites[0].results.passedCount === 2),
'Should have found 2 passing specs, got ' + runner.suites[0].results.passedCount);
};
var testResultsAliasing = function () {
var env = newJasmineEnv();
env.describe('Suite for result aliasing test', function () {
env.it('should be a test', function() {
this.runs(function () {
this.expect(true).toEqual(true);
});
});
});
};
var runTests = function () { var runTests = function () {
document.getElementById('spinner').style.display = ""; document.getElementById('spinner').style.display = "";
@ -174,15 +138,9 @@ var runTests = function () {
runSuite('suites/NestedResultsTest.js'); runSuite('suites/NestedResultsTest.js');
runSuite('suites/ReporterTest.js'); runSuite('suites/ReporterTest.js');
runSuite('suites/RunnerTest.js'); runSuite('suites/RunnerTest.js');
runSuite('suites/JsonReporterTest.js');
runSuite('suites/SpyTest.js'); runSuite('suites/SpyTest.js');
runSuite('suites/ExceptionsTest.js'); runSuite('suites/ExceptionsTest.js');
// testResultsAliasing(); // this appears to do nothing.
// handle blank specs will work later.
// testHandlesBlankSpecs();
reporter.summary(); reporter.summary();
document.getElementById('spinner').style.display = "none"; document.getElementById('spinner').style.display = "none";
}; };

View File

@ -1,158 +0,0 @@
// Mock setTimeout, clearTimeout
// Contributed by Pivotal Computer Systems, www.pivotalsf.com
jasmine.FakeTimer = function() {
this.reset();
var self = this;
self.setTimeout = function(funcToCall, millis) {
self.timeoutsMade++;
self.scheduleFunction(self.timeoutsMade, funcToCall, millis, false);
return self.timeoutsMade;
};
self.setInterval = function(funcToCall, millis) {
self.timeoutsMade++;
self.scheduleFunction(self.timeoutsMade, funcToCall, millis, true);
return self.timeoutsMade;
};
self.clearTimeout = function(timeoutKey) {
self.scheduledFunctions[timeoutKey] = undefined;
};
self.clearInterval = function(timeoutKey) {
self.scheduledFunctions[timeoutKey] = undefined;
};
};
jasmine.FakeTimer.prototype.reset = function() {
this.timeoutsMade = 0;
this.scheduledFunctions = {};
this.nowMillis = 0;
};
jasmine.FakeTimer.prototype.tick = function(millis) {
var oldMillis = this.nowMillis;
var newMillis = oldMillis + millis;
this.runFunctionsWithinRange(oldMillis, newMillis);
this.nowMillis = newMillis;
};
jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMillis) {
var scheduledFunc;
var funcsToRun = [];
for (var timeoutKey in this.scheduledFunctions) {
scheduledFunc = this.scheduledFunctions[timeoutKey];
if (scheduledFunc != undefined &&
scheduledFunc.runAtMillis >= oldMillis &&
scheduledFunc.runAtMillis <= nowMillis) {
funcsToRun.push(scheduledFunc);
this.scheduledFunctions[timeoutKey] = undefined;
}
}
if (funcsToRun.length > 0) {
funcsToRun.sort(function(a, b) {
return a.runAtMillis - b.runAtMillis;
});
for (var i = 0; i < funcsToRun.length; ++i) {
try {
var funcToRun = funcsToRun[i];
this.nowMillis = funcToRun.runAtMillis;
funcToRun.funcToCall();
if (funcToRun.recurring) {
this.scheduleFunction(funcToRun.timeoutKey,
funcToRun.funcToCall,
funcToRun.millis,
true);
}
} catch(e) {
}
}
this.runFunctionsWithinRange(oldMillis, nowMillis);
}
};
jasmine.FakeTimer.prototype.scheduleFunction = function(timeoutKey, funcToCall, millis, recurring) {
this.scheduledFunctions[timeoutKey] = {
runAtMillis: this.nowMillis + millis,
funcToCall: funcToCall,
recurring: recurring,
timeoutKey: timeoutKey,
millis: millis
};
};
jasmine.Clock = {
defaultFakeTimer: new jasmine.FakeTimer(),
reset: function() {
jasmine.Clock.assertInstalled();
jasmine.Clock.defaultFakeTimer.reset();
},
tick: function(millis) {
jasmine.Clock.assertInstalled();
jasmine.Clock.defaultFakeTimer.tick(millis);
},
runFunctionsWithinRange: function(oldMillis, nowMillis) {
jasmine.Clock.defaultFakeTimer.runFunctionsWithinRange(oldMillis, nowMillis);
},
scheduleFunction: function(timeoutKey, funcToCall, millis, recurring) {
jasmine.Clock.defaultFakeTimer.scheduleFunction(timeoutKey, funcToCall, millis, recurring);
},
useMock: function() {
var spec = jasmine.getEnv().currentSpec;
spec.after(jasmine.Clock.uninstallMock);
jasmine.Clock.installMock();
},
installMock: function() {
jasmine.Clock.installed = jasmine.Clock.defaultFakeTimer;
},
uninstallMock: function() {
jasmine.Clock.assertInstalled();
jasmine.Clock.installed = jasmine.Clock.real;
},
real: {
setTimeout: window.setTimeout,
clearTimeout: window.clearTimeout,
setInterval: window.setInterval,
clearInterval: window.clearInterval
},
assertInstalled: function() {
if (jasmine.Clock.installed != jasmine.Clock.defaultFakeTimer) {
throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()");
}
},
installed: null
};
jasmine.Clock.installed = jasmine.Clock.real;
window.setTimeout = function(funcToCall, millis) {
return jasmine.Clock.installed.setTimeout.apply(this, arguments);
};
window.setInterval = function(funcToCall, millis) {
return jasmine.Clock.installed.setInterval.apply(this, arguments);
};
window.clearTimeout = function(timeoutKey) {
return jasmine.Clock.installed.clearTimeout.apply(this, arguments);
};
window.clearInterval = function(timeoutKey) {
return jasmine.Clock.installed.clearInterval.apply(this, arguments);
};

View File

@ -1,53 +0,0 @@
describe("jasmine.Reporters.JSON", function () {
var env;
var expectedSpecJSON;
var expectedSuiteJSON;
var expectedRunnerJSON;
beforeEach(function() {
env = new jasmine.Env();
env.describe('Suite for JSON Reporter, NO DOM', function () {
env.it('should be a test', function() {
this.runs(function () {
this.expect(true).toEqual(true);
});
});
});
env.reporter = jasmine.Reporters.JSON();
var runner = env.currentRunner;
runner.execute();
expectedSpecJSON = {
"totalCount":1,"passedCount":1,"failedCount":0,"skipped":false,
"items_":[{"type": 'ExpectationResult', "passed":true,"message":"Passed.", trace: jasmine.any(Object), details: jasmine.any(Object)}],
"description":"should be a test"
};
expectedSuiteJSON = {
"totalCount":1,"passedCount":1,"failedCount":0,"skipped":false, items_:[]
};
expectedRunnerJSON = {
"totalCount":1,"passedCount":1,"failedCount":0,"skipped":false, items_:[]
};
});
it("should report spec results as json", function() {
var specJSON = env.reporter.specJSON;
expect(JSON.parse(specJSON)).toEqual(expectedSpecJSON);
});
it("should report test results as json", function() {
var suiteJSON = env.reporter.suiteJSON;
expect(JSON.parse(suiteJSON)).toEqual(expectedSuiteJSON);
});
it("should report test results as json", function() {
var runnerJSON = env.reporter.runnerJSON;
expect(JSON.parse(runnerJSON)).toEqual(expectedRunnerJSON);
});
});