@microsoft/windows-admin-center-sdk
Version:
Microsoft - Windows Admin Center Shell
1 lines • 3.41 kB
Source Map (JSON)
{"version":3,"sources":["../../../packages/tools/test-runner/index.ts"],"names":[],"mappings":"","file":"index.d.ts","sourcesContent":["'use strict';\r\n\r\nimport childProcess from 'child_process';\r\nimport fs from 'fs';\r\nimport path from 'path';\r\nimport log from 'fancy-log';\r\nimport pluginError from 'plugin-error';\r\n\r\nconst PLUGIN_NAME = 'test-runner';\r\n\r\ninterface PesterOptions {\r\n outputPath: string;\r\n srcPath: string;\r\n testPath: string;\r\n verbose: boolean;\r\n logIdentifier: string;\r\n}\r\n\r\nfunction runPester(options: PesterOptions, callback: Function) {\r\n const powerShell = 'powershell.exe';\r\n const script = path.normalize(__dirname + '..\\\\..\\\\..\\\\tools\\\\scripts\\\\Invoke-PesterTest.ps1');\r\n\r\n // get output directory\r\n const outputDir = path.dirname(options.outputPath);\r\n\r\n // make results dir if it doesn't exist\r\n if (!fs.existsSync(outputDir)) {\r\n fs.mkdirSync(outputDir);\r\n }\r\n\r\n const args = ['-NoProfile', '-File', script];\r\n if (options.srcPath) {\r\n args.push('-SrcPath', options.srcPath);\r\n }\r\n\r\n if (options.testPath) {\r\n args.push('-TestPath', options.testPath);\r\n }\r\n\r\n if (options.outputPath) {\r\n args.push('-OutputPath', options.outputPath);\r\n }\r\n\r\n if (!options.verbose) {\r\n args.push('-Quiet');\r\n }\r\n\r\n log(powerShell, args.join(' '));\r\n const cmd = childProcess.spawn(powerShell, args);\r\n const errors = [];\r\n\r\n cmd.stdout.on('data', function (data) {\r\n const message = data.toString().trim();\r\n if (message && message.length) {\r\n log(`${options.logIdentifier} - ${data.toString().trim()}`);\r\n }\r\n });\r\n\r\n cmd.stderr.on('data', function (data) {\r\n const message = data.toString().trim();\r\n if (message.toUpperCase().startsWith('ERROR')) {\r\n log.error(`${options.logIdentifier} - ${message}`);\r\n errors.push(`${options.logIdentifier} - ${message}`);\r\n } else if (message && message.length) {\r\n log(`${options.logIdentifier} - ${message}`);\r\n }\r\n });\r\n\r\n cmd.on('exit', function (code) {\r\n if (code !== 0) {\r\n callback('Powershell Unit tests failed. Please check the log for errors or failed tests.');\r\n return;\r\n }\r\n callback();\r\n });\r\n}\r\n\r\ninterface TestOptions {\r\n pester?: PesterOptions;\r\n}\r\n\r\ntype CallbackFunction = (err?: any) => void;\r\n\r\nfunction run(options: TestOptions, callback: Function) {\r\n const tests: ((cb: CallbackFunction) => void)[] = [];\r\n const next = () => {\r\n if (tests.length > 0) {\r\n tests[0]((err) => {\r\n if (!err) {\r\n // remove first test runner\r\n tests.splice(0, 1);\r\n // call next runner\r\n next();\r\n } else {\r\n callback(new pluginError({ plugin: PLUGIN_NAME, message: err }));\r\n }\r\n });\r\n } else {\r\n callback();\r\n }\r\n };\r\n\r\n if (options.pester) {\r\n tests.push((cb) => runPester(options.pester, cb));\r\n }\r\n\r\n next();\r\n}\r\n\r\nmodule.exports = run;\r\n"]}