Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function runSuite() {
Object.keys(require.cache).forEach(key => delete require.cache[key])
const mocha = new Mocha({ reporter: 'spec' })
fileList.forEach(filepath => mocha.addFile(filepath))
try {
mocha.run()
if (global.gc) {
global.gc()
}
else {
/* eslint-disable no-console */
console.log('Garbage collection unavailable')
/* eslint-enable no-console */
}
}
catch (e) {
/* eslint-disable no-console */
console.log('------------')
console.log('Failed with Error', e.stack)
export function runMocha(file: string, options: ThreadOptions, debugSubprocess: boolean) {
const channel = new MessageChannel();
const Reporter = getReporterFactory(channel, debugSubprocess);
const mocha = new Mocha();
mocha.addFile(file);
// --compilers
applyCompilers(options.compilers);
// --delay
applyDelay(mocha, options.delay);
// --grep
applyGrepPattern(mocha, options.grep);
// --enableTimeouts
applyNoTimeouts(mocha, options.enableTimeouts);
// --exit
const onComplete = applyExit(channel, options.exitImmediately);
jsdom,
} from 'jsdom';
global.document = jsdom('');
global.window = document.defaultView;
global.navigator = global.window.navigator;
global.Node = global.window.Node;
const argv = minimist(process.argv.slice(2), {
alias: {
c: 'component',
g: 'grep',
},
});
const mocha = new Mocha({
grep: argv.grep ? argv.grep : undefined,
});
glob(`src/**/${argv.component ? argv.component : '*'}.spec.js`, {}, (err, files) => {
files.forEach((file) => mocha.addFile(file));
mocha.run((failures) => {
process.on('exit', () => {
/* eslint-disable no-process-exit */
process.exit(failures);
});
});
});
import minimist from 'minimist';
import Mocha from 'mocha';
import glob from 'glob';
const argv = minimist(process.argv.slice(2), {
alias: {
m: 'module',
g: 'grep',
},
});
const globPatterns = [
`test/**/${argv.module ? argv.module : '*'}.spec.js`,
];
const mocha = new Mocha({
grep: argv.grep ? argv.grep : undefined,
});
glob(
globPatterns.length > 1 ? `{${globPatterns.join(',')}}` : globPatterns[0],
{},
(err, files) => {
files.forEach((file) => mocha.addFile(file));
mocha.run((failures) => {
process.on('exit', () => {
process.exit(failures); // eslint-disable-line no-process-exit
});
});
}
);
global[property] = document.defaultView[property];
}
});
global.navigator = {
userAgent: 'node.js',
};
const argv = minimist(process.argv.slice(2), {
alias: {
c: 'component',
g: 'grep',
},
});
const mocha = new Mocha({
grep: argv.grep ? argv.grep : undefined,
reporter: 'dot',
});
glob(`packages/**/src/**/${argv.component ? argv.component : '*'}.spec.js`, {}, (err, files) => {
files.forEach((file) => mocha.addFile(file));
mocha.run((failures) => {
process.on('exit', () => {
process.exit(failures); // eslint-disable-line no-process-exit
});
});
});
const createMocha = (driver, testCase) => {
// Create our Mocha instance
const mocha = new Mocha({
reporter: 'mochawesome',
reporterOptions: {
overwrite: false,
reportTitle: 'UI Tests',
reportFilename: 'UITestReport',
reportDir: './dist/reports/UITestsReport',
assetsDir: './dist/reports/UITestsReport',
},
timeout: testCase.timeout
});
// By default `require` caches files, making it impossible to require the same file multiple times.
// Since we want to execute the same tests against many browsers we need to prevent this behaviour by
// clearing the require cache.
mocha.suite.on('require', (global, file) => {
delete require.cache[file];
});
export function run(): Promise {
// Create the mocha test
const mocha = new Mocha({
ui: 'tdd'
});
mocha.useColors(true);
const testsRoot = path.resolve(__dirname, '..');
return new Promise((c, e) => {
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
if (err) {
return e(err);
}
// Add files to the test suite
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
try {
const createMocha = (driver, testCase) => {
// Create our Mocha instance
const mocha = new Mocha({
timeout: testCase.timeout,
fullTrace: true
});
// By default `require` caches files, making it impossible to require the same file multiple times.
// Since we want to execute the same tests against many browsers we need to prevent this behaviour by
// clearing the require cache.
mocha.suite.on('require', (global, file) => {
delete require.cache[file];
});
mocha.addFile(`${testCase.file}`);
mocha.suite.ctx.driver = driver
mocha.runP = () => new Promise((resolve) => {
mocha.run(resolve)
})
global[property] = document.defaultView[property];
}
});
global.navigator = {
userAgent: 'node.js'
};
const argv = Minimist(process.argv.slice(2), {
alias: {
c: 'component',
g: 'grep',
},
});
const mocha = new Mocha({
grep: argv.grep ? argv.grep : undefined,
});
Glob(`src/**/${argv.component ? argv.component : '*'}.spec.js`, {}, (err, files) => {
files.forEach((file) => mocha.addFile(file));
mocha.run((failures) => {
process.on('exit', () => {
process.exit(failures);
});
});
});
exercise.addSetup(function(mode, callback) {
const mocha = new Mocha({timeout: 20000});
mocha.addFile(path.join(this.dir, 'spec.js'));
runFunction(global.submission);
mocha.run((failures) => {
this.failures = failures;
callback(null, true);
});
});