Created
October 25, 2013 21:43
-
-
Save BlackVegetable/7162283 to your computer and use it in GitHub Desktop.
Incomplete test runner port of Jasmine from nodejs to gjs. Line 224 to 228 requires particular investigation as I am unsure of how to port that section at all. When run with the various referenced files in their proper locations, this attempts to run the tests found in ConsoleReporterSpec but all 14 tests fail. The stack trace grows longer with …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/gjs | |
imports.searchPath.unshift('lib/jasmine-core'); | |
imports.searchPath.unshift('src'); | |
imports.searchPath.unshift('src/core'); | |
imports.searchPath.unshift('src/core/matchers') | |
imports.searchPath.unshift('src/consoleJ'); | |
imports.searchPath.unshift('.'); | |
/* | |
var fs = require('fs'); | |
var util = require('util'); | |
var path = require('path'); | |
*/ | |
/* | |
var jasmineRequire = require('../lib/jasmine-core/jasmine.js'); | |
var jasmine = jasmineRequire.core(jasmineRequire); | |
*/ | |
var _jasmineRequire = imports.jasmine; | |
var jasmineRequire = _jasmineRequire.getJasmineRequireObj(_jasmineRequire); | |
var jasmine = jasmineRequire.core(jasmineRequire); | |
/* | |
var consoleFns = require('../src/console/console.js'); | |
extend(jasmineRequire, consoleFns); | |
jasmineRequire.console(jasmineRequire, jasmine); | |
*/ | |
var consoleFuncs = imports.consoleJ; // Had to change name/path -- GJS has "console" as a reserved word. | |
extend(jasmineRequire, consoleFuncs); | |
jasmineRequire.registerConsoleReporter(jasmineRequire, jasmine); // Again with the name change. | |
var env = jasmine.getEnv(); | |
var jasmineInterface = { | |
describe: function(description, specDefinitions) { | |
return env.describe(description, specDefinitions); | |
}, | |
xdescribe: function(description, specDefinitions) { | |
return env.xdescribe(description, specDefinitions); | |
}, | |
it: function(desc, func) { | |
return env.it(desc, func); | |
}, | |
xit: function(desc, func) { | |
return env.xit(desc, func); | |
}, | |
beforeEach: function(beforeEachFunction) { | |
return env.beforeEach(beforeEachFunction); | |
}, | |
afterEach: function(afterEachFunction) { | |
return env.afterEach(afterEachFunction); | |
}, | |
expect: function(actual) { | |
return env.expect(actual); | |
}, | |
spyOn: function(obj, methodName) { | |
return env.spyOn(obj, methodName); | |
}, | |
jsApiReporter: new jasmine.JsApiReporter({ | |
//timer: new jasmine.Timer() | |
// No timer is available yet. | |
}) | |
}; | |
//extend(global, jasmineInterface); | |
extend(window, jasmineInterface); // window is the GJS equivalent of global. | |
function extend(destination, source) { | |
for (var property in source) destination[property] = source[property]; | |
return destination; | |
} | |
jasmine.addCustomEqualityTester = function(tester) { | |
env.addCustomEqualityTester(tester); | |
}; | |
jasmine.addMatchers = function(matchers) { | |
return env.addMatchers(matchers); | |
}; | |
jasmine.clock = function() { | |
return env.clock; | |
}; | |
/* | |
function executeSpecs(specs, done, isVerbose, showColors) { | |
global.jasmine = jasmine; | |
for (var i = 0; i < specs.length; i++) { | |
var filename = specs[i]; | |
require(filename.replace(/\.\w+$/, "")); | |
} | |
var env = jasmine.getEnv(); | |
var consoleReporter = new jasmine.ConsoleReporter({ | |
print: util.print, | |
onComplete: done, | |
showColors: showColors, | |
timer: new jasmine.Timer() | |
}); | |
env.addReporter(consoleReporter); | |
env.execute(); | |
} | |
*/ | |
function executeSpecs() { | |
window.jasmine = jasmine; | |
let testFile = imports.ConsoleReporterSpec; // For testing our test runner, we are hardcoding the spec. | |
var env = jasmine.getEnv(); | |
var consoleReporter = jasmine.ConsoleReporter({ | |
showColors: true, | |
print: this.print // Making sure the builtin print function is used. | |
// We don't have a timer. | |
// onComplete defaults to an empty function, which is fine by us. | |
}); | |
env.addReporter(consoleReporter); | |
env.execute(); | |
}; | |
/* | |
function getFiles(dir, matcher) { | |
var allFiles = []; | |
if (fs.statSync(dir).isFile() && dir.match(matcher)) { | |
allFiles.push(dir); | |
} else { | |
var files = fs.readdirSync(dir); | |
for (var i = 0, len = files.length; i < len; ++i) { | |
var filename = dir + '/' + files[i]; | |
if (fs.statSync(filename).isFile() && filename.match(matcher)) { | |
allFiles.push(filename); | |
} else if (fs.statSync(filename).isDirectory()) { | |
var subfiles = getFiles(filename); | |
subfiles.forEach(function(result) { | |
allFiles.push(result); | |
}); | |
} | |
} | |
} | |
return allFiles; | |
} | |
*/ | |
// We are using hardcoded files for the time being, so we won't use this function. | |
/* | |
function getSpecFiles(dir) { | |
return getFiles(dir, new RegExp("Spec.js$")); | |
} | |
*/ | |
// Likewise | |
/* | |
var j$require = (function() { | |
var exported = {}, | |
j$req; | |
global.getJasmineRequireObj = getJasmineRequireObj; | |
j$req = require(__dirname + "/../src/core/requireCore.js"); | |
extend(j$req, require(__dirname + "/../src/console/requireConsole.js")); | |
var srcFiles = getFiles(__dirname + "/../src/core"); | |
srcFiles.push(__dirname + "/../src/version.js"); | |
srcFiles.push(__dirname + "/../src/console/ConsoleReporter.js"); | |
for (var i = 0; i < srcFiles.length; i++) { | |
require(srcFiles[i]); | |
} | |
extend(j$req, exported); | |
delete global.getJasmineRequireObj; | |
return j$req; | |
function getJasmineRequireObj() { | |
return exported; | |
} | |
}());*/ | |
var j$require = (function() { | |
var exported = {}, | |
j$req; | |
window.getJasmineRequireObj = getJasmineRequireObj; | |
j$req = imports.src.core.requireCore; | |
extend(j$req, imports.src.consoleJ.requireConsole); | |
let srcFiles = ["Any", "base", "CallTracker", "Clock", "DelayedFunctionScheduler", | |
"Env", "ExceptionFormatter", "Expectation", "ExpectationResult", | |
"JsApiReporter", "ObjectContaining", "PrettyPrinter", "QueueRunner", | |
"ReportDispatcher", "requireCore", "Spec", "SpyStrategy", "Suite", | |
"Timer", "util", "matchersUtil", "requireMatchers", "toBeCloseTo", | |
"toBeDefined", "toBeFalsy", "toBeGreaterThan", "toBe", "toBeLessThan", | |
"toBeNaN", "toBeTruthy", "toBeUndefined", "toContain", "toEqual", | |
"toHaveBeenCalled", "toHaveBeenCalledWith", "toMatch", "toThrowError", | |
"toThrow", "version", "ConsoleReporter"]; | |
let outputObjects = []; | |
for (let i = 0; i < srcFiles.length; i++) { | |
eval('outputObjects[' + String(i) + '] = imports.' + srcFiles[i] + ';'); | |
} | |
extend(j$req, exported); | |
delete window.getJasmineRequireObj; | |
return j$req; | |
function getJasmineRequireObj() { | |
return exported; | |
} | |
}()); | |
/* | |
j$ = j$require.core(j$require); | |
j$require.console(j$require, j$); | |
*/ | |
// I don't know what this code does, or how to translate it to GJS. | |
// There seems to be some global witchcraft going on... | |
/* | |
var isVerbose = false; | |
var showColors = true; | |
var perfSuite = false; | |
*/ | |
// Hardcoding in such values for the time being. | |
/* | |
process.argv.forEach(function(arg) { | |
switch (arg) { | |
case '--color': | |
showColors = true; | |
break; | |
case '--noColor': | |
showColors = false; | |
break; | |
case '--verbose': | |
isVerbose = true; | |
break; | |
case '--perf': | |
perfSuite = true; | |
break; | |
} | |
}); | |
*/ | |
// GJS has a different way of handling command line arguments. | |
// Nonetheless, it doesn't matter because we are hardcoding | |
// some values for now. | |
/* | |
let specs = []; | |
if (perfSuite) { | |
specs = getFiles(__dirname + '/performance', new RegExp("test.js$")); | |
} else { | |
var consoleSpecs = getSpecFiles(__dirname + "/console"), | |
coreSpecs = getSpecFiles(__dirname + "/core"), | |
specs = consoleSpecs.concat(coreSpecs); | |
}*/ | |
// We are just using the ConsoleReporterSpec and it is hardcoded. | |
/* | |
executeSpecs(specs, function(passed) { | |
if (passed) { | |
process.exit(0); | |
} else { | |
process.exit(1); | |
} | |
}, isVerbose, showColors); | |
*/ | |
executeSpecs(); // Requires no parameters due to hardcoded values. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is the 14th failing test w\stack trace: