From ca59a402282cd1f5f459f05ccb1cbab6b342e63e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=91=A8=F0=9F=8F=BC=E2=80=8D=F0=9F=92=BB=20Romain=20M?= =?UTF-8?q?arcadier-Muller?= Date: Wed, 10 Oct 2018 09:32:02 +0200 Subject: [PATCH] feat: Resolve paths to nyc & nodeunit Resolves paths to `nyc` and `nodeunit` from node-provided dependencies, so that it is possible to use `npm run test` from packages without having those installed globally or having the `lerna`-modified `$PATH`. Also allows configuring different executables from CLI arguments or environment variables. --- tools/cdk-build-tools/bin/cdk-test.ts | 16 ++++++++++++++-- tools/cdk-build-tools/package.json | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tools/cdk-build-tools/bin/cdk-test.ts b/tools/cdk-build-tools/bin/cdk-test.ts index a0d19767fba48..57910e22910ca 100644 --- a/tools/cdk-build-tools/bin/cdk-test.ts +++ b/tools/cdk-build-tools/bin/cdk-test.ts @@ -27,6 +27,18 @@ async function main() { desc: 'Specify a different tsc executable', defaultDescription: 'tsc provided by node dependencies' }) + .option('nyc', { + type: 'string', + desc: 'Specify a different nyc executable', + default: require.resolve('nyc/bin/nyc'), + defaultDescription: 'nyc provided by node dependencies' + }) + .option('nodeunit', { + type: 'string', + desc: 'Specify a different nodeunit executable', + default: require.resolve('nodeunit/bin/nodeunit'), + defaultDescription: 'nodeunit provided by node dependencies' + }) .argv as any; // Always recompile before running tests, so it's impossible to forget. @@ -53,9 +65,9 @@ async function main() { // It's okay if the symlink already exists if (e.code !== 'EEXIST') { throw e; } } - testCommand.push(...['nyc', '--clean']); + testCommand.push(...[args.nyc, '--clean']); } - testCommand.push('nodeunit'); + testCommand.push(args.nodeunit); testCommand.push(...testFiles.map(f => f.path)); await shell(testCommand, timers); diff --git a/tools/cdk-build-tools/package.json b/tools/cdk-build-tools/package.json index d994e1cdfdd51..4d334994b9339 100644 --- a/tools/cdk-build-tools/package.json +++ b/tools/cdk-build-tools/package.json @@ -35,6 +35,8 @@ "jsii": "^0.7.6", "jsii-pacmak": "^0.7.6", "merkle-build": "^0.10.0", + "nodeunit": "^0.11.3", + "nyc": "^13.0.1", "typescript": "^3.0.1", "yargs": "^9.0.1" },