remix-project mirror
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
remix-project/libs/remix-tests/src/run.ts

79 lines
2.2 KiB

import commander from 'commander'
import Web3 from 'web3';
import path from 'path'
6 years ago
import { runTestFiles } from './runTestFiles'
import fs from './fileSystem'
import { Provider } from '@remix-project/remix-simulator'
import Log from './logger'
6 years ago
const logger = new Log()
const log = logger.logger
import colors from 'colors'
6 years ago
// parse verbosity
function mapVerbosity (v: number) {
6 years ago
const levels = {
0: 'error',
1: 'warn',
2: 'info',
3: 'verbose',
4: 'debug',
5: 'silly'
}
return levels[v]
}
const version = require('../package.json').version
6 years ago
commander.version(version)
commander.command('version').description('output the version number').action(function () {
console.log(version)
})
commander.command('help').description('output usage information').action(function () {
commander.help()
})
// get current version
commander
.option('-v, --verbose <level>', 'run with verbosity', mapVerbosity)
.action(async (testsPath) => {
// Check if path exists
if (!fs.existsSync(testsPath)) {
log.error(testsPath + ' not found')
process.exit(1)
}
// Check if path is for a directory
const isDirectory = fs.lstatSync(testsPath).isDirectory()
// If path is for a file, file name must have `_test.sol` suffix
if(!isDirectory && !testsPath.endsWith('_test.sol')) {
log.error('Test filename should end with "_test.sol"')
process.exit()
}
6 years ago
// Console message
console.log(colors.white('\n\t👁\t:: Running remix-tests - Unit testing for solidity ::\t👁\n'))
// Set logger verbosity
6 years ago
if (commander.verbose) {
logger.setVerbosity(commander.verbose)
log.info('verbosity level set to ' + commander.verbose.blue)
}
const web3 = new Web3()
const provider: any = new Provider()
await provider.init()
web3.setProvider(provider)
6 years ago
runTestFiles(path.resolve(testsPath), isDirectory, web3)
6 years ago
})
if (!process.argv.slice(2).length) {
log.error('Please specify a file or directory path')
6 years ago
process.exit()
}
commander.parse(process.argv)