From 3140a693722c14d5623b64e6c4d1f1c43f58008f Mon Sep 17 00:00:00 2001 From: Jan Krems Date: Sun, 11 Dec 2016 14:37:25 -0800 Subject: [PATCH] build: add node-inspect integration test This just adds an additional make target (`make test-node-inspect`) but will not include the new debugger in releases. PR-URL: https://github.com/nodejs/node/pull/10187 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell --- Makefile | 4 ++ tools/test-npm-package.js | 139 ++++++++++++++++++++++++++++++++++++++ vcbuild.bat | 8 +++ 3 files changed, 151 insertions(+) create mode 100755 tools/test-npm-package.js diff --git a/Makefile b/Makefile index d4548ba99d580a..2aac5c2f6a26e0 100644 --- a/Makefile +++ b/Makefile @@ -256,6 +256,10 @@ test-debugger: all test-inspector: all $(PYTHON) tools/test.py inspector +test-node-inspect: $(NODE_EXE) + USE_EMBEDDED_NODE_INSPECT=1 $(NODE) tools/test-npm-package \ + --install deps/node-inspect test + test-tick-processor: all $(PYTHON) tools/test.py tick-processor diff --git a/tools/test-npm-package.js b/tools/test-npm-package.js new file mode 100755 index 00000000000000..951ec5c306ecc7 --- /dev/null +++ b/tools/test-npm-package.js @@ -0,0 +1,139 @@ +#!/usr/bin/env node +/** + * Usage: + * test-npm-package.js [--install] [--rebuild] + + * + * Everything after the directory gets passed to `npm run` to build + * the test command. + * + * If `--install` is passed, we'll run a full `npm install` before running the + * test suite. Same for `--rebuild` and `npm rebuild`. + * + * We always use the node used to spawn this script and the `npm` version + * bundled in `deps/npm`. + * + * If an additional `--logfile=` option is passed before ``, + * the stdout output of the test script will be written to that file. + */ +'use strict'; +const { spawn, spawnSync } = require('child_process'); +const { createHash } = require('crypto'); +const { createWriteStream, mkdirSync, rmdirSync } = require('fs'); +const path = require('path'); + +const common = require('../test/common'); + +const projectDir = path.resolve(__dirname, '..'); +const npmBin = path.join(projectDir, 'deps', 'npm', 'cli.js'); +const nodePath = path.dirname(process.execPath); + +function spawnCopyDeepSync(source, destination) { + if (common.isWindows) { + mkdirSync(destination); // prevent interactive prompt + return spawnSync('xcopy.exe', ['/E', source, destination]); + } else { + return spawnSync('cp', ['-r', `${source}/`, destination]); + } +} + +function runNPMPackageTests({ srcDir, install, rebuild, testArgs, logfile }) { + // Make sure we don't conflict with concurrent test runs + const srcHash = createHash('md5').update(srcDir).digest('hex'); + common.tmpDir = common.tmpDir + '.npm.' + srcHash; + common.refreshTmpDir(); + + const tmpDir = common.tmpDir; + const npmCache = path.join(tmpDir, 'npm-cache'); + const npmPrefix = path.join(tmpDir, 'npm-prefix'); + const npmTmp = path.join(tmpDir, 'npm-tmp'); + const npmUserconfig = path.join(tmpDir, 'npm-userconfig'); + const pkgDir = path.join(tmpDir, 'pkg'); + + spawnCopyDeepSync(srcDir, pkgDir); + + const npmOptions = { + cwd: pkgDir, + env: Object.assign({}, process.env, { + 'npm_config_cache': npmCache, + 'npm_config_prefix': npmPrefix, + 'npm_config_tmp': npmTmp, + 'npm_config_userconfig': npmUserconfig, + }), + stdio: 'inherit', + }; + + if (common.isWindows) { + npmOptions.env.home = tmpDir; + npmOptions.env.Path = `${nodePath};${process.env.Path}`; + } else { + npmOptions.env.HOME = tmpDir; + npmOptions.env.PATH = `${nodePath}:${process.env.PATH}`; + } + + if (rebuild) { + spawnSync(process.execPath, [ + npmBin, + 'rebuild', + ], npmOptions); + } + + if (install) { + spawnSync(process.execPath, [ + npmBin, + 'install', + '--ignore-scripts', + ], npmOptions); + } + + const testChild = spawn(process.execPath, [ + npmBin, + '--silent', + 'run', + ...testArgs, + ], Object.assign({}, npmOptions, { stdio: 'pipe' })); + + testChild.stdout.pipe(process.stdout); + testChild.stderr.pipe(process.stderr); + + if (logfile) { + const logStream = createWriteStream(logfile); + testChild.stdout.pipe(logStream); + } + + testChild.on('exit', () => { + common.refreshTmpDir(); + rmdirSync(tmpDir); + }); +} + +function parseArgs(args) { + let srcDir; + let rebuild = false; + let install = false; + let logfile = null; + const testArgs = []; + args.forEach((arg) => { + if (srcDir) { + testArgs.push(arg); + return; + } + + if (arg === '--install') { + install = true; + } else if (arg === '--rebuild') { + rebuild = true; + } else if (arg[0] !== '-') { + srcDir = path.resolve(projectDir, arg); + } else if (arg.startsWith('--logfile=')) { + logfile = path.resolve(projectDir, arg.slice('--logfile='.length)); + } else { + throw new Error(`Unrecognized option ${arg}`); + } + }); + if (!srcDir) { + throw new Error('Expected a source directory'); + } + return { srcDir, install, rebuild, testArgs, logfile }; +} + +runNPMPackageTests(parseArgs(process.argv.slice(2))); diff --git a/vcbuild.bat b/vcbuild.bat index 06d09fd792b463..375901ba6276de 100644 --- a/vcbuild.bat +++ b/vcbuild.bat @@ -39,6 +39,7 @@ set enable_vtune_arg= set configure_flags= set build_addons= set dll= +set test_node_inspect= :next-arg if "%1"=="" goto args-done @@ -68,6 +69,7 @@ if /i "%1"=="test-internet" set test_args=%test_args% internet&goto arg-ok if /i "%1"=="test-pummel" set test_args=%test_args% pummel&goto arg-ok if /i "%1"=="test-all" set test_args=%test_args% sequential parallel message gc inspector internet pummel&set build_testgc_addon=1&set jslint=1&goto arg-ok if /i "%1"=="test-known-issues" set test_args=%test_args% known_issues&goto arg-ok +if /i "%1"=="test-node-inspect" set test_node_inspect=1&goto arg-ok if /i "%1"=="jslint" set jslint=1&goto arg-ok if /i "%1"=="jslint-ci" set jslint_ci=1&goto arg-ok if /i "%1"=="package" set package=1&goto arg-ok @@ -331,6 +333,12 @@ EndLocal goto run-tests :run-tests +if not defined test_node_inspect goto node-tests +set USE_EMBEDDED_NODE_INSPECT=1 +%config%\node tools\test-npm-package.js --install deps\node-inspect test +goto node-tests + +:node-tests if "%test_args%"=="" goto jslint if "%config%"=="Debug" set test_args=--mode=debug %test_args% if "%config%"=="Release" set test_args=--mode=release %test_args%