Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function (exit) {
// banner line
console.log(chalk.yellow.bold('Running unit tests using mocha on node...'));
sh.test('-d', COV_REPORT_PATH) && sh.rm('-rf', COV_REPORT_PATH);
sh.mkdir('-p', COV_REPORT_PATH);
var Mocha = require('mocha'),
nyc = new NYC({
hookRequire: true,
reporter: ['text', 'lcov', 'text-summary', 'json'],
reportDir: COV_REPORT_PATH,
tempDirectory: COV_REPORT_PATH
});
nyc.wrap();
// add all spec files to mocha
recursive(SPEC_SOURCE_DIR, function (err, files) {
if (err) { console.error(err); return exit(1); }
var mocha = new Mocha({ timeout: 1000 * 60 });
// run each plugin's tests:
let plugins = ['adjectives', 'dates', 'ngrams', 'numbers', 'output', 'paragraphs', 'sentences', 'syllables']
plugins.forEach(dir => {
code = sh.exec(`tape "./plugins/${dir}/tests/**/*.test.js" | tap-dancer --color always`).code
if (code !== 0) {
console.log(dir)
fail = true
}
})
// return proper exit-code:
if (fail) {
sh.exit(1)
} else {
sh.exit(0)
}
it('should not create the path if it already exist', function () {
const folderPath = path.resolve('./reacterminator')
shell.mkdir(folderPath)
const notCustomPath = path.resolve(folderPath, 'not-custom.js')
fs.writeFileSync(notCustomPath, '/* eslint-disable */\nnot custom')
const customPath = path.resolve(folderPath, 'custom.js')
fs.writeFileSync(customPath, '//')
cleanFolder(folderPath)
assert(!shell.test('-f', notCustomPath), 'generated file should not exist')
assert(shell.test('-f', customPath), 'custom file should exist')
})
})
//------------------------------------------------------------------------------
const
path = require("path"),
{ Linter } = require("eslint"),
shelljs = require("shelljs"),
parser = require("../../"),
testUtils = require("../../tools/test-utils");
//------------------------------------------------------------------------------
// Setup
//------------------------------------------------------------------------------
const TSX_FIXTURES_DIR = "./tests/fixtures/tsx";
const testFiles = shelljs.find(TSX_FIXTURES_DIR)
.filter(filename => filename.indexOf(".src.tsx") > -1)
// strip off ".src.tsx"
.map(filename => filename.substring(TSX_FIXTURES_DIR.length - 1, filename.length - 8));
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
describe("TSX", () => {
testFiles.forEach(filename => {
const code = shelljs.cat(`${path.resolve(TSX_FIXTURES_DIR, filename)}.src.tsx`);
const config = {
useJSXTextNode: true,
jsx: true
};
test(`fixtures/${filename}.src`, testUtils.createSnapshotTestBlock(code, config));
function reset() {
console.log('Reset environment...');
// exec('npm unlink', { cwd: publicPluginRoot });
// exec('npm unlink rekit-plugin-public-test', { cwd: appRoot });
shell.rm('-rf', publicPluginRoot);
shell.rm('-rf', localPluginRoot);
_.pull(pkg.rekit.plugins, 'public-test');
shell.ShellString(JSON.stringify(pkg, null, ' ')).to(appPkgJsonPath);
}
// $ExpectError
sh.exit('');
// Success
(sh.exit(): void);
// Success
(sh.exit(0): void);
// $ExpectError
sh.find();
// $ExpectError
sh.find(0);
// Success
(sh.find('~', '/tmp'): ShellArray);
// $ExpectError
sh.grep();
// $ExpectError
sh.grep(0);
// $ExpectError
sh.grep({'-x': true }, 'type');
// $ExpectError
sh.grep({'-x': true }, 'type');
// $ExpectError
sh.grep({ '-x': true }, /type/, 'definitions/**/*.js');
// Success
(sh.grep({ '-l': true }, /type/, 'definitions/**/*.js'): ShellString);
// Success
(sh.grep({ '-l': true }, 'type', 'definitions/**/*.js'): ShellString);
// Success
(sh.grep('type', 'definitions/**/*.js'): ShellString);
// $ExpectError
tryExecNTimes(() => {
echo(`Starting ${testClass}`);
// any faster means Circle CI crashes
exec('sleep 10s');
return exec(
`./scripts/run-instrumentation-tests-via-adb-shell.sh ${
argv.package
} ${testClass}`,
).code;
}, numberOfRetries)
) {
const migration = deployDouble(contracts);
// Scaffold
shell.mkdir(temp);
shell.cp('-Rf', templatePath, temp);
// Contracts
contracts.forEach(item => {
shell.cp(`${sourcesPath}${item}.sol`, `${temp}/contracts/${item}.sol`)
});
// Migration
fs.writeFileSync(migrationPath, migration)
// Test
shell.cp(`${testPath}${test}`, `${temp}/test/${test}`);
// Configs
fs.writeFileSync(`${temp}/${truffleConfigName}`, getTruffleConfigJS());
fs.writeFileSync(`${temp}/${buidlerConfigName}`, getBuidlerConfigJS());
fs.writeFileSync(configPath, configjs);
decacheConfigs();
};
(sh.rm('/tmp/tmp0', '/tmp/tmp1'): ShellString);
// $ExpectError
sh.sed();
// $ExpectError
sh.sed(0);
// $ExpectError
sh.sed('foo');
// $ExpectError
sh.sed('foo', 'bar');
// $ExpectError
sh.sed({ '-x': true }, 'foo', 'bar', '/tmp/tmp0');
// Success
(sh.sed({ '-i': true }, 'foo', 'bar', '/tmp/tmp0'): ShellString);
// Success
(sh.sed('foo', 'bar', '/tmp/tmp0'): ShellString);
// Success
(sh.sed(/foo/, 'bar', '/tmp/tmp0'): ShellString);
// $ExpectError
sh.set();
// $ExpectError
sh.set(0);
// $ExpectError
sh.set('-x');
// Success
(sh.set('-e'): void);
// Success
(sh.set('+e'): void);
// $ExpectError
sh.sort();
renameDir: function(test) {
test.expect(1);
var application = Util.createTmpApplication("com.example.foo");
var path = application.rootPath;
var path2 = Path.join(Path.dirname(path), "foo");
ShellJS.mv(path, path2);
try {
application = new Application(path2, null);
test.equal(application.packageId, "com.example.foo");
} catch (error) {
// Just catch error, missing test assertion makes test case fail.
}
// Clean up manually, so it also works in case of error.
// Util.createTmpApplication() always works inside a random named dir
// so go one level up and remove.
ShellJS.rm("-rf", Path.dirname(path2));
test.done();
},