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:
parent
c420c78517
commit
275b83cc52
@ -4,12 +4,12 @@
|
||||
<head>
|
||||
<title>Jasmine Test Runner</title>
|
||||
</head>
|
||||
<script type="text/javascript" src="../spec/lib/json2.js"></script>
|
||||
<script type="text/javascript" src="../lib/jasmine.js"></script>
|
||||
<script type="text/javascript" src="../lib/TrivialReporter.js"></script>
|
||||
<script type="text/javascript" src="json2.js"></script>
|
||||
<script type="text/javascript" src="jasmine.js"></script>
|
||||
<script type="text/javascript" src="TrivialReporter.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
jasmine.include('example.js', true);
|
||||
jasmine.include('example_suite.js', true);
|
||||
</script>
|
||||
|
||||
<style type="text/css">
|
@ -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;
|
||||
};
|
@ -19,8 +19,7 @@
|
||||
<script type="text/javascript" src="../src/Runner.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="../lib/json_reporter.js"></script>
|
||||
<script type="text/javascript" src="lib/mock-timeout.js"></script>
|
||||
<script type="text/javascript" src="../src/mock-timeout.js"></script>
|
||||
|
||||
<script type="text/javascript" src="bootstrap.js"></script>
|
||||
|
||||
|
42
spec/bootstrap.js
vendored
42
spec/bootstrap.js
vendored
@ -129,42 +129,6 @@ var testRunnerFinishCallback = function () {
|
||||
"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 () {
|
||||
document.getElementById('spinner').style.display = "";
|
||||
|
||||
@ -174,15 +138,9 @@ var runTests = function () {
|
||||
runSuite('suites/NestedResultsTest.js');
|
||||
runSuite('suites/ReporterTest.js');
|
||||
runSuite('suites/RunnerTest.js');
|
||||
runSuite('suites/JsonReporterTest.js');
|
||||
runSuite('suites/SpyTest.js');
|
||||
runSuite('suites/ExceptionsTest.js');
|
||||
|
||||
// testResultsAliasing(); // this appears to do nothing.
|
||||
|
||||
// handle blank specs will work later.
|
||||
// testHandlesBlankSpecs();
|
||||
|
||||
reporter.summary();
|
||||
document.getElementById('spinner').style.display = "none";
|
||||
};
|
@ -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);
|
||||
};
|
||||
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user