UNPKG

siesta-lite

Version:

Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers

187 lines (147 loc) 6.43 kB
/* Siesta 5.6.1 Copyright(c) 2009-2022 Bryntum AB https://bryntum.com/contact https://bryntum.com/products/siesta/license */ Class('Siesta.Launcher.NodeJS', { isa : Siesta.Launcher.BaseLauncher, does : [ Siesta.Launcher.CommandLineTool.NodeJSTool, Siesta.Launcher.Role.CanWorkWithNyc ], has : { executableName : 'nodejs', sharedNativeSimulator : false, knownOptionGroups : { init : { '15-nodejs' : { name : 'NodeJS options' } } }, knownOptions : { init : [ { name : 'isolate-console', desc : [ 'This option disables the "shared" console - the `stdin/stdout/stderr` streams of all test files will not be forwarded', 'to the main console.' ], group : '20-misc' }, { name : 'inspect', desc : [ 'This option will be translated to the --inspect[=[host:]port] option of the Node.js process, starting', 'a debugger inspector instance on the given host/port, by default 127.0.0.1:9229.', 'It will also switch the test suite to --max-workers=1 mode, to avoid collision of the debugger instances', ], group : '15-debug' }, { name : 'inspect-brk', desc : [ 'Same as --inspect, and will also stop on the breakpoint before launching every test', ], group : '15-debug' }, { name : 'node-arg', desc : [ 'This option can be repeated several times, and specifies command line arguments for the derived NodeJS process', 'in the form --node-arg name=value, for example:\n', ' --node-arg=\'--inspect-port=12345\' --node-arg=\'--no-deprecation\'\n', 'Full options list is listed in: > node --help\n', ], group : '20-misc' }, { name : '__instrumented-copy__', desc : 'System option, not for user', group : '20-misc' } ] }, helpIntro : function () { var style = this.style() return [ style.bold('Usage: ') + this.executableName + ' [glob] [OPTIONS]\n', 'Will launch all tests matching ' + style.bold('glob') + ' (default value is "**/*.t.?(m)js").', 'Use trailing ' + style.bold('/') + ' to match directories.', 'All options are optional.', '' ] }, manuallyProcessCoverageResults : false }, methods : { // getRawNycArgs : function () { // return this.positionalGroups.nyc // }, createOptionsWrapper : function (cfg) { return new Siesta.Launcher.Options.NodeJS({ options : cfg, launcher : this }) }, // this method runs before the "prepareOptions" call createRunners : function () { return [ new Siesta.Launcher.Runner.NodeJS({ launcher : this }) ] }, getCommonProjectConfig : function () { const options = this.options const res = this.SUPER() return options[ 'inspect-brk' ] ? Object.assign(res, { debuggerOnStart : true }) : res }, printVersion : function () { this.SUPERARG(arguments) this.print(this.style().bold("NodeJS : ") + process.version) }, setup : async function () { const instrumentedCopyOptionName = '__instrumented-copy__' if (this.options.coverage && !this.options[ instrumentedCopyOptionName ]) { const path = require('path') const foreground = require('foreground-child') const sw = require('spawn-wrap') const wrapper = require.resolve('nyc/bin/wrap.js') let argv = this.buildNycArgv(this.positionalGroups.nyc) // always exclude siesta files from instrumentation argv.exclude.push( path.relative(argv.cwd, __dirname + '/../bin'), path.relative(argv.cwd, __dirname + '/../src'), path.relative(argv.cwd, __dirname + '/../index.js'), path.relative(argv.cwd, __dirname + '/../siesta-nodejs-all.js'), '**/*.t.js' ) let nyc = await this.buildNyc(argv) if (argv.all) await nyc.addAllFiles() let env = { NYC_CONFIG : JSON.stringify(argv), NYC_CWD : process.cwd(), NYC_ROOT_ID : nyc.rootId, NYC_INSTRUMENTER : nyc.config.instrumenter } if (argv['babel-cache'] === false) { // babel's cache interferes with some configurations, so is // disabled by default. opt in by setting babel-cache=true. env.BABEL_DISABLE_CACHE = process.env.BABEL_DISABLE_CACHE = '1' } sw([ wrapper ], env) return new Promise((resolve, reject) => { foreground( process.argv[ 0 ], process.argv.slice(1).concat('--' + instrumentedCopyOptionName), async () => { await this.nycReport(nyc) resolve('instrumentation') } ) }) } else return Promise.resolve() } } // eof methods })