mirror of https://gitee.com/bigwinds/arangodb
Remove jasmine completely
This should not impact the frontend tests as they use a npm-installed copy of jasmine.
This commit is contained in:
parent
bb14ad043d
commit
b3c7cfd11e
|
@ -55,21 +55,6 @@ function runJSUnityTests(tests) {
|
|||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief runs all jasmine tests
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function runJasmineTests(testFiles, options) {
|
||||
var result = true;
|
||||
|
||||
if (testFiles.length > 0) {
|
||||
print('\nRunning Jasmine Tests: ' + testFiles.join(', '));
|
||||
result = require('jasmine').executeTestSuite(testFiles, options);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief runs all mocha tests
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -89,26 +74,18 @@ function runMochaTests(testFiles) {
|
|||
/// @brief runs tests from command-line
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function runCommandLineTests(opts) {
|
||||
function runCommandLineTests() {
|
||||
var result = true,
|
||||
options = opts || {},
|
||||
jasmineReportFormat = options.jasmineReportFormat || 'progress',
|
||||
unitTests = internal.unitTests(),
|
||||
isSpecRegEx = /.+-spec.*\.js/,
|
||||
isJasmineRegEx = /.+-jasmine-spec.*\.js/,
|
||||
isSpec = function (unitTest) {
|
||||
return isSpecRegEx.test(unitTest);
|
||||
},
|
||||
isJasmine = function (unitTest) {
|
||||
return isJasmineRegEx.test(unitTest);
|
||||
},
|
||||
jasmine = _.filter(unitTests, isJasmine),
|
||||
jsUnity = _.reject(unitTests, isSpec),
|
||||
mocha = _.reject(_.filter(unitTests, isSpec), isJasmine);
|
||||
mocha = _.filter(unitTests, isSpec);
|
||||
|
||||
result = (
|
||||
runJSUnityTests(jsUnity)
|
||||
&& runJasmineTests(jasmine, { format: jasmineReportFormat })
|
||||
&& runMochaTests(mocha)
|
||||
);
|
||||
|
||||
|
|
|
@ -1,101 +0,0 @@
|
|||
/*global print */
|
||||
|
||||
/** Jasmine Wrapper
|
||||
*
|
||||
* This file is based upon Jasmine's boot.js,
|
||||
* but adjusted to work with ArangoDB
|
||||
*
|
||||
* jasmine/core: This is an unmodified copy of Jasmine's Standalone Version
|
||||
* jasmine/reporter: A reporter written for ArangoDB
|
||||
*/
|
||||
|
||||
var jasmine = require('jasmine/core'),
|
||||
_ = require('lodash'),
|
||||
fs = require('fs'),
|
||||
Reporter = require('jasmine/reporter').Reporter;
|
||||
|
||||
// tasks = require('@arangodb/tasks');
|
||||
|
||||
jasmine = jasmine.core(jasmine);
|
||||
|
||||
// Works except params, because tasks takes an object of params,
|
||||
// setTimeout an array.
|
||||
jasmine.getGlobal().setTimeout = function (func) {
|
||||
func();
|
||||
// This would be the real implementation, but this will lead to the
|
||||
// task never terminating
|
||||
|
||||
// var timeoutId = (new Date()).toString();
|
||||
|
||||
// tasks.register({
|
||||
// id: timeoutId,
|
||||
// offset: delay,
|
||||
// command: func
|
||||
// });
|
||||
|
||||
// return timeoutId;
|
||||
};
|
||||
|
||||
jasmine.getGlobal().clearTimeout = function (timeoutId) {
|
||||
// tasks.unregister(timeoutId);
|
||||
};
|
||||
|
||||
exports.executeTestSuite = function (specFileNames, options) {
|
||||
'use strict';
|
||||
var sandbox = new jasmine.Env(),
|
||||
format = options.format || 'progress';
|
||||
|
||||
// Explicitly add require
|
||||
sandbox.require = require;
|
||||
sandbox.createSpy = jasmine.createSpy;
|
||||
sandbox.createSpyObj = jasmine.createSpyObj;
|
||||
|
||||
sandbox.catchExceptions(false);
|
||||
|
||||
/**
|
||||
* The `jsApiReporter` also receives spec results, and is used by any environment
|
||||
* that needs to extract the results from JavaScript.
|
||||
*/
|
||||
var jsApiReporter = new jasmine.JsApiReporter({
|
||||
timer: new jasmine.Timer()
|
||||
});
|
||||
|
||||
sandbox.addReporter(jsApiReporter);
|
||||
|
||||
/**
|
||||
* The `arangoReporter` does the reporting to the console
|
||||
*/
|
||||
var arangoReporter = new Reporter({ format: format });
|
||||
sandbox.addReporter(arangoReporter);
|
||||
|
||||
var _ = require('lodash'),
|
||||
internal = require('internal');
|
||||
|
||||
_.each(specFileNames, function (specFileName) {
|
||||
var spec = fs.read(specFileName);
|
||||
var content = "(function (__myenv__) {";
|
||||
var key;
|
||||
|
||||
for (key in sandbox) {
|
||||
if (sandbox.hasOwnProperty(key)) {
|
||||
content += "var " + key + " = __myenv__['" + key + "'];";
|
||||
}
|
||||
}
|
||||
|
||||
content += "delete __myenv__;"
|
||||
+ spec
|
||||
+ "\n});";
|
||||
|
||||
var fun = internal.executeScript(content, undefined, specFileName);
|
||||
|
||||
if (fun === undefined) {
|
||||
throw new Error("execute jasmine script: " + content);
|
||||
}
|
||||
|
||||
fun(sandbox);
|
||||
});
|
||||
|
||||
sandbox.execute();
|
||||
|
||||
return !arangoReporter.hasErrors();
|
||||
};
|
File diff suppressed because it is too large
Load Diff
|
@ -1,205 +0,0 @@
|
|||
/*global print, printf */
|
||||
|
||||
// Reporter
|
||||
// progress [default]: Dots
|
||||
// documentation: Group and example names
|
||||
|
||||
var Reporter,
|
||||
_ = require('lodash'),
|
||||
internal = require('internal'),
|
||||
inspect = internal.inspect,
|
||||
failureColor = internal.COLORS.COLOR_RED,
|
||||
successColor = internal.COLORS.COLOR_GREEN,
|
||||
commentColor = internal.COLORS.COLOR_BLUE,
|
||||
resetColor = internal.COLORS.COLOR_RESET,
|
||||
pendingColor = internal.COLORS.COLOR_YELLOW,
|
||||
p = function (x) { 'use strict'; print(inspect(x)); };
|
||||
|
||||
var repeatString = function (str, num) {
|
||||
'use strict';
|
||||
return new Array(num + 1).join(str);
|
||||
};
|
||||
|
||||
var indenter = function (indentation) {
|
||||
'use strict';
|
||||
return function (str) {
|
||||
return repeatString(" ", indentation) + str;
|
||||
};
|
||||
};
|
||||
|
||||
var indent = function (message, indentation) {
|
||||
'use strict';
|
||||
var lines = message.split("\n");
|
||||
return _.map(lines, indenter(indentation)).join("\n");
|
||||
};
|
||||
|
||||
// "at Function.main (test.js:19:11)"
|
||||
|
||||
var fileInfoPattern = /\(([^:]+):[^)]+\)/;
|
||||
|
||||
var parseFileName = function (stack) {
|
||||
'use strict';
|
||||
var parsedStack = _.last(_.filter(stack.split("\n"), function (line) {
|
||||
return fileInfoPattern.test(line);
|
||||
}));
|
||||
return fileInfoPattern.exec(parsedStack)[1];
|
||||
};
|
||||
|
||||
Reporter = function (options) {
|
||||
'use strict';
|
||||
options = options || {};
|
||||
this.format = options.format || 'progress';
|
||||
this.failures = [];
|
||||
};
|
||||
|
||||
_.extend(Reporter.prototype, {
|
||||
jasmineStarted: function (options) {
|
||||
'use strict';
|
||||
this.totalSpecs = options.totalSpecsDefined || 0;
|
||||
this.failedSpecs = [];
|
||||
this.pendingSpecs = [];
|
||||
this.start = new Date();
|
||||
print();
|
||||
},
|
||||
|
||||
hasErrors: function () {
|
||||
'use strict';
|
||||
return this.failedSpecs.length > 0;
|
||||
},
|
||||
|
||||
jasmineDone: function () {
|
||||
'use strict';
|
||||
if (this.format === 'progress') {
|
||||
print('\n');
|
||||
}
|
||||
if (this.failures.length > 0) {
|
||||
this.printFailureInfo();
|
||||
}
|
||||
if (this.pendingSpecs.length > 0) {
|
||||
this.printPendingInfo();
|
||||
}
|
||||
this.printFooter();
|
||||
if (this.failures.length > 0) {
|
||||
this.printFailedExamples();
|
||||
}
|
||||
print();
|
||||
},
|
||||
|
||||
suiteStarted: function (result) {
|
||||
'use strict';
|
||||
if (this.format === 'documentation') {
|
||||
print(result.description);
|
||||
}
|
||||
},
|
||||
|
||||
suiteDone: function () {
|
||||
'use strict';
|
||||
if (this.format === 'documentation') {
|
||||
print();
|
||||
}
|
||||
},
|
||||
|
||||
specDone: function (result) {
|
||||
'use strict';
|
||||
if (_.isEqual(result.status, 'passed')) {
|
||||
this.pass(result.description);
|
||||
} else if (_.isEqual(result.status, 'pending')) {
|
||||
this.pending(result.description, result);
|
||||
} else {
|
||||
this.fail(result.description, result);
|
||||
}
|
||||
},
|
||||
|
||||
pending: function (testName, result) {
|
||||
'use strict';
|
||||
this.pendingSpecs.push(result);
|
||||
if (this.format === 'progress') {
|
||||
printf("%s", pendingColor + "*" + resetColor);
|
||||
} else if (this.format === 'documentation') {
|
||||
print(pendingColor + " " + testName + " [PENDING]" + resetColor);
|
||||
}
|
||||
},
|
||||
|
||||
pass: function (testName) {
|
||||
'use strict';
|
||||
if (this.format === 'progress') {
|
||||
printf("%s", successColor + "." + resetColor);
|
||||
} else if (this.format === 'documentation') {
|
||||
print(successColor + " " + testName + resetColor);
|
||||
}
|
||||
},
|
||||
|
||||
printFailureMessage: function (testName) {
|
||||
'use strict';
|
||||
if (this.format === 'progress') {
|
||||
printf("%s", failureColor + "F" + resetColor);
|
||||
} else if (this.format === 'documentation') {
|
||||
print(failureColor + " " + testName + " [FAILED]" + resetColor);
|
||||
}
|
||||
},
|
||||
|
||||
fail: function (testName, result) {
|
||||
'use strict';
|
||||
var failedExpectations = result.failedExpectations;
|
||||
this.failedSpecs.push(result.fullName);
|
||||
this.printFailureMessage(testName);
|
||||
_.each(failedExpectations, function (failedExpectation) {
|
||||
this.failures.push({
|
||||
fullName: result.fullName,
|
||||
failedExpectation: failedExpectation,
|
||||
fileName: parseFileName(failedExpectation.stack)
|
||||
});
|
||||
}, this);
|
||||
},
|
||||
|
||||
printFailureInfo: function () {
|
||||
'use strict';
|
||||
print("Failures:\n");
|
||||
_.each(this.failures, function (failure, index) {
|
||||
var failedExpectation = failure.failedExpectation;
|
||||
|
||||
print(" " + index + ") " + failure.fullName);
|
||||
print(failureColor + indent(failedExpectation.stack, 6) + resetColor);
|
||||
});
|
||||
},
|
||||
|
||||
printPendingInfo: function () {
|
||||
'use strict';
|
||||
print("Pending:\n");
|
||||
_.each(this.pendingSpecs, function (pending) {
|
||||
print(pendingColor + " " + pending.fullName + resetColor);
|
||||
});
|
||||
},
|
||||
|
||||
printFooter: function () {
|
||||
'use strict';
|
||||
var end = new Date(),
|
||||
timeInMilliseconds = end - this.start,
|
||||
color,
|
||||
message = this.totalSpecs + ' example, ' + this.failedSpecs.length + ' failures';
|
||||
|
||||
if (this.failedSpecs.length > 0) {
|
||||
color = failureColor;
|
||||
} else if (this.pendingSpecs.length > 0) {
|
||||
color = pendingColor;
|
||||
message += ', ' + this.pendingSpecs.length + ' pending';
|
||||
} else {
|
||||
color = successColor;
|
||||
}
|
||||
|
||||
print();
|
||||
print('Finished in ' + (timeInMilliseconds / 1000) + ' seconds');
|
||||
print(color + message + resetColor);
|
||||
},
|
||||
|
||||
printFailedExamples: function () {
|
||||
'use strict';
|
||||
print("\nFailed examples:\n");
|
||||
_.each(this.failures, function (failure) {
|
||||
var repeatAction = "arangod --javascript.unit-tests " + failure.fileName + " /tmp/arangodb_test";
|
||||
print(failureColor + repeatAction + commentColor + " # " + failure.fullName + resetColor);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
exports.Reporter = Reporter;
|
|
@ -79,8 +79,6 @@ var optionsDocumentation = [
|
|||
' - `test`: path to single test to execute for "single" test target',
|
||||
' - `cleanup`: if set to true (the default), the cluster data files',
|
||||
' and logs are removed after termination of the test.',
|
||||
' - `jasmineReportFormat`: this option is passed on to the `format`',
|
||||
' option of the Jasmine options object, only for Jasmine tests.',
|
||||
'',
|
||||
' - benchargs : additional commandline arguments to arangob',
|
||||
'',
|
||||
|
@ -489,23 +487,18 @@ function startInstance (protocol, options, addArgs, testname, tmpDir) {
|
|||
function readImportantLogLines(logPath) {
|
||||
var i, j;
|
||||
var importantLines = {};
|
||||
var list=fs.list(logPath);
|
||||
var jasmineTest = fs.join("jasmine", "core");
|
||||
var list = fs.list(logPath);
|
||||
for (i = 0; i < list.length; i++) {
|
||||
var fnLines = [];
|
||||
if (list[i].slice(0,3) === 'log') {
|
||||
var buf = fs.readBuffer(fs.join(logPath,list[i]));
|
||||
if (list[i].slice(0, 3) === 'log') {
|
||||
var buf = fs.readBuffer(fs.join(logPath, list[i]));
|
||||
var lineStart = 0;
|
||||
var maxBuffer = buf.length;
|
||||
for (j = 0; j < maxBuffer; j++) {
|
||||
if (buf[j] === 10) { // \n
|
||||
var line = buf.asciiSlice(lineStart, j);
|
||||
// filter out regular INFO lines, and test related messages
|
||||
if ((line.search(" INFO ") < 0) &&
|
||||
(line.search("WARNING about to execute:") < 0) &&
|
||||
(line.search(jasmineTest) < 0)) {
|
||||
fnLines.push(line);
|
||||
}
|
||||
fnLines.push(line);
|
||||
lineStart = j + 1;
|
||||
}
|
||||
}
|
||||
|
@ -894,20 +887,6 @@ function runThere (options, instanceInfo, file) {
|
|||
t = 'var runTest = require("jsunity").runTest; '+
|
||||
'return runTest(' + JSON.stringify(file) + ', true);';
|
||||
}
|
||||
else if (file.indexOf("-jasmine-spec") !== -1) {
|
||||
var jasmineReportFormat = options.jasmineReportFormat || 'progress';
|
||||
t = 'var executeTestSuite = require("jasmine").executeTestSuite; '+
|
||||
'try {' +
|
||||
'return { status: executeTestSuite([' + JSON.stringify(file) + '], {"format": '+
|
||||
JSON.stringify(jasmineReportFormat) + '}), message: "Success"};'+
|
||||
' } catch (e) {' +
|
||||
'return {' +
|
||||
' status: false,' +
|
||||
' message: e.message || String(e) || "unknown",' +
|
||||
' stack: e.stack' +
|
||||
'};' +
|
||||
'}';
|
||||
}
|
||||
else {
|
||||
t = 'var runTest = require("@arangodb/mocha-runner"); ' +
|
||||
'return runTest(' + JSON.stringify(file) + ', true);';
|
||||
|
@ -939,34 +918,18 @@ function runThere (options, instanceInfo, file) {
|
|||
function runHere (options, instanceInfo, file) {
|
||||
var result;
|
||||
try {
|
||||
if (file.indexOf("-spec") === -1) {
|
||||
var runTest = require("jsunity").runTest;
|
||||
result = runTest(file, true);
|
||||
}
|
||||
else if (file.indexOf("-jasmine-spec") === -1) {
|
||||
var runTest = require("@arangodb/mocha-runner");
|
||||
if (file.indexOf('-spec') === -1) {
|
||||
let runTest = require('jsunity').runTest;
|
||||
result = runTest(file, true);
|
||||
}
|
||||
else {
|
||||
var jasmineReportFormat = options.jasmineReportFormat || 'progress';
|
||||
var executeTestSuite = require("jasmine").executeTestSuite;
|
||||
try {
|
||||
result = executeTestSuite([ file ], { format: jasmineReportFormat });
|
||||
} catch (e) {
|
||||
result = {
|
||||
status: false,
|
||||
message: e.message || String(e) || "unknown",
|
||||
stack: e.stack
|
||||
};
|
||||
return result;
|
||||
}
|
||||
}
|
||||
if (file.indexOf("-spec") !== -1) {
|
||||
result = {
|
||||
status: result,
|
||||
message: ''
|
||||
};
|
||||
let runTest = require('@arangodb/mocha-runner');
|
||||
result = runTest(file, true);
|
||||
}
|
||||
result = {
|
||||
status: result,
|
||||
message: ''
|
||||
};
|
||||
}
|
||||
catch (err) {
|
||||
result = err;
|
||||
|
@ -1021,7 +984,7 @@ function runInArangosh (options, instanceInfo, file, addArgs) {
|
|||
if (addArgs !== undefined) {
|
||||
args = _.extend(args, addArgs);
|
||||
}
|
||||
var arangosh = fs.join("bin","arangosh");
|
||||
var arangosh = fs.join("bin", "arangosh");
|
||||
var result;
|
||||
var rc = executeAndWait(arangosh, toArgv(args));
|
||||
try {
|
||||
|
@ -1030,12 +993,11 @@ function runInArangosh (options, instanceInfo, file, addArgs) {
|
|||
catch(x) {
|
||||
return rc;
|
||||
}
|
||||
if ((typeof(result[0]) === 'object') &&
|
||||
if ((typeof result[0] === 'object') &&
|
||||
result[0].hasOwnProperty('status')) {
|
||||
return result[0];
|
||||
}
|
||||
else {
|
||||
// Jasmine tests...
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue