1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-10-31 23:26:18 +00:00

Make test harness exit with a non-zero code when there's test failure (#4889)

* Rename variables to better convey what they're about

* Refactor comments so that they make more sense

* In Node.js, call the wrapper's execute function

The function sets up callbacks necessary for
exiting the process with the appropriate exit code.
https://github.com/jasmine/jasmine-npm/blob/v3.4.0/lib/jasmine.js#L235

* No need to configure the default reporter manually

The .execute() function does it

* Add note on which path comes from which npm package

* Note that other properties of the process object are referenced too
This commit is contained in:
ento 2020-10-18 06:19:52 -08:00 committed by GitHub
parent 41931082e6
commit dbda09b9fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,6 +16,13 @@ var TEST_TIDDLER_FILTER = "[type[application/javascript]tag[$:/tags/test-spec]]"
/* /*
Startup function for running tests Startup function for running tests
Below, paths like jasmine-core/jasmine.js refer to files in the 'jasmine-core' npm
package, whose repository is https://github.com/jasmine/jasmine.
Paths like jasmine/jasmine.js refer to files in the 'jasmine' npm package, whose
repository is https://github.com/jasmine/jasmine-npm.
They're all locally checked into the `./files` directory.
*/ */
exports.startup = function() { exports.startup = function() {
// Set up a shared context object. // Set up a shared context object.
@ -65,37 +72,52 @@ exports.startup = function() {
return context.module.exports || contextExports; return context.module.exports || contextExports;
} }
// Get the core Jasmine exports // Get the core Jasmine exports.
// We load 'jasmine-core/jasmine.js' here in order to start with a module
// that is shared between browser and Node.js environments. Browser-specific
// and Node-specific modules are loaded next.
var jasmineCore = evalInContext("$:/plugins/tiddlywiki/jasmine/jasmine-core/jasmine-core/jasmine.js"); var jasmineCore = evalInContext("$:/plugins/tiddlywiki/jasmine/jasmine-core/jasmine-core/jasmine.js");
// Get the Jasmine instance and configure reporters // The core Jasmine instance
var jasmine; var jasmine;
// Node.js wrapper for calling `.execute()`
var nodeJasmineWrapper;
if($tw.browser) { if($tw.browser) {
window.jasmineRequire = jasmineCore; window.jasmineRequire = jasmineCore;
$tw.modules.execute("$:/plugins/tiddlywiki/jasmine/jasmine-core/jasmine-core/jasmine-html.js"); $tw.modules.execute("$:/plugins/tiddlywiki/jasmine/jasmine-core/jasmine-core/jasmine-html.js");
$tw.modules.execute("$:/plugins/tiddlywiki/jasmine/jasmine-core/jasmine-core/boot.js"); $tw.modules.execute("$:/plugins/tiddlywiki/jasmine/jasmine-core/jasmine-core/boot.js");
jasmine = window.jasmine; jasmine = window.jasmine;
} else { } else {
// We load 'jasmine-core/jasmine.js' above instead of the // Add missing properties to `jasmineCore` in order to call the Jasmine
// main script 'jasmine-core/jasmine-core.js', which is what's loaded // constructor in Node.js.
// when you run `require('jasmine-core')` in a Node.js environment. //
// We load 'jasmine-core/jasmine.js' because we want to factor out // The constructor loads the `jasmineCore` object automatically, if
// code paths that are common between browser and Node.js environments. // not explicitly specified, by calling `require('jasmine-core')`.
// As a result, the `jasmineCore` object is missing some properties that // What happens internally next is...
// 'jasmine/jasmine.js' expects, so we manually populate what we need. //
// 1. require('jasmine-core')
// a. loads the package's main script, 'jasmine-core/jasmine-core.js'
// i. requires 'jasmine-core/jasmine.js'
// ii. reads some extra files and returns a `jasmineCore` object
//
// Because we're in TiddlyWiki land, we really don't need step 1.a.ii.
//
// Since the `jasmineCore` variable already holds the result of 1.a.i,
// we'll add a few properties necessary for calling the Jasmine constructor
// and pass it in explicitly. The consructor function can be seen here:
// https://github.com/jasmine/jasmine-npm/blob/v3.4.0/lib/jasmine.js#L10
// 'jasmine/jasmine.js' calls `.boot()` // 'jasmine/jasmine.js' requires the `.boot()` function
jasmineCore.boot = evalInContext("$:/plugins/tiddlywiki/jasmine/jasmine-core/jasmine-core/node_boot.js"); jasmineCore.boot = evalInContext("$:/plugins/tiddlywiki/jasmine/jasmine-core/jasmine-core/node_boot.js");
// 'jasmine/jasmine.js' references `.files.path` // 'jasmine/jasmine.js' references `.files.path`
jasmineCore.files = { jasmineCore.files = {
path: "$:/plugins/tiddlywiki/jasmine/jasmine-core/jasmine-core" path: "$:/plugins/tiddlywiki/jasmine/jasmine-core/jasmine-core"
}; };
// 'jasmine/jasmine.js' references `process.exit` // 'jasmine/jasmine.js' references `process.exit`, among other properties
context.process = process; context.process = process;
var JasmineNode = evalInContext("$:/plugins/tiddlywiki/jasmine/jasmine/jasmine.js"); var NodeJasmine = evalInContext("$:/plugins/tiddlywiki/jasmine/jasmine/jasmine.js");
var jasmineRunner = new JasmineNode({jasmineCore: jasmineCore}); nodeJasmineWrapper = new NodeJasmine({jasmineCore: jasmineCore});
jasmineRunner.configureDefaultReporter({}); jasmine = nodeJasmineWrapper.jasmine;
jasmine = jasmineRunner.jasmine;
} }
// Add Jasmine's DSL to our context // Add Jasmine's DSL to our context
var env = jasmine.getEnv(); var env = jasmine.getEnv();
@ -109,7 +131,7 @@ exports.startup = function() {
// In a browser environment, jasmine-core/boot.js calls `execute()` for us. // In a browser environment, jasmine-core/boot.js calls `execute()` for us.
// In Node.js, we call it manually. // In Node.js, we call it manually.
if(!$tw.browser) { if(!$tw.browser) {
env.execute(); nodeJasmineWrapper.execute();
} }
}; };