Skip to content

Commit

Permalink
add jasmine 3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
mmanela committed Jan 25, 2020
1 parent 20b7d3d commit c58c764
Show file tree
Hide file tree
Showing 16 changed files with 15,468 additions and 14 deletions.
3 changes: 3 additions & 0 deletions Chutzpah.NoVS.sln
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {370B87B0-118E-4F9A-A13C-8E4A9B222047}
EndGlobalSection
EndGlobal
30 changes: 30 additions & 0 deletions Chutzpah/Chutzpah.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,9 @@
<Content Include="ChutzpahJSRunners\Chrome\jasmineRunnerV2.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ChutzpahJSRunners\Chrome\jasmineRunnerV3.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ChutzpahJSRunners\Chrome\mochaRunner.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand All @@ -397,6 +400,9 @@
<Content Include="ChutzpahJSRunners\jasmineFunctionsV2.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ChutzpahJSRunners\jasmineFunctionsV3.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ChutzpahJSRunners\JsDom\chutzpahRunner.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand All @@ -406,6 +412,9 @@
<Content Include="ChutzpahJSRunners\JsDom\jasmineRunnerV2.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ChutzpahJSRunners\JsDom\jasmineRunnerV3.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ChutzpahJSRunners\JsDom\mochaRunner.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand Down Expand Up @@ -433,6 +442,9 @@
<Content Include="ChutzpahTestHarnessFiles\chutzpah_boot.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ChutzpahTestHarnessFiles\Coverage\blanket_jasmine_v3.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ChutzpahTestHarnessFiles\Coverage\blanket_jasmine_v2.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand Down Expand Up @@ -481,6 +493,24 @@
<Content Include="ChutzpahTestHarnessFiles\Jasmine\v2\jasmine_favicon.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ChutzpahTestHarnessFiles\Jasmine\v3\boot.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ChutzpahTestHarnessFiles\Jasmine\v3\jasmine-html.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ChutzpahTestHarnessFiles\Jasmine\v3\jasmine.css">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ChutzpahTestHarnessFiles\Jasmine\v3\jasmine.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ChutzpahTestHarnessFiles\Jasmine\v3\jasmine.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ChutzpahTestHarnessFiles\Jasmine\v3\jasmine_favicon.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ChutzpahTestHarnessFiles\Mocha\mocha.css">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand Down
22 changes: 22 additions & 0 deletions Chutzpah/ChutzpahJSRunners/Chrome/jasmineRunnerV3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/// <reference path="chutzpahRunner.js" />

(async function () {

const functions = require('../jasmineFunctionsV3.js');
const chutzpahRunner = require('./chutzpahRunner.js');

try {
await chutzpahRunner.runner(
functions.onInitialized,
functions.onPageLoaded,
functions.isJasmineLoaded,
functions.onJasmineLoaded,
functions.isTestingDone);

} catch (e) {
throw new Error("Failed to run jasmineRunnerV3.js: " + e);
}
})().catch(e => {
console.error(e);
process.exit(2);
});
22 changes: 22 additions & 0 deletions Chutzpah/ChutzpahJSRunners/JsDom/jasmineRunnerV3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/// <reference path="chutzpahRunner.js" />

(async function () {

const functions = require('../jasmineFunctionsV3.js');
const chutzpahRunner = require('./chutzpahRunner.js');

try {
await chutzpahRunner.runner(
functions.onInitialized,
functions.onPageLoaded,
functions.isJasmineLoaded,
functions.onJasmineLoaded,
functions.isTestingDone);

} catch (e) {
throw new Error("Failed to run jasmineRunnerV3.js: " + e);
}
})().catch(e => {
console.error(e);
process.exit(2);
});
163 changes: 163 additions & 0 deletions Chutzpah/ChutzpahJSRunners/jasmineFunctionsV3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
var module = module || {};
module.exports = module.exports || {};

function onInitialized() {
console.log("!!_!! onInitialized Jasmine - v3");
}

function isTestingDone() {
console.log("!!_!! isTestingDone");
return window.chutzpah.isTestingFinished === true;
}

function isJasmineLoaded() {
console.log("!!_!! isJasmineLoaded");
return !!window.jasmine && !!window.jasmine.getEnv;
}

function onJasmineLoaded() {

console.log("!!_!! onJasmineLoaded");

function log(obj) {
console.log(JSON.stringify(obj));
}


var activeTestCase = null,
fileStartTime = null,
testStartTime = null,
suites = [];

window.chutzpah.isTestingFinished = false;
window.chutzpah.testCases = [];

function logCoverage() {
if (window._Chutzpah_covobj_name && window[window._Chutzpah_covobj_name]) {
log({ type: "CoverageObject", object: JSON.stringify(window[window._Chutzpah_covobj_name]) });
}
}

function recordStackTrace(stack) {
if (stack) {
// Truncate stack to 5 deep.
stack = stack.split('\n').slice(1, 6).join('\n');
}
return stack;
}


function ChutzpahJasmineReporter(options) {

var passedCount = 0;
var failedCount = 0;
var skippedCount = 0;

this.jasmineStarted = function () {

fileStartTime = new Date().getTime();

// Testing began
log({ type: "FileStart" });
};


this.jasmineDone = function () {
var timetaken = new Date().getTime() - fileStartTime;
logCoverage();
log({ type: "FileDone", timetaken: timetaken, passed: passedCount, failed: failedCount });
window.chutzpah.isTestingFinished = true;
};


this.suiteStarted = function (result) {
suites.push(result);
};

this.suiteDone = function (result) {
suites.pop();
};

this.specStarted = function (result) {
var currentSuiteName = suites.length > 0
? suites[suites.length - 1].fullName
: null;

testStartTime = new Date().getTime();
var suiteName = currentSuiteName;
var specName = result.description;
var newTestCase = { moduleName: suiteName, testName: specName, testResults: [] };
window.chutzpah.testCases.push(newTestCase);
activeTestCase = newTestCase;
log({ type: "TestStart", testCase: activeTestCase });
};

this.specDone = function (result) {
if (result.status === "disabled") {
return;
}

if (result.status === "failed") {
failedCount++;
}
else if (result.status === "pending") {
skippedCount++;
activeTestCase.skipped = true;
}
else {
passedCount++;
}

var timetaken = new Date().getTime() - testStartTime;
activeTestCase.timetaken = timetaken;

for (var i = 0; i < result.failedExpectations.length; i++) {
var expectation = result.failedExpectations[i];

var testResult = {};
testResult.passed = false;
testResult.message = expectation.message;
testResult.stackTrace = recordStackTrace(expectation.stack);
activeTestCase.testResults.push(testResult);

}

// Log test case when done. This will get picked up by phantom and streamed to chutzpah.
log({ type: "TestDone", testCase: activeTestCase });


};

}

if (window.chutzpah.testMode) {
jasmine.getEnv().addReporter(new ChutzpahJasmineReporter());
}

if (window.chutzpah.testMode === 'discovery') {
// If discovery mode overwrite execute to not run the test
jasmine.getEnv().beforeAll = function () { };
jasmine.getEnv().afterAll = function () { };
jasmine.Spec.prototype.execute = function (onComplete) {
this.onStart(this);
this.resultCallback(this.result);
if (onComplete)
onComplete();
};
}

}

function onPageLoaded() {
console.log("!!_!! onPageLoaded");

if (!window.chutzpah.usingModuleLoader && window.chutzpah.autoStart !== false) {
(window.chutzpah.start || window.initializeJasmine)();
}
}

module.exports.onInitialized = onInitialized;
module.exports.isTestingDone = isTestingDone;
module.exports.isJasmineLoaded = isJasmineLoaded;
module.exports.onJasmineLoaded = onJasmineLoaded;
module.exports.onPageLoaded = onPageLoaded;
Loading

0 comments on commit c58c764

Please sign in to comment.