Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function startTest(data) {
// Create a new Mocha test instance with out information
var test = new mocha.Test(data.title, data.pending);
var parent = mochaObjects[data.parent];
if(!parent) {
throw new Error('No parent suite found for test ' + JSON.stringify(data));
}
// Extend with the test properties that are interesting to us
_.extend(test, _.pick(data, testProperties), {
parent: parent
});
// Add to parent suite
parent.addTest(test);
mochaObjects[data.id] = test;
// Emit the event that a test started
if(contracts[Object.keys(contracts)[0]].currentProvider.ganache === true){ // Only runs tests in dev environment
var Mocha = require('mocha');
var mocha = new Mocha();
var testDir = process.cwd() + '/tests'
// Add each .js file to the mocha instance
var files = fs.readdirSync(testDir).filter(function(file){
// Only keep the .js files
return file.substr(-3) === '.js';
})
if(Object.keys(context.parasol.tests).length > 0) {
for (file in context.parasol.tests) {
var suite = Mocha.Suite.create(mocha.suite, file + ": Inline tests");
for (test in context.parasol.tests[file]) {
suite.addTest(new Mocha.Test(test, context.parasol.tests[file][test]))
}
//var runner = new Mocha.Runner(suite);
//runner.run();
}
}
for (var i = 0; i < files.length; i++) {
delete require.cache[require.resolve(path.join(testDir, files[i]))]
mocha.addFile(path.join(testDir, files[i]))
}
// In order to pass contracts to mocha tests
global.web3 = web3;
global.contracts = contracts;
global.address0 = "0x0000000000000000000000000000000000000000";
global.accounts = accounts;
global.assert = require('assert');
"/gagarin/feedback": function (what, data) {
var args = Array.prototype.slice.call(arguments, 0);
var test = new Mocha.Test(data.name);
var err = null;
test.parent = suite;
if (what === 'pass') {
if (!silent) {
runner.emit('pass', test);
}
} else if (what === 'fail') {
err = new Error(data.failureMessage);
err.stack = data.failureStackTrace;
err.actual = data.failureActual;
err.expected = data.failureExpected;
err.showDiff = data.failureShowDiff;
fs.readdirSync(testdir).forEach(function(testfilename) {
if (testfilename.substr(-5) === '.test') {
var testfile = testdir + '/' + testfilename;
var testname = testfilename.slice(0, -5);
var test = new mocha.Test(testname, function(done) {
runTestFile(testfile, done);
});
suite.addTest(test);
}
});
}
googObject.forEach(expectedErrors.errorsByLineNumber, (lineErrors, line) => {
if (fileSuite) {
const lineTest = new Mocha.Test(` line ${lineErrors.line}`, () => {
verifyEslintErrors(lineErrors);
verifyExpectedErrors(lineErrors);
});
fileSuite.addTest(lineTest);
} else {
verifyEslintErrors(lineErrors);
verifyExpectedErrors(lineErrors);
}
});
}
function createRouteTest(route, dataDir) {
const testParams = route.test;
const { shouldSpawnJobs, shouldCreateItems } = testParams;
const responsabilities = getTestResponsabilities(testParams);
const testName = `${route.name} should ${responsabilities.join(' and ')}`;
return new Test(testName, async () => {
const spider = createSpider();
const job = await Queue.createJob(route.key, { query: testParams.query });
const url = route.getUrl(job);
const scraped = await spider.scrape(url, route);
if (dataDir) {
await logScrapedData(scraped, route, dataDir);
await logPageBody(scraped, route, dataDir);
}
if (shouldSpawnJobs && !scraped.jobs.length) {
const errorMsg = 'New crawling jobs were not spawned.';
throw new Error(errorMsg);
}
for (const example of examples.tableBody) {
let exampleSteps = [...child.steps];
const current = {};
for (const index in example.cells) {
const placeholder = fields[index];
const value = example.cells[index].value;
current[placeholder] = value;
exampleSteps = exampleSteps.map((step) => {
step = Object.assign({}, step);
step.text = step.text.replace(`<${placeholder}>`, value);
return step;
});
}
const tags = child.tags.map(t => t.name);
const title = `${child.name} ${JSON.stringify(current)} ${tags.join(' ')}`.trim();
const test = new Test(title, async () => runSteps(addExampleInTable(exampleSteps, current)));
test.tags = suite.tags.concat(tags);
suite.addTest(scenario.test(test));
}
}
continue;
}
const tags = child.tags.map(t => t.name);
const title = `${child.name} ${tags.join(' ')}`.trim();
const test = new Test(title, async () => runSteps(child.steps));
test.tags = suite.tags.concat(tags);
suite.addTest(scenario.test(test));
}
return suite;
};
function repackTest(test) {
test = Object.assign(new Test(test.title || '', () => { }), test);
test.parent = Object.assign(new Suite(test.parent.title), test.parent);
return test;
}
Receiver.prototype.createTest = function createTest(rawTest) {
var test = new Mocha.Test(rawTest.title);
test.parent = this.suite;
test.speed = rawTest.speed;
test.duration = rawTest.duration;
return test;
};
var suite = new mocha.Suite(type, new mocha.Context);
for (var key in this.tests[type]) {
var fn = this.tests[type][key];
switch (key) {
case 'before':
suite.beforeAll(fn.bind(fn, issue.exports));
break;
case 'after':
suite.afterAll(fn.bind(fn, issue.exports));
break;
default:
suite.addTest(new mocha.Test(key, fn.bind(fn, issue.exports)));
}
}
var runner = new mocha.Runner(suite);
var reporter = new mocha.reporters[reporterType](runner);
issue.exports.reporter = reporter;
runner.run(function () {
if (reporter.stats.failures) {
total['failing-' + Repo.typeMap[type]]++;
}
next();
});