From a68825d058991bbe08ce3cd05b3a690722a5594c Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 15 Apr 2018 13:33:07 +0200 Subject: [PATCH 01/28] feat: add support for yarn installations --- CONTRIBUTING.md | 2 +- README.md | 2 ++ bin/citgm-all.js | 1 + bin/citgm.js | 3 +- lib/citgm.js | 7 +++-- lib/common-args.js | 6 ++++ lib/lookup.js | 3 ++ lib/package-manager/index.js | 24 +++++++++++++++ lib/{npm => package-manager}/install.js | 27 ++++++++++------- lib/{npm/index.js => package-manager/npm.js} | 4 +-- lib/{npm => package-manager}/test.js | 31 +++++++++++++------- lib/package-manager/yarn.js | 8 +++++ test/npm/test-npm-author-name.js | 2 +- test/npm/test-npm-install.js | 12 ++++---- test/npm/test-npm-test.js | 14 ++++----- 15 files changed, 103 insertions(+), 43 deletions(-) create mode 100644 lib/package-manager/index.js rename lib/{npm => package-manager}/install.js (62%) rename lib/{npm/index.js => package-manager/npm.js} (60%) rename lib/{npm => package-manager}/test.js (75%) create mode 100644 lib/package-manager/yarn.js diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 471f579f1..f11501440 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -52,7 +52,7 @@ This is for adding a module to be included in the default `citgm-all` runs. * Module source code must be on Github. * Published versions must include a tag on Github * The test process must be executable with only the commands -`npm install && npm test` using the tarball downloaded from the Github tag +`npm install && npm test` or (`yarn install && yarn test`) using the tarball downloaded from the Github tag mentioned above * The tests pass on supported major release lines * The maintainers of the module remain responsive when there are problems diff --git a/README.md b/README.md index 3b7492627..17e51ab86 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,7 @@ Options: --includeTags tag1 tag2 Only test modules from the lookup that contain a matching tag field --excludeTags tag1 tag2 Specify which tags to skip from the lookup (takes priority over includeTags) Module names are automatically added as tags. + -y, --yarn Install and test the project using yarn instead of npm ``` When using a JSON config file, the properties need to be the same as the @@ -140,6 +141,7 @@ For syntax, see [lookup.json](./lib/lookup.json), the available attributes are: "maintainers": ["user1", "user2"] - List of module maintainers to be contacted with issues "tags": ["tag1", "tag2"] Specify which tags apply to the module "ignoreGitHead": Ignore the gitHead field if it exists and fallback to using github tags +"yarn": Install and test the project using yarn instead of npm ``` If you want to pass options to npm, eg `--registry`, you can usually define an diff --git a/bin/citgm-all.js b/bin/citgm-all.js index 3d8d157dd..ffe138664 100755 --- a/bin/citgm-all.js +++ b/bin/citgm-all.js @@ -71,6 +71,7 @@ const options = { timeoutLength: app.timeout, tmpDir: app.tmpDir, customTest: app.customTest, + yarn: app.yarn, includeTags: app.includeTags || [], excludeTags: app.excludeTags || [] }; diff --git a/bin/citgm.js b/bin/citgm.js index c905cf9c4..c74bc268a 100755 --- a/bin/citgm.js +++ b/bin/citgm.js @@ -48,7 +48,8 @@ const options = { timeoutLength: app.timeout, sha: app.sha, tmpDir: app.tmpDir, - customTest: app.customTest + customTest: app.customTest, + yarn: app.yarn }; if (!citgm.windows) { diff --git a/lib/citgm.js b/lib/citgm.js index 2e28a0f37..6fe660773 100644 --- a/lib/citgm.js +++ b/lib/citgm.js @@ -10,7 +10,7 @@ let which = require('which'); // Mocked in tests const grabModuleData = require('./grab-module-data'); const grabProject = require('./grab-project'); const lookup = require('./lookup'); -const npm = require('./npm'); +const packageManager = require('./package-manager'); const tempDirectory = require('./temp-directory'); const unpack = require('./unpack'); @@ -100,13 +100,14 @@ Tester.prototype.run = function() { init.bind(null, this), find.bind(null, 'node'), find.bind(null, 'npm'), + find.bind(null, 'yarn'), tempDirectory.create, grabModuleData, lookup, grabProject, unpack, - npm.install, - npm.test + packageManager.install, + packageManager.test ], (err) => { if (!this.cleanexit) { const payload = { diff --git a/lib/common-args.js b/lib/common-args.js index 26a566826..818cdb0f2 100644 --- a/lib/common-args.js +++ b/lib/common-args.js @@ -75,6 +75,12 @@ module.exports = function commonArgs (app) { description: 'Set timeout for npm install', default: 1000 * 60 * 10 }) + .option('yarn', { + alias: 'y', + type: 'boolean', + description: 'Install and test the project using yarn instead of npm', + default: false + }) .example('citgm-all --customTest /path/to/customTest.js', 'Runs a custom node test script instead of "npm test"'); diff --git a/lib/lookup.js b/lib/lookup.js index edc3c3902..35a2ea431 100644 --- a/lib/lookup.js +++ b/lib/lookup.js @@ -114,6 +114,9 @@ function resolve(context, next) { if (rep.tags) { context.module.tags = rep.tags; } + if (rep.yarn) { + context.module.useYarn = true; + } context.module.flaky = context.options.failFlaky ? false : isMatch(rep.flaky); context.module.expectFail = context.options.expectFail ? diff --git a/lib/package-manager/index.js b/lib/package-manager/index.js new file mode 100644 index 000000000..c8cbe6c2f --- /dev/null +++ b/lib/package-manager/index.js @@ -0,0 +1,24 @@ +'use strict'; +const npm = require('./npm'); +const yarn = require('./yarn'); + +function install(context, next) { + if (context.options.yarn || context.module.useYarn) { + yarn.install(context, next); + } else { + npm.install(context, next); + } +} + +function test(context, next) { + if (context.options.yarn || context.module.useYarn) { + yarn.test(context, next); + } else { + npm.test(context, next); + } +} + +module.exports = { + install: install, + test: test +}; diff --git a/lib/npm/install.js b/lib/package-manager/install.js similarity index 62% rename from lib/npm/install.js rename to lib/package-manager/install.js index 8cfbeddab..a0cad3a74 100644 --- a/lib/npm/install.js +++ b/lib/package-manager/install.js @@ -7,22 +7,24 @@ const createOptions = require('../create-options'); const spawn = require('../spawn'); const timeout = require('../timeout'); -function install(context, next) { +function install(packageManager, context, next) { const options = createOptions( path.join(context.path, context.module.name), context); let args = ['install']; - context.emit('data', 'info', context.module.name + ' npm:', - 'npm install started'); + context.emit('data', 'info', context.module.name + ' ' + packageManager + + ':', + packageManager + ' install started'); - context.emit('data', 'verbose', context.module.name + ' npm:', + context.emit('data', 'verbose', context.module.name + ' ' + packageManager + + ':', 'Using temp directory: "' + options.env['npm_config_tmp'] + '"'); if (context.module.install) { args = args.concat(context.module.install); } - const proc = spawn('npm', args, options); + const proc = spawn(packageManager, args, options); const finish = timeout(context, proc, next, 'Install'); proc.stderr.on('data', function (chunk) { @@ -31,7 +33,8 @@ function install(context, next) { chunk = stripAnsi(chunk.toString()); chunk = chunk.replace(/\r/g, '\n'); } - context.emit('data', 'warn', context.module.name + ' npm-install:', + context.emit('data', 'warn', context.module.name + + ' ' + packageManager + '-install:', chunk.toString()); }); @@ -41,20 +44,22 @@ function install(context, next) { chunk = stripAnsi(chunk.toString()); chunk = chunk.replace(/\r/g, '\n'); } - context.emit('data', 'verbose', context.module.name + ' npm-install:', + context.emit('data', 'verbose', context.module.name + + ' ' + packageManager + '-install:', chunk.toString()); }); - proc.on('error', function() { + proc.on('error', function () { return finish(new Error('Install Failed')); }); - proc.on('close', function(code) { + proc.on('close', function (code) { if (code > 0) { return finish(Error('Install Failed')); } - context.emit('data', 'info', context.module.name + ' npm:', - 'npm install successfully completed'); + context.emit('data', 'info', context.module.name + ' ' + + packageManager + ':', + packageManager + ' install successfully completed'); return finish(null, context); }); } diff --git a/lib/npm/index.js b/lib/package-manager/npm.js similarity index 60% rename from lib/npm/index.js rename to lib/package-manager/npm.js index eeb1b8fc9..daf945d68 100644 --- a/lib/npm/index.js +++ b/lib/package-manager/npm.js @@ -3,6 +3,6 @@ const install = require('./install'); const test = require('./test'); module.exports = { - install: install, - test: test + install: install.bind(null, 'npm'), + test: test.bind(null, 'npm') }; diff --git a/lib/npm/test.js b/lib/package-manager/test.js similarity index 75% rename from lib/npm/test.js rename to lib/package-manager/test.js index 6726b37d9..c40d81ccc 100644 --- a/lib/npm/test.js +++ b/lib/package-manager/test.js @@ -12,6 +12,7 @@ const timeout = require('../timeout'); const windows = (process.platform === 'win32'); let nodeBinName = 'node'; // Mocked in tests const npmBinName = 'npm'; +const yarnBinName = 'yarn'; function authorName(author) { if (typeof author === 'string') return author; @@ -22,9 +23,10 @@ function authorName(author) { return parts.join(' '); } -function test(context, next) { +function test(packageManager, context, next) { + const useYarn = packageManager === 'yarn'; const wd = path.join(context.path, context.module.name); - context.emit('data', 'info', context.module.name + ' npm:', + context.emit('data', 'info', context.module.name + ' ' + packageManager + ':', 'test suite started'); readPackage(path.join(wd, 'package.json'), false, function(err, data) { if (err) { @@ -35,10 +37,10 @@ function test(context, next) { data.scripts.test === undefined) { if (data.author) { context.emit('data', 'warn', context.module.name + ' notice', - 'Please contact the module developer to request adding npm' + - ' test support: ' + authorName(data.author)); + 'Please contact the module developer to request adding ' + + packageManager + '' + ' test support: ' + authorName(data.author)); } - next(new Error('Module does not support npm-test!')); + next(new Error('Module does not support ' + packageManager + '-test!')); return; } @@ -49,17 +51,24 @@ function test(context, next) { nodeBin = which(nodeBinName, {path: options.env.PATH || process.env.PATH}); } - let npmBin = which(npmBinName, {path: options.env.PATH - || process.env.PATH}); - if (windows) { - npmBin = path.join(path.dirname(npmBin), 'node_modules', 'npm', 'bin', - 'npm-cli.js'); + let packageManagerBin; + + if (useYarn) { + which(yarnBinName, {path: options.env.PATH + || process.env.PATH}); + } else { + packageManagerBin = which(npmBinName, {path: options.env.PATH + || process.env.PATH}); + if (windows) { + packageManagerBin = path.join(path.dirname(packageManagerBin), + 'node_modules', 'npm', 'bin', 'npm-cli.js'); + } } /* Run `npm test`, or `/path/to/customTest.js` if the customTest option was passed */ const args = context.options.customTest ? - [context.options.customTest] : [npmBin, 'test']; + [context.options.customTest] : [packageManagerBin, 'test']; const proc = spawn(nodeBin, args, options); const finish = timeout(context, proc, next, 'Test'); diff --git a/lib/package-manager/yarn.js b/lib/package-manager/yarn.js new file mode 100644 index 000000000..07395f13c --- /dev/null +++ b/lib/package-manager/yarn.js @@ -0,0 +1,8 @@ +'use strict'; +const install = require('./install'); +const test = require('./test'); + +module.exports = { + install: install.bind(null, 'yarn'), + test: test.bind(null, 'yarn') +}; diff --git a/test/npm/test-npm-author-name.js b/test/npm/test-npm-author-name.js index 098ddfd55..91acb269f 100644 --- a/test/npm/test-npm-author-name.js +++ b/test/npm/test-npm-author-name.js @@ -3,7 +3,7 @@ const test = require('tap').test; const rewire = require('rewire'); -const npmTest = rewire('../../lib/npm/test'); +const npmTest = rewire('../../lib/package-manager/test'); const authorName = npmTest.__get__('authorName'); diff --git a/test/npm/test-npm-install.js b/test/npm/test-npm-install.js index cbf6cde3b..29ce7499f 100644 --- a/test/npm/test-npm-install.js +++ b/test/npm/test-npm-install.js @@ -8,7 +8,7 @@ const mkdirp = require('mkdirp'); const rimraf = require('rimraf'); const ncp = require('ncp'); -const npmInstall = require('../../lib/npm/install'); +const npmInstall = require('../../lib/package-manager/install'); const makeContext = require('../helpers/make-context'); const sandbox = path.join(os.tmpdir(), 'citgm-' + Date.now()); @@ -43,7 +43,7 @@ test('npm-install: basic module', function (t) { const context = makeContext.npmContext('omg-i-pass', sandbox, { npmLevel: 'silly' }); - npmInstall(context, function (err) { + npmInstall('npm', context, function (err) { t.error(err); t.end(); }); @@ -56,7 +56,7 @@ test('npm-install: extra install parameters', function (t) { }, sandbox, { npmLevel: 'silly' }); - npmInstall(context, function (err) { + npmInstall('npm', context, function (err) { t.error(err); t.notOk(context.module.flaky, 'Module passed and is not flaky'); t.end(); @@ -67,7 +67,7 @@ test('npm-install: no package.json', function (t) { const context = makeContext.npmContext('omg-i-fail', sandbox, { npmLevel: 'silly' }); - npmInstall(context, function (err) { + npmInstall('npm', context, function (err) { t.equals(err && err.message, 'Install Failed'); t.notOk(context.module.flaky, 'Module failed but is not flaky'); t.end(); @@ -79,7 +79,7 @@ test('npm-install: timeout', function (t) { npmLevel: 'silly', timeoutLength: 100 }); - npmInstall(context, function (err) { + npmInstall('npm', context, function (err) { t.ok(context.module.flaky, 'Module is Flaky because install timed out'); t.equals(err && err.message, 'Install Timed Out'); t.end(); @@ -94,7 +94,7 @@ test('npm-install: failed install', function (t) { testOutput: /^$/, testError: /npm ERR! 404 Not [Ff]ound\s*: THIS-WILL-FAIL(@0\.0\.1)?/ }; - npmInstall(context, function (err) { + npmInstall('npm', context, function (err) { t.notOk(context.module.flaky, 'Module failed is not flaky'); t.equals(err && err.message, 'Install Failed'); t.match(context, expected, 'Install error reported'); diff --git a/test/npm/test-npm-test.js b/test/npm/test-npm-test.js index 6c094b4d6..9a89ac82c 100644 --- a/test/npm/test-npm-test.js +++ b/test/npm/test-npm-test.js @@ -10,7 +10,7 @@ const ncp = require('ncp'); const rewire = require('rewire'); const makeContext = require('../helpers/make-context'); -const npmTest = rewire('../../lib/npm/test'); +const npmTest = rewire('../../lib/package-manager/test'); const sandbox = path.join(os.tmpdir(), 'citgm-' + Date.now()); const fixtures = path.join(__dirname, '..', 'fixtures'); @@ -47,7 +47,7 @@ test('npm-test: basic module passing', function (t) { const context = makeContext.npmContext('omg-i-pass', sandbox, { npmLevel: 'silly' }); - npmTest(context, function (err) { + npmTest('npm', context, function (err) { t.error(err); t.end(); }); @@ -55,7 +55,7 @@ test('npm-test: basic module passing', function (t) { test('npm-test: basic module failing', function (t) { const context = makeContext.npmContext('omg-i-fail', sandbox); - npmTest(context, function (err) { + npmTest('npm', context, function (err) { t.equals(err && err.message, 'The canary is dead:'); t.end(); }); @@ -64,7 +64,7 @@ test('npm-test: basic module failing', function (t) { test('npm-test: basic module no test script', function (t) { const context = makeContext.npmContext('omg-i-do-not-support-testing', sandbox); - npmTest(context, function (err) { + npmTest('npm', context, function (err) { t.equals(err && err.message, 'Module does not support npm-test!'); t.end(); }); @@ -72,7 +72,7 @@ test('npm-test: basic module no test script', function (t) { test('npm-test: no package.json', function (t) { const context = makeContext.npmContext('omg-i-dont-exist', sandbox); - npmTest(context, function (err) { + npmTest('npm', context, function (err) { t.equals(err && err.message, 'Package.json Could not be found'); t.end(); }); @@ -86,7 +86,7 @@ test('npm-test: alternative test-path', function (t) { npmLevel: 'silly', testPath: path.resolve(__dirname, '..', 'fixtures', 'fakenodebin') }); - npmTest(context, function (err) { + npmTest('npm', context, function (err) { npmTest.__set__('nodeBinName', nodeBinName); t.equals(err && err.message, 'The canary is dead:'); t.end(); @@ -98,7 +98,7 @@ test('npm-test: timeout', function (t) { npmLevel: 'silly', timeoutLength: 100 }); - npmTest(context, function (err) { + npmTest('npm', context, function (err) { t.ok(context.module.flaky, 'Module is Flaky because tests timed out'); t.equals(err && err.message, 'Test Timed Out'); t.end(); From 6e901ebb44b086f41dd8a7250f73fa69aa2e3777 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 16 Apr 2018 07:23:32 +0200 Subject: [PATCH 02/28] chore: install yarn on Travis CI --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 9d0683d07..90fa0776e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: node_js +before_install: curl -o- -L https://yarnpkg.com/install.sh | bash os: - linux - osx From 2714b8ad75c8dbee34a46573d21465166e3fc45e Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 23 Oct 2018 10:25:04 +0200 Subject: [PATCH 03/28] PR feedback --- lib/package-manager/install.js | 4 ++-- lib/package-manager/test.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/package-manager/install.js b/lib/package-manager/install.js index a0cad3a74..ceb726e02 100644 --- a/lib/package-manager/install.js +++ b/lib/package-manager/install.js @@ -49,11 +49,11 @@ function install(packageManager, context, next) { chunk.toString()); }); - proc.on('error', function () { + proc.on('error', function() { return finish(new Error('Install Failed')); }); - proc.on('close', function (code) { + proc.on('close', function(code) { if (code > 0) { return finish(Error('Install Failed')); } diff --git a/lib/package-manager/test.js b/lib/package-manager/test.js index c40d81ccc..c351a2eab 100644 --- a/lib/package-manager/test.js +++ b/lib/package-manager/test.js @@ -54,7 +54,7 @@ function test(packageManager, context, next) { let packageManagerBin; if (useYarn) { - which(yarnBinName, {path: options.env.PATH + packageManagerBin = which(yarnBinName, {path: options.env.PATH || process.env.PATH}); } else { packageManagerBin = which(npmBinName, {path: options.env.PATH From 126ce60693f378b75ba796dd884955f3e7a5d975 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 23 Oct 2018 10:57:32 +0200 Subject: [PATCH 04/28] explicitly add yarn to `$PATH` --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 90fa0776e..77ddd3589 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,7 @@ language: node_js -before_install: curl -o- -L https://yarnpkg.com/install.sh | bash +before_install: + - curl -o- -L https://yarnpkg.com/install.sh | bash + - export PATH=$HOME/.yarn/bin:$PATH os: - linux - osx From 6a7013e87391cc74282004b9f4d74f27bd772cf3 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 24 Oct 2018 11:49:36 +0200 Subject: [PATCH 05/28] fix spawning of yarn process --- lib/package-manager/test.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/package-manager/test.js b/lib/package-manager/test.js index c351a2eab..3cad85e60 100644 --- a/lib/package-manager/test.js +++ b/lib/package-manager/test.js @@ -65,12 +65,13 @@ function test(packageManager, context, next) { } } - /* Run `npm test`, or `/path/to/customTest.js` if the customTest option + /* Run `npm/yarn test`, or `/path/to/customTest.js` if the customTest option was passed */ - const args = context.options.customTest ? - [context.options.customTest] : [packageManagerBin, 'test']; - - const proc = spawn(nodeBin, args, options); + const proc = context.options.customTest + ? spawn(nodeBin, [context.options.customTest], options) + // We spawn the package manager binary directly instead of via `node` t + // support it being a script instead of a JS file + : spawn(packageManagerBin, ['test'], options); const finish = timeout(context, proc, next, 'Test'); proc.stdout.on('data', function (data) { From 8904db1c254c1cdb33db445d85f5ba61e7a5ad63 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 24 Oct 2018 12:18:51 +0200 Subject: [PATCH 06/28] add tests --- test/npm/test-npm-install.js | 12 ++-- test/npm/test-npm-test.js | 20 +++--- test/yarn/test-yarn-install.js | 102 ++++++++++++++++++++++++++++++ test/yarn/test-yarn-test.js | 109 +++++++++++++++++++++++++++++++++ 4 files changed, 227 insertions(+), 16 deletions(-) create mode 100644 test/yarn/test-yarn-install.js create mode 100644 test/yarn/test-yarn-test.js diff --git a/test/npm/test-npm-install.js b/test/npm/test-npm-install.js index 29ce7499f..a3bf66584 100644 --- a/test/npm/test-npm-install.js +++ b/test/npm/test-npm-install.js @@ -8,7 +8,7 @@ const mkdirp = require('mkdirp'); const rimraf = require('rimraf'); const ncp = require('ncp'); -const npmInstall = require('../../lib/package-manager/install'); +const packageManagerInstall = require('../../lib/package-manager/install'); const makeContext = require('../helpers/make-context'); const sandbox = path.join(os.tmpdir(), 'citgm-' + Date.now()); @@ -43,7 +43,7 @@ test('npm-install: basic module', function (t) { const context = makeContext.npmContext('omg-i-pass', sandbox, { npmLevel: 'silly' }); - npmInstall('npm', context, function (err) { + packageManagerInstall('npm', context, function (err) { t.error(err); t.end(); }); @@ -56,7 +56,7 @@ test('npm-install: extra install parameters', function (t) { }, sandbox, { npmLevel: 'silly' }); - npmInstall('npm', context, function (err) { + packageManagerInstall('npm', context, function (err) { t.error(err); t.notOk(context.module.flaky, 'Module passed and is not flaky'); t.end(); @@ -67,7 +67,7 @@ test('npm-install: no package.json', function (t) { const context = makeContext.npmContext('omg-i-fail', sandbox, { npmLevel: 'silly' }); - npmInstall('npm', context, function (err) { + packageManagerInstall('npm', context, function (err) { t.equals(err && err.message, 'Install Failed'); t.notOk(context.module.flaky, 'Module failed but is not flaky'); t.end(); @@ -79,7 +79,7 @@ test('npm-install: timeout', function (t) { npmLevel: 'silly', timeoutLength: 100 }); - npmInstall('npm', context, function (err) { + packageManagerInstall('npm', context, function (err) { t.ok(context.module.flaky, 'Module is Flaky because install timed out'); t.equals(err && err.message, 'Install Timed Out'); t.end(); @@ -94,7 +94,7 @@ test('npm-install: failed install', function (t) { testOutput: /^$/, testError: /npm ERR! 404 Not [Ff]ound\s*: THIS-WILL-FAIL(@0\.0\.1)?/ }; - npmInstall('npm', context, function (err) { + packageManagerInstall('npm', context, function (err) { t.notOk(context.module.flaky, 'Module failed is not flaky'); t.equals(err && err.message, 'Install Failed'); t.match(context, expected, 'Install error reported'); diff --git a/test/npm/test-npm-test.js b/test/npm/test-npm-test.js index 9a89ac82c..352ac72ee 100644 --- a/test/npm/test-npm-test.js +++ b/test/npm/test-npm-test.js @@ -10,7 +10,7 @@ const ncp = require('ncp'); const rewire = require('rewire'); const makeContext = require('../helpers/make-context'); -const npmTest = rewire('../../lib/package-manager/test'); +const packageManagerTest = rewire('../../lib/package-manager/test'); const sandbox = path.join(os.tmpdir(), 'citgm-' + Date.now()); const fixtures = path.join(__dirname, '..', 'fixtures'); @@ -47,7 +47,7 @@ test('npm-test: basic module passing', function (t) { const context = makeContext.npmContext('omg-i-pass', sandbox, { npmLevel: 'silly' }); - npmTest('npm', context, function (err) { + packageManagerTest('npm', context, function (err) { t.error(err); t.end(); }); @@ -55,7 +55,7 @@ test('npm-test: basic module passing', function (t) { test('npm-test: basic module failing', function (t) { const context = makeContext.npmContext('omg-i-fail', sandbox); - npmTest('npm', context, function (err) { + packageManagerTest('npm', context, function (err) { t.equals(err && err.message, 'The canary is dead:'); t.end(); }); @@ -64,7 +64,7 @@ test('npm-test: basic module failing', function (t) { test('npm-test: basic module no test script', function (t) { const context = makeContext.npmContext('omg-i-do-not-support-testing', sandbox); - npmTest('npm', context, function (err) { + packageManagerTest('npm', context, function (err) { t.equals(err && err.message, 'Module does not support npm-test!'); t.end(); }); @@ -72,7 +72,7 @@ test('npm-test: basic module no test script', function (t) { test('npm-test: no package.json', function (t) { const context = makeContext.npmContext('omg-i-dont-exist', sandbox); - npmTest('npm', context, function (err) { + packageManagerTest('npm', context, function (err) { t.equals(err && err.message, 'Package.json Could not be found'); t.end(); }); @@ -80,14 +80,14 @@ test('npm-test: no package.json', function (t) { test('npm-test: alternative test-path', function (t) { // Same test as 'basic module passing', except with alt node bin which fails. - const nodeBinName = npmTest.__get__('nodeBinName'); - npmTest.__set__('nodeBinName', 'fake-node'); + const nodeBinName = packageManagerTest.__get__('nodeBinName'); + packageManagerTest.__set__('nodeBinName', 'fake-node'); const context = makeContext.npmContext('omg-i-pass', sandbox, { npmLevel: 'silly', testPath: path.resolve(__dirname, '..', 'fixtures', 'fakenodebin') }); - npmTest('npm', context, function (err) { - npmTest.__set__('nodeBinName', nodeBinName); + packageManagerTest('npm', context, function (err) { + packageManagerTest.__set__('nodeBinName', nodeBinName); t.equals(err && err.message, 'The canary is dead:'); t.end(); }); @@ -98,7 +98,7 @@ test('npm-test: timeout', function (t) { npmLevel: 'silly', timeoutLength: 100 }); - npmTest('npm', context, function (err) { + packageManagerTest('npm', context, function (err) { t.ok(context.module.flaky, 'Module is Flaky because tests timed out'); t.equals(err && err.message, 'Test Timed Out'); t.end(); diff --git a/test/yarn/test-yarn-install.js b/test/yarn/test-yarn-install.js new file mode 100644 index 000000000..ff1762af9 --- /dev/null +++ b/test/yarn/test-yarn-install.js @@ -0,0 +1,102 @@ +'use strict'; +const os = require('os'); +const path = require('path'); +const fs = require('fs'); + +const test = require('tap').test; +const mkdirp = require('mkdirp'); +const rimraf = require('rimraf'); +const ncp = require('ncp'); + +const packageManagerInstall = require('../../lib/package-manager/install'); +const makeContext = require('../helpers/make-context'); + +const sandbox = path.join(os.tmpdir(), 'citgm-' + Date.now()); +const fixtures = path.join(__dirname, '..', 'fixtures'); +const moduleFixtures = path.join(fixtures, 'omg-i-pass'); +const moduleTemp = path.join(sandbox, 'omg-i-pass'); +const extraParamFixtures = path.join(fixtures, 'omg-i-pass-with-install-param'); +const extraParamTemp = path.join(sandbox, 'omg-i-pass-with-install-param'); +const badFixtures = path.join(fixtures, 'omg-bad-tree'); +const badTemp = path.join(sandbox, 'omg-bad-tree'); + +test('yarn-install: setup', function (t) { + t.plan(7); + mkdirp(sandbox, function (err) { + t.error(err); + ncp(moduleFixtures, moduleTemp, function (e) { + t.error(e); + t.ok(fs.existsSync(path.join(moduleTemp, 'package.json'))); + }); + ncp(extraParamFixtures, extraParamTemp, function (e) { + t.error(e); + t.ok(fs.existsSync(path.join(moduleTemp, 'package.json'))); + }); + ncp(badFixtures, badTemp, function (e) { + t.error(e); + t.ok(fs.existsSync(path.join(badTemp, 'package.json'))); + }); + }); +}); + +test('yarn-install: basic module', function (t) { + const context = makeContext.npmContext('omg-i-pass', sandbox); + packageManagerInstall('yarn', context, function (err) { + t.error(err); + t.end(); + }); +}); + +test('yarn-install: extra install parameters', function (t) { + const context = makeContext.npmContext({ + name: 'omg-i-pass-with-install-param', + install: ['--extra-param'] + }, sandbox); + packageManagerInstall('yarn', context, function (err) { + t.error(err); + t.notOk(context.module.flaky, 'Module passed and is not flaky'); + t.end(); + }); +}); + +test('yarn-install: no package.json', function (t) { + const context = makeContext.npmContext('omg-i-fail', sandbox); + packageManagerInstall('yarn', context, function (err) { + t.equals(err && err.message, 'Install Failed'); + t.notOk(context.module.flaky, 'Module failed but is not flaky'); + t.end(); + }); +}); + +test('yarn-install: timeout', function (t) { + const context = makeContext.npmContext('omg-i-pass', sandbox, { + timeoutLength: 100 + }); + packageManagerInstall('yarn', context, function (err) { + t.ok(context.module.flaky, 'Module is Flaky because install timed out'); + t.equals(err && err.message, 'Install Timed Out'); + t.end(); + }); +}); + +test('yarn-install: failed install', function (t) { + const context = makeContext.npmContext('omg-bad-tree', sandbox, { + npmLevel: 'http' + }); + const expected = { + testError: /"https:\/\/registry.yarnpkg.com\/THIS-WILL-FAIL: Not found/ + }; + packageManagerInstall('yarn', context, function (err) { + t.notOk(context.module.flaky, 'Module failed is not flaky'); + t.equals(err && err.message, 'Install Failed'); + t.match(context, expected, 'Install error reported'); + t.end(); + }); +}); + +test('yarn-install: teardown', function (t) { + rimraf(sandbox, function (err) { + t.error(err); + t.end(); + }); +}); diff --git a/test/yarn/test-yarn-test.js b/test/yarn/test-yarn-test.js new file mode 100644 index 000000000..08709eeaa --- /dev/null +++ b/test/yarn/test-yarn-test.js @@ -0,0 +1,109 @@ +'use strict'; +const os = require('os'); +const path = require('path'); +const fs = require('fs'); + +const test = require('tap').test; +const mkdirp = require('mkdirp'); +const rimraf = require('rimraf'); +const ncp = require('ncp'); +const rewire = require('rewire'); + +const makeContext = require('../helpers/make-context'); +const packageManagerTest = rewire('../../lib/package-manager/test'); + +const sandbox = path.join(os.tmpdir(), 'citgm-' + Date.now()); +const fixtures = path.join(__dirname, '..', 'fixtures'); + +const passFixtures = path.join(fixtures, 'omg-i-pass'); +const passTemp = path.join(sandbox, 'omg-i-pass'); + +const failFixtures = path.join(fixtures, 'omg-i-fail'); +const failTemp = path.join(sandbox, 'omg-i-fail'); + +const badFixtures = path.join(fixtures, 'omg-i-do-not-support-testing'); +const badTemp = path.join(sandbox, 'omg-i-do-not-support-testing'); + +test('yarn-test: setup', function (t) { + t.plan(7); + mkdirp(sandbox, function (err) { + t.error(err); + ncp(passFixtures, passTemp, function (e) { + t.error(e); + t.ok(fs.existsSync(path.join(passTemp, 'package.json'))); + }); + ncp(failFixtures, failTemp, function (e) { + t.error(e); + t.ok(fs.existsSync(path.join(failTemp, 'package.json'))); + }); + ncp(badFixtures, badTemp, function (e) { + t.error(e); + t.ok(fs.existsSync(path.join(badTemp, 'package.json'))); + }); + }); +}); + +test('yarn-test: basic module passing', function (t) { + const context = makeContext.npmContext('omg-i-pass', sandbox); + packageManagerTest('yarn', context, function (err) { + t.error(err); + t.end(); + }); +}); + +test('yarn-test: basic module failing', function (t) { + const context = makeContext.npmContext('omg-i-fail', sandbox); + packageManagerTest('yarn', context, function (err) { + t.equals(err && err.message, 'The canary is dead:'); + t.end(); + }); +}); + +test('yarn-test: basic module no test script', function (t) { + const context = + makeContext.npmContext('omg-i-do-not-support-testing', sandbox); + packageManagerTest('yarn', context, function (err) { + t.equals(err && err.message, 'Module does not support yarn-test!'); + t.end(); + }); +}); + +test('yarn-test: no package.json', function (t) { + const context = makeContext.npmContext('omg-i-dont-exist', sandbox); + packageManagerTest('yarn', context, function (err) { + t.equals(err && err.message, 'Package.json Could not be found'); + t.end(); + }); +}); + +test('yarn-test: alternative test-path', function (t) { + // Same test as 'basic module passing', except with alt node bin which fails. + const nodeBinName = packageManagerTest.__get__('nodeBinName'); + packageManagerTest.__set__('nodeBinName', 'fake-node'); + const context = makeContext.npmContext('omg-i-pass', sandbox, { + testPath: path.resolve(__dirname, '..', 'fixtures', 'fakenodebin') + }); + packageManagerTest('yarn', context, function (err) { + packageManagerTest.__set__('nodeBinName', nodeBinName); + t.equals(err && err.message, 'The canary is dead:'); + t.end(); + }); +}); + +test('yarn-test: timeout', function (t) { + const context = makeContext.npmContext('omg-i-pass', sandbox, { + timeoutLength: 100 + }); + packageManagerTest('yarn', context, function (err) { + t.ok(context.module.flaky, 'Module is Flaky because tests timed out'); + t.equals(err && err.message, 'Test Timed Out'); + t.end(); + }); +}); + +test('yarn-test: teardown', function (t) { + rimraf(sandbox, function (err) { + t.error(err); + t.end(); + }); +}); From c5dbdaa36f22f670539333775cb720896e408b39 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 24 Oct 2018 12:21:58 +0200 Subject: [PATCH 07/28] skip failing tests --- test/npm/test-npm-test.js | 7 +++++-- test/yarn/test-yarn-install.js | 7 +++++-- test/yarn/test-yarn-test.js | 7 +++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/test/npm/test-npm-test.js b/test/npm/test-npm-test.js index 352ac72ee..ad3a03bc8 100644 --- a/test/npm/test-npm-test.js +++ b/test/npm/test-npm-test.js @@ -3,7 +3,9 @@ const os = require('os'); const path = require('path'); const fs = require('fs'); -const test = require('tap').test; +const tap = require('tap'); +const test = tap.test; +const skip = tap.skip; const mkdirp = require('mkdirp'); const rimraf = require('rimraf'); const ncp = require('ncp'); @@ -78,7 +80,8 @@ test('npm-test: no package.json', function (t) { }); }); -test('npm-test: alternative test-path', function (t) { +// Skipped since this does not work with shell scripts +skip('npm-test: alternative test-path', function (t) { // Same test as 'basic module passing', except with alt node bin which fails. const nodeBinName = packageManagerTest.__get__('nodeBinName'); packageManagerTest.__set__('nodeBinName', 'fake-node'); diff --git a/test/yarn/test-yarn-install.js b/test/yarn/test-yarn-install.js index ff1762af9..40484cc17 100644 --- a/test/yarn/test-yarn-install.js +++ b/test/yarn/test-yarn-install.js @@ -3,7 +3,9 @@ const os = require('os'); const path = require('path'); const fs = require('fs'); -const test = require('tap').test; +const tap = require('tap'); +const test = tap.test; +const skip = tap.skip; const mkdirp = require('mkdirp'); const rimraf = require('rimraf'); const ncp = require('ncp'); @@ -47,7 +49,8 @@ test('yarn-install: basic module', function (t) { }); }); -test('yarn-install: extra install parameters', function (t) { +// Skipped because yarn does not have the same behavior. +skip('yarn-install: extra install parameters', function (t) { const context = makeContext.npmContext({ name: 'omg-i-pass-with-install-param', install: ['--extra-param'] diff --git a/test/yarn/test-yarn-test.js b/test/yarn/test-yarn-test.js index 08709eeaa..29a2adf80 100644 --- a/test/yarn/test-yarn-test.js +++ b/test/yarn/test-yarn-test.js @@ -3,7 +3,9 @@ const os = require('os'); const path = require('path'); const fs = require('fs'); -const test = require('tap').test; +const tap = require('tap'); +const test = tap.test; +const skip = tap.skip; const mkdirp = require('mkdirp'); const rimraf = require('rimraf'); const ncp = require('ncp'); @@ -76,7 +78,8 @@ test('yarn-test: no package.json', function (t) { }); }); -test('yarn-test: alternative test-path', function (t) { +// Skipped since this does not work with shell scripts +skip('yarn-test: alternative test-path', function (t) { // Same test as 'basic module passing', except with alt node bin which fails. const nodeBinName = packageManagerTest.__get__('nodeBinName'); packageManagerTest.__set__('nodeBinName', 'fake-node'); From 9ced83df3a0d509fbd7bb053ca7fc5c8f872afff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Wed, 24 Oct 2018 19:19:05 +0200 Subject: [PATCH 08/28] Update lib/package-manager/test.js Co-Authored-By: SimenB --- lib/package-manager/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/package-manager/test.js b/lib/package-manager/test.js index 3cad85e60..ddd58e9de 100644 --- a/lib/package-manager/test.js +++ b/lib/package-manager/test.js @@ -69,7 +69,7 @@ function test(packageManager, context, next) { was passed */ const proc = context.options.customTest ? spawn(nodeBin, [context.options.customTest], options) - // We spawn the package manager binary directly instead of via `node` t + // We spawn the package manager binary directly instead of via `node` to // support it being a script instead of a JS file : spawn(packageManagerBin, ['test'], options); const finish = timeout(context, proc, next, 'Test'); From 5cb839f3d80d5be5c5ad0f93f5c5e871d34a3e1c Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 24 Oct 2018 19:21:02 +0200 Subject: [PATCH 09/28] Revert "skip failing tests" This reverts commit 02cb5abad0b2c3fefd13fa5c5b6c0ebefae46dc5. --- test/npm/test-npm-test.js | 7 ++----- test/yarn/test-yarn-install.js | 7 ++----- test/yarn/test-yarn-test.js | 7 ++----- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/test/npm/test-npm-test.js b/test/npm/test-npm-test.js index ad3a03bc8..352ac72ee 100644 --- a/test/npm/test-npm-test.js +++ b/test/npm/test-npm-test.js @@ -3,9 +3,7 @@ const os = require('os'); const path = require('path'); const fs = require('fs'); -const tap = require('tap'); -const test = tap.test; -const skip = tap.skip; +const test = require('tap').test; const mkdirp = require('mkdirp'); const rimraf = require('rimraf'); const ncp = require('ncp'); @@ -80,8 +78,7 @@ test('npm-test: no package.json', function (t) { }); }); -// Skipped since this does not work with shell scripts -skip('npm-test: alternative test-path', function (t) { +test('npm-test: alternative test-path', function (t) { // Same test as 'basic module passing', except with alt node bin which fails. const nodeBinName = packageManagerTest.__get__('nodeBinName'); packageManagerTest.__set__('nodeBinName', 'fake-node'); diff --git a/test/yarn/test-yarn-install.js b/test/yarn/test-yarn-install.js index 40484cc17..ff1762af9 100644 --- a/test/yarn/test-yarn-install.js +++ b/test/yarn/test-yarn-install.js @@ -3,9 +3,7 @@ const os = require('os'); const path = require('path'); const fs = require('fs'); -const tap = require('tap'); -const test = tap.test; -const skip = tap.skip; +const test = require('tap').test; const mkdirp = require('mkdirp'); const rimraf = require('rimraf'); const ncp = require('ncp'); @@ -49,8 +47,7 @@ test('yarn-install: basic module', function (t) { }); }); -// Skipped because yarn does not have the same behavior. -skip('yarn-install: extra install parameters', function (t) { +test('yarn-install: extra install parameters', function (t) { const context = makeContext.npmContext({ name: 'omg-i-pass-with-install-param', install: ['--extra-param'] diff --git a/test/yarn/test-yarn-test.js b/test/yarn/test-yarn-test.js index 29a2adf80..08709eeaa 100644 --- a/test/yarn/test-yarn-test.js +++ b/test/yarn/test-yarn-test.js @@ -3,9 +3,7 @@ const os = require('os'); const path = require('path'); const fs = require('fs'); -const tap = require('tap'); -const test = tap.test; -const skip = tap.skip; +const test = require('tap').test; const mkdirp = require('mkdirp'); const rimraf = require('rimraf'); const ncp = require('ncp'); @@ -78,8 +76,7 @@ test('yarn-test: no package.json', function (t) { }); }); -// Skipped since this does not work with shell scripts -skip('yarn-test: alternative test-path', function (t) { +test('yarn-test: alternative test-path', function (t) { // Same test as 'basic module passing', except with alt node bin which fails. const nodeBinName = packageManagerTest.__get__('nodeBinName'); packageManagerTest.__set__('nodeBinName', 'fake-node'); From 190877f0d7d8a5fb4b76994c0f7e016c6082e077 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 24 Oct 2018 19:28:53 +0200 Subject: [PATCH 10/28] remove invalid test for yarn --- test/yarn/test-yarn-install.js | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/test/yarn/test-yarn-install.js b/test/yarn/test-yarn-install.js index ff1762af9..e1b800a4c 100644 --- a/test/yarn/test-yarn-install.js +++ b/test/yarn/test-yarn-install.js @@ -47,18 +47,6 @@ test('yarn-install: basic module', function (t) { }); }); -test('yarn-install: extra install parameters', function (t) { - const context = makeContext.npmContext({ - name: 'omg-i-pass-with-install-param', - install: ['--extra-param'] - }, sandbox); - packageManagerInstall('yarn', context, function (err) { - t.error(err); - t.notOk(context.module.flaky, 'Module passed and is not flaky'); - t.end(); - }); -}); - test('yarn-install: no package.json', function (t) { const context = makeContext.npmContext('omg-i-fail', sandbox); packageManagerInstall('yarn', context, function (err) { From 938fec5611932d3d3a0646ec2a4e4b1addd4c262 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 24 Oct 2018 19:41:07 +0200 Subject: [PATCH 11/28] install yarn from npm --- lib/citgm.js | 11 ++++++++++- lib/package-manager/install.js | 23 ++++++++++++++++++++++- lib/package-manager/test.js | 13 +++++++------ package.json | 4 +++- 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/lib/citgm.js b/lib/citgm.js index 6fe660773..aadb9e35c 100644 --- a/lib/citgm.js +++ b/lib/citgm.js @@ -6,6 +6,7 @@ const async = require('async'); const npa = require('npm-package-arg'); const BufferList = require('bl'); let which = require('which'); // Mocked in tests +const npmWhich = require('npm-which')(__dirname); const grabModuleData = require('./grab-module-data'); const grabProject = require('./grab-project'); @@ -32,7 +33,15 @@ exports.windows = windows; function find(app, context, next) { which(app, function(err, resolved) { if (err) { - next(Error(app + ' not found in path!')); + npmWhich(app, function(err, resolved) { + if (err) { + next(Error(app + ' not found in path!')); + return; + } + + context.emit('data', 'verbose', context.module.name + ' using-' + app, + resolved); + }); return; } context.emit('data', 'verbose', context.module.name + ' using-' + app, diff --git a/lib/package-manager/install.js b/lib/package-manager/install.js index ceb726e02..b3b80dd74 100644 --- a/lib/package-manager/install.js +++ b/lib/package-manager/install.js @@ -2,12 +2,18 @@ const path = require('path'); const stripAnsi = require('strip-ansi'); +const which = require('which').sync; +const npmWhich = require('npm-which')(__dirname).sync; const createOptions = require('../create-options'); const spawn = require('../spawn'); const timeout = require('../timeout'); +const windows = (process.platform === 'win32'); +const npmBinName = 'npm'; +const yarnBinName = 'yarn'; function install(packageManager, context, next) { + const useYarn = packageManager === 'yarn'; const options = createOptions( path.join(context.path, context.module.name), context); @@ -24,7 +30,22 @@ function install(packageManager, context, next) { args = args.concat(context.module.install); } - const proc = spawn(packageManager, args, options); + let packageManagerBin; + + if (useYarn) { + // Use `npm-which` for yarn to get the locally version + packageManagerBin = npmWhich(yarnBinName, {path: options.env.PATH + || process.env.PATH}); + } else { + packageManagerBin = which(npmBinName, {path: options.env.PATH + || process.env.PATH}); + if (windows) { + packageManagerBin = path.join(path.dirname(packageManagerBin), + 'node_modules', 'npm', 'bin', 'npm-cli.js'); + } + } + + const proc = spawn(packageManagerBin, args, options); const finish = timeout(context, proc, next, 'Install'); proc.stderr.on('data', function (chunk) { diff --git a/lib/package-manager/test.js b/lib/package-manager/test.js index ddd58e9de..58e71cb1e 100644 --- a/lib/package-manager/test.js +++ b/lib/package-manager/test.js @@ -4,6 +4,7 @@ const path = require('path'); const readPackage = require('read-package-json'); const stripAnsi = require('strip-ansi'); const which = require('which').sync; +const npmWhich = require('npm-which')(__dirname).sync; const createOptions = require('../create-options'); const spawn = require('../spawn'); @@ -54,7 +55,8 @@ function test(packageManager, context, next) { let packageManagerBin; if (useYarn) { - packageManagerBin = which(yarnBinName, {path: options.env.PATH + // Use `npm-which` for yarn to get the locally version + packageManagerBin = npmWhich(yarnBinName, {path: options.env.PATH || process.env.PATH}); } else { packageManagerBin = which(npmBinName, {path: options.env.PATH @@ -67,11 +69,10 @@ function test(packageManager, context, next) { /* Run `npm/yarn test`, or `/path/to/customTest.js` if the customTest option was passed */ - const proc = context.options.customTest - ? spawn(nodeBin, [context.options.customTest], options) - // We spawn the package manager binary directly instead of via `node` to - // support it being a script instead of a JS file - : spawn(packageManagerBin, ['test'], options); + const args = context.options.customTest ? + [context.options.customTest] : [packageManagerBin, 'test']; + + const proc = spawn(nodeBin, args, options); const finish = timeout(context, proc, next, 'Test'); proc.stdout.on('data', function (data) { diff --git a/package.json b/package.json index 673771816..e2b9f3da6 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "mkdirp": "^0.5.1", "normalize-git-url": "^3.0.2", "npm-package-arg": "^6.1.0", + "npm-which": "^3.0.1", "osenv": "^0.1.5", "read-package-json": "^2.0.13", "request": "^2.88.0", @@ -55,7 +56,8 @@ "winston": "^2.4.4", "xml-sanitizer": "^1.1.6", "xmlbuilder": "^10.1.1", - "yargs": "^12.0.2" + "yargs": "^12.0.2", + "yarn": "^1.12.3" }, "devDependencies": { "eslint": "^5.7.0", From 9352ad658ee74f9aa0511cf6002848bd11c80ce3 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 24 Oct 2018 19:50:17 +0200 Subject: [PATCH 12/28] extract package manager finder to separate module --- lib/package-manager/get-binary.js | 24 ++++++++++++++++++++++++ lib/package-manager/install.js | 22 ++-------------------- lib/package-manager/test.js | 20 ++------------------ 3 files changed, 28 insertions(+), 38 deletions(-) create mode 100644 lib/package-manager/get-binary.js diff --git a/lib/package-manager/get-binary.js b/lib/package-manager/get-binary.js new file mode 100644 index 000000000..0136f766b --- /dev/null +++ b/lib/package-manager/get-binary.js @@ -0,0 +1,24 @@ +'use strict'; + +const path = require('path'); +const which = require('which').sync; +const npmWhich = require('npm-which')(__dirname).sync; + +const windows = (process.platform === 'win32'); + +module.exports = function(binaryName, options) { + if (binaryName === 'yarn') { + // Use `npm-which` for yarn to get the locally version + return npmWhich(binaryName, {path: options.env.PATH + || process.env.PATH}); + } + + let packageManagerBin = which(binaryName, {path: options.env.PATH + || process.env.PATH}); + if (windows) { + packageManagerBin = path.join(path.dirname(packageManagerBin), + 'node_modules', 'npm', 'bin', 'npm-cli.js'); + } + + return packageManagerBin; +}; diff --git a/lib/package-manager/install.js b/lib/package-manager/install.js index b3b80dd74..fbf8790b5 100644 --- a/lib/package-manager/install.js +++ b/lib/package-manager/install.js @@ -2,18 +2,13 @@ const path = require('path'); const stripAnsi = require('strip-ansi'); -const which = require('which').sync; -const npmWhich = require('npm-which')(__dirname).sync; const createOptions = require('../create-options'); +const getBinary = require('./get-binary'); const spawn = require('../spawn'); const timeout = require('../timeout'); -const windows = (process.platform === 'win32'); -const npmBinName = 'npm'; -const yarnBinName = 'yarn'; function install(packageManager, context, next) { - const useYarn = packageManager === 'yarn'; const options = createOptions( path.join(context.path, context.module.name), context); @@ -30,20 +25,7 @@ function install(packageManager, context, next) { args = args.concat(context.module.install); } - let packageManagerBin; - - if (useYarn) { - // Use `npm-which` for yarn to get the locally version - packageManagerBin = npmWhich(yarnBinName, {path: options.env.PATH - || process.env.PATH}); - } else { - packageManagerBin = which(npmBinName, {path: options.env.PATH - || process.env.PATH}); - if (windows) { - packageManagerBin = path.join(path.dirname(packageManagerBin), - 'node_modules', 'npm', 'bin', 'npm-cli.js'); - } - } + const packageManagerBin = getBinary(packageManager, options); const proc = spawn(packageManagerBin, args, options); const finish = timeout(context, proc, next, 'Install'); diff --git a/lib/package-manager/test.js b/lib/package-manager/test.js index 58e71cb1e..fde774884 100644 --- a/lib/package-manager/test.js +++ b/lib/package-manager/test.js @@ -4,16 +4,13 @@ const path = require('path'); const readPackage = require('read-package-json'); const stripAnsi = require('strip-ansi'); const which = require('which').sync; -const npmWhich = require('npm-which')(__dirname).sync; const createOptions = require('../create-options'); +const getBinary = require('./get-binary'); const spawn = require('../spawn'); const timeout = require('../timeout'); -const windows = (process.platform === 'win32'); let nodeBinName = 'node'; // Mocked in tests -const npmBinName = 'npm'; -const yarnBinName = 'yarn'; function authorName(author) { if (typeof author === 'string') return author; @@ -25,7 +22,6 @@ function authorName(author) { } function test(packageManager, context, next) { - const useYarn = packageManager === 'yarn'; const wd = path.join(context.path, context.module.name); context.emit('data', 'info', context.module.name + ' ' + packageManager + ':', 'test suite started'); @@ -52,20 +48,8 @@ function test(packageManager, context, next) { nodeBin = which(nodeBinName, {path: options.env.PATH || process.env.PATH}); } - let packageManagerBin; - if (useYarn) { - // Use `npm-which` for yarn to get the locally version - packageManagerBin = npmWhich(yarnBinName, {path: options.env.PATH - || process.env.PATH}); - } else { - packageManagerBin = which(npmBinName, {path: options.env.PATH - || process.env.PATH}); - if (windows) { - packageManagerBin = path.join(path.dirname(packageManagerBin), - 'node_modules', 'npm', 'bin', 'npm-cli.js'); - } - } + const packageManagerBin = getBinary(packageManager, options); /* Run `npm/yarn test`, or `/path/to/customTest.js` if the customTest option was passed */ From 84c73cf951fb27beeb3362abd1d2a835e599fc0d Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 24 Oct 2018 19:54:45 +0200 Subject: [PATCH 13/28] don't install yarn in .travis.yml --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 77ddd3589..9d0683d07 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,4 @@ language: node_js -before_install: - - curl -o- -L https://yarnpkg.com/install.sh | bash - - export PATH=$HOME/.yarn/bin:$PATH os: - linux - osx From 3becd4dcab0dd5ddf066ae50534f19f342b4e784 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 24 Oct 2018 19:58:56 +0200 Subject: [PATCH 14/28] name function [skip ci] --- lib/package-manager/get-binary.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/package-manager/get-binary.js b/lib/package-manager/get-binary.js index 0136f766b..0c2d8babd 100644 --- a/lib/package-manager/get-binary.js +++ b/lib/package-manager/get-binary.js @@ -6,7 +6,7 @@ const npmWhich = require('npm-which')(__dirname).sync; const windows = (process.platform === 'win32'); -module.exports = function(binaryName, options) { +module.exports = function getBinary(binaryName, options) { if (binaryName === 'yarn') { // Use `npm-which` for yarn to get the locally version return npmWhich(binaryName, {path: options.env.PATH From b6f99c13b94b5820f3091e44db35bd1434256383 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Wed, 24 Oct 2018 22:18:10 +0200 Subject: [PATCH 15/28] fix find when bin is not in PATH --- lib/citgm.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/citgm.js b/lib/citgm.js index aadb9e35c..511af206e 100644 --- a/lib/citgm.js +++ b/lib/citgm.js @@ -41,6 +41,7 @@ function find(app, context, next) { context.emit('data', 'verbose', context.module.name + ' using-' + app, resolved); + next(null, context); }); return; } From 61f3b3d0df14c19badfe92abf0a4a58b47bb1cf4 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 24 Oct 2018 22:23:08 +0200 Subject: [PATCH 16/28] run custom test script and try to add yarn to path --- lib/lookup.js | 3 +++ lib/lookup.json | 10 ++++++++++ lib/package-manager/install.js | 3 +++ lib/package-manager/test.js | 8 ++++++-- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/lookup.js b/lib/lookup.js index 35a2ea431..1c7aef0d4 100644 --- a/lib/lookup.js +++ b/lib/lookup.js @@ -117,6 +117,9 @@ function resolve(context, next) { if (rep.yarn) { context.module.useYarn = true; } + if (rep.customTestScript) { + context.module.customTestScript = rep.customTestScript; + } context.module.flaky = context.options.failFlaky ? false : isMatch(rep.flaky); context.module.expectFail = context.options.expectFail ? diff --git a/lib/lookup.json b/lib/lookup.json index 161b9414d..381544097 100644 --- a/lib/lookup.json +++ b/lib/lookup.json @@ -504,5 +504,15 @@ "@nearform/bubbleprof": { "maintainers": ["mcollina", "BridgeAR"], "prefix": "v" + }, + "jest": { + "maintainers": ["cpojer", "SimenB"], + "prefix": "v", + "customTestScript": "test-ci-partial", + "yarn": true, + "stripAnsi": true, + "envVar": { + "FORCE_COLOR": 1 + } } } diff --git a/lib/package-manager/install.js b/lib/package-manager/install.js index fbf8790b5..2f81036a0 100644 --- a/lib/package-manager/install.js +++ b/lib/package-manager/install.js @@ -27,6 +27,9 @@ function install(packageManager, context, next) { const packageManagerBin = getBinary(packageManager, options); + const binDirectory = path.dirname(packageManagerBin); + options.env.PATH = binDirectory + ':' + process.env.PATH; + const proc = spawn(packageManagerBin, args, options); const finish = timeout(context, proc, next, 'Install'); diff --git a/lib/package-manager/test.js b/lib/package-manager/test.js index fde774884..935d0fb21 100644 --- a/lib/package-manager/test.js +++ b/lib/package-manager/test.js @@ -51,10 +51,14 @@ function test(packageManager, context, next) { const packageManagerBin = getBinary(packageManager, options); + const binDirectory = path.dirname(packageManagerBin); + options.env.PATH = binDirectory + ':' + process.env.PATH; + /* Run `npm/yarn test`, or `/path/to/customTest.js` if the customTest option was passed */ - const args = context.options.customTest ? - [context.options.customTest] : [packageManagerBin, 'test']; + const args = context.options.customTest + ? [context.options.customTest] + : [packageManagerBin, context.module.customTestScript || 'test']; const proc = spawn(nodeBin, args, options); const finish = timeout(context, proc, next, 'Test'); From fb3ea5a107d45ce7143da472edf4da5c11d9d007 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 24 Oct 2018 23:58:55 +0200 Subject: [PATCH 17/28] remove custom test script --- lib/lookup.js | 3 --- lib/lookup.json | 10 ---------- lib/package-manager/test.js | 5 ++--- 3 files changed, 2 insertions(+), 16 deletions(-) diff --git a/lib/lookup.js b/lib/lookup.js index 1c7aef0d4..35a2ea431 100644 --- a/lib/lookup.js +++ b/lib/lookup.js @@ -117,9 +117,6 @@ function resolve(context, next) { if (rep.yarn) { context.module.useYarn = true; } - if (rep.customTestScript) { - context.module.customTestScript = rep.customTestScript; - } context.module.flaky = context.options.failFlaky ? false : isMatch(rep.flaky); context.module.expectFail = context.options.expectFail ? diff --git a/lib/lookup.json b/lib/lookup.json index 381544097..161b9414d 100644 --- a/lib/lookup.json +++ b/lib/lookup.json @@ -504,15 +504,5 @@ "@nearform/bubbleprof": { "maintainers": ["mcollina", "BridgeAR"], "prefix": "v" - }, - "jest": { - "maintainers": ["cpojer", "SimenB"], - "prefix": "v", - "customTestScript": "test-ci-partial", - "yarn": true, - "stripAnsi": true, - "envVar": { - "FORCE_COLOR": 1 - } } } diff --git a/lib/package-manager/test.js b/lib/package-manager/test.js index 935d0fb21..bcc0ae31b 100644 --- a/lib/package-manager/test.js +++ b/lib/package-manager/test.js @@ -56,9 +56,8 @@ function test(packageManager, context, next) { /* Run `npm/yarn test`, or `/path/to/customTest.js` if the customTest option was passed */ - const args = context.options.customTest - ? [context.options.customTest] - : [packageManagerBin, context.module.customTestScript || 'test']; + const args = context.options.customTest ? + [context.options.customTest] : [packageManagerBin, 'test']; const proc = spawn(nodeBin, args, options); const finish = timeout(context, proc, next, 'Test'); From ede6a95b3d0dbc4acc5d182c0ebe054e24a56962 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Thu, 25 Oct 2018 00:04:56 +0200 Subject: [PATCH 18/28] fix tests --- lib/citgm.js | 4 ++-- test/test-citgm.js | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/citgm.js b/lib/citgm.js index 511af206e..2a81c87a0 100644 --- a/lib/citgm.js +++ b/lib/citgm.js @@ -6,7 +6,7 @@ const async = require('async'); const npa = require('npm-package-arg'); const BufferList = require('bl'); let which = require('which'); // Mocked in tests -const npmWhich = require('npm-which')(__dirname); +let npmWhich = require('npm-which'); // Mocked in tests const grabModuleData = require('./grab-module-data'); const grabProject = require('./grab-project'); @@ -33,7 +33,7 @@ exports.windows = windows; function find(app, context, next) { which(app, function(err, resolved) { if (err) { - npmWhich(app, function(err, resolved) { + npmWhich(__dirname)(app, function(err, resolved) { if (err) { next(Error(app + ' not found in path!')); return; diff --git a/test/test-citgm.js b/test/test-citgm.js index 62239f31d..54b8d732b 100644 --- a/test/test-citgm.js +++ b/test/test-citgm.js @@ -50,12 +50,19 @@ test('citgm: omg-i-pass from git url', function (t) { test('citgm: internal function find with error', function (t) { const which = citgm.__get__('which'); + const npmWhich = citgm.__get__('npmWhich'); citgm.__set__('which', function (app, next) { return next('Error'); }); + citgm.__set__('npmWhich', function () { + return function (app, next) { + return next('Error'); + }; + }); find(undefined, undefined, function (err) { t.equals(err && err.message, 'undefined not found in path!'); citgm.__set__('which', which); + citgm.__set__('npmWhich', npmWhich); t.end(); }); }); From 99df018fd87cd79cba3beb2c7ddd03ad94daaf50 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Thu, 25 Oct 2018 00:09:31 +0200 Subject: [PATCH 19/28] remove uknown flag from yarn call --- test/yarn/test-yarn-install.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/yarn/test-yarn-install.js b/test/yarn/test-yarn-install.js index e1b800a4c..deed5123e 100644 --- a/test/yarn/test-yarn-install.js +++ b/test/yarn/test-yarn-install.js @@ -68,9 +68,7 @@ test('yarn-install: timeout', function (t) { }); test('yarn-install: failed install', function (t) { - const context = makeContext.npmContext('omg-bad-tree', sandbox, { - npmLevel: 'http' - }); + const context = makeContext.npmContext('omg-bad-tree', sandbox); const expected = { testError: /"https:\/\/registry.yarnpkg.com\/THIS-WILL-FAIL: Not found/ }; From 4e4cfa6d5337b06790b11a651327e394468878d2 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Thu, 25 Oct 2018 07:43:03 +0200 Subject: [PATCH 20/28] stringify buffers in test --- test/yarn/test-yarn-install.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/yarn/test-yarn-install.js b/test/yarn/test-yarn-install.js index deed5123e..2d12f612b 100644 --- a/test/yarn/test-yarn-install.js +++ b/test/yarn/test-yarn-install.js @@ -42,6 +42,8 @@ test('yarn-install: setup', function (t) { test('yarn-install: basic module', function (t) { const context = makeContext.npmContext('omg-i-pass', sandbox); packageManagerInstall('yarn', context, function (err) { + context.testOutput = context.testOutput.toString(); + context.testError = context.testError.toString(); t.error(err); t.end(); }); @@ -50,6 +52,8 @@ test('yarn-install: basic module', function (t) { test('yarn-install: no package.json', function (t) { const context = makeContext.npmContext('omg-i-fail', sandbox); packageManagerInstall('yarn', context, function (err) { + context.testOutput = context.testOutput.toString(); + context.testError = context.testError.toString(); t.equals(err && err.message, 'Install Failed'); t.notOk(context.module.flaky, 'Module failed but is not flaky'); t.end(); @@ -61,6 +65,8 @@ test('yarn-install: timeout', function (t) { timeoutLength: 100 }); packageManagerInstall('yarn', context, function (err) { + context.testOutput = context.testOutput.toString(); + context.testError = context.testError.toString(); t.ok(context.module.flaky, 'Module is Flaky because install timed out'); t.equals(err && err.message, 'Install Timed Out'); t.end(); @@ -73,6 +79,8 @@ test('yarn-install: failed install', function (t) { testError: /"https:\/\/registry.yarnpkg.com\/THIS-WILL-FAIL: Not found/ }; packageManagerInstall('yarn', context, function (err) { + context.testOutput = context.testOutput.toString(); + context.testError = context.testError.toString(); t.notOk(context.module.flaky, 'Module failed is not flaky'); t.equals(err && err.message, 'Install Failed'); t.match(context, expected, 'Install error reported'); From 6829ba8bb36b21d0bbf933fc0d0cac55fac03ef7 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Thu, 25 Oct 2018 07:50:23 +0200 Subject: [PATCH 21/28] tweak assertion --- test/yarn/test-yarn-install.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/yarn/test-yarn-install.js b/test/yarn/test-yarn-install.js index 2d12f612b..a81d020b5 100644 --- a/test/yarn/test-yarn-install.js +++ b/test/yarn/test-yarn-install.js @@ -76,7 +76,7 @@ test('yarn-install: timeout', function (t) { test('yarn-install: failed install', function (t) { const context = makeContext.npmContext('omg-bad-tree', sandbox); const expected = { - testError: /"https:\/\/registry.yarnpkg.com\/THIS-WILL-FAIL: Not found/ + testError: /\/THIS-WILL-FAIL: Not found/ }; packageManagerInstall('yarn', context, function (err) { context.testOutput = context.testOutput.toString(); From 013b0938dc012aa7e8ffcadbe2211897847f8e2b Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 18 Nov 2018 10:29:05 +0100 Subject: [PATCH 22/28] chore: rename file --- lib/package-manager/{get-binary.js => get-executable.js} | 0 lib/package-manager/install.js | 4 ++-- lib/package-manager/test.js | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) rename lib/package-manager/{get-binary.js => get-executable.js} (100%) diff --git a/lib/package-manager/get-binary.js b/lib/package-manager/get-executable.js similarity index 100% rename from lib/package-manager/get-binary.js rename to lib/package-manager/get-executable.js diff --git a/lib/package-manager/install.js b/lib/package-manager/install.js index 2f81036a0..1b45485c5 100644 --- a/lib/package-manager/install.js +++ b/lib/package-manager/install.js @@ -4,7 +4,7 @@ const path = require('path'); const stripAnsi = require('strip-ansi'); const createOptions = require('../create-options'); -const getBinary = require('./get-binary'); +const getExecutable = require('./get-executable'); const spawn = require('../spawn'); const timeout = require('../timeout'); @@ -25,7 +25,7 @@ function install(packageManager, context, next) { args = args.concat(context.module.install); } - const packageManagerBin = getBinary(packageManager, options); + const packageManagerBin = getExecutable(packageManager, options); const binDirectory = path.dirname(packageManagerBin); options.env.PATH = binDirectory + ':' + process.env.PATH; diff --git a/lib/package-manager/test.js b/lib/package-manager/test.js index bcc0ae31b..9aa521e83 100644 --- a/lib/package-manager/test.js +++ b/lib/package-manager/test.js @@ -6,7 +6,7 @@ const stripAnsi = require('strip-ansi'); const which = require('which').sync; const createOptions = require('../create-options'); -const getBinary = require('./get-binary'); +const getExecutable = require('./get-executable'); const spawn = require('../spawn'); const timeout = require('../timeout'); @@ -49,7 +49,7 @@ function test(packageManager, context, next) { || process.env.PATH}); } - const packageManagerBin = getBinary(packageManager, options); + const packageManagerBin = getExecutable(packageManager, options); const binDirectory = path.dirname(packageManagerBin); options.env.PATH = binDirectory + ':' + process.env.PATH; From 8f7795b35f4f4e5b3eb34724d004ce9b5e41c31a Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 21 Nov 2018 15:06:44 +0100 Subject: [PATCH 23/28] rename exported function --- lib/package-manager/get-executable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/package-manager/get-executable.js b/lib/package-manager/get-executable.js index 0c2d8babd..600e9b7da 100644 --- a/lib/package-manager/get-executable.js +++ b/lib/package-manager/get-executable.js @@ -6,7 +6,7 @@ const npmWhich = require('npm-which')(__dirname).sync; const windows = (process.platform === 'win32'); -module.exports = function getBinary(binaryName, options) { +module.exports = function getExecutable(binaryName, options) { if (binaryName === 'yarn') { // Use `npm-which` for yarn to get the locally version return npmWhich(binaryName, {path: options.env.PATH From 261d246fec3c4ddd1692cf97cc11b8675e4a3467 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 21 Nov 2018 15:11:48 +0100 Subject: [PATCH 24/28] simplify calling pkg manager install and test --- lib/package-manager/index.js | 20 ++++++++++---------- lib/package-manager/npm.js | 8 -------- lib/package-manager/yarn.js | 8 -------- 3 files changed, 10 insertions(+), 26 deletions(-) delete mode 100644 lib/package-manager/npm.js delete mode 100644 lib/package-manager/yarn.js diff --git a/lib/package-manager/index.js b/lib/package-manager/index.js index c8cbe6c2f..d6282adff 100644 --- a/lib/package-manager/index.js +++ b/lib/package-manager/index.js @@ -1,24 +1,24 @@ 'use strict'; -const npm = require('./npm'); -const yarn = require('./yarn'); +const install = require('./install'); +const test = require('./test'); -function install(context, next) { +function pkgInstall(context, next) { if (context.options.yarn || context.module.useYarn) { - yarn.install(context, next); + install('yarn', context, next); } else { - npm.install(context, next); + install('npm', context, next); } } -function test(context, next) { +function pkgTest(context, next) { if (context.options.yarn || context.module.useYarn) { - yarn.test(context, next); + test('yarn', context, next); } else { - npm.test(context, next); + test('npm', context, next); } } module.exports = { - install: install, - test: test + install: pkgInstall, + test: pkgTest }; diff --git a/lib/package-manager/npm.js b/lib/package-manager/npm.js deleted file mode 100644 index daf945d68..000000000 --- a/lib/package-manager/npm.js +++ /dev/null @@ -1,8 +0,0 @@ -'use strict'; -const install = require('./install'); -const test = require('./test'); - -module.exports = { - install: install.bind(null, 'npm'), - test: test.bind(null, 'npm') -}; diff --git a/lib/package-manager/yarn.js b/lib/package-manager/yarn.js deleted file mode 100644 index 07395f13c..000000000 --- a/lib/package-manager/yarn.js +++ /dev/null @@ -1,8 +0,0 @@ -'use strict'; -const install = require('./install'); -const test = require('./test'); - -module.exports = { - install: install.bind(null, 'yarn'), - test: test.bind(null, 'yarn') -}; From 9bb22dc169c359da71f307aed4ee9202da67f900 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 21 Nov 2018 16:13:17 +0100 Subject: [PATCH 25/28] cache package manager binary lookup --- lib/citgm.js | 42 +++++++++++++++++--------- lib/package-manager/get-executable.js | 28 ++++++++++------- lib/package-manager/index.js | 19 +++++++++++- lib/package-manager/install.js | 5 ++-- lib/package-manager/test.js | 5 ++-- test/helpers/make-context.js | 6 ++-- test/npm/test-npm-install.js | 41 +++++++++++++++---------- test/npm/test-npm-test.js | 43 +++++++++++++++++---------- test/test-citgm.js | 20 ------------- test/yarn/test-yarn-install.js | 25 +++++++++++----- test/yarn/test-yarn-test.js | 35 +++++++++++++++------- 11 files changed, 169 insertions(+), 100 deletions(-) diff --git a/lib/citgm.js b/lib/citgm.js index 2a81c87a0..c50a4f851 100644 --- a/lib/citgm.js +++ b/lib/citgm.js @@ -30,23 +30,38 @@ exports.windows = windows; * 5. Output the results. **/ -function find(app, context, next) { - which(app, function(err, resolved) { +function findNode(context, next) { + which('node', function(err, resolved) { if (err) { - npmWhich(__dirname)(app, function(err, resolved) { + npmWhich(__dirname)('node', function(err, resolved) { if (err) { - next(Error(app + ' not found in path!')); + next(Error('node not found in path!')); return; } - context.emit('data', 'verbose', context.module.name + ' using-' + app, + context.emit('data', 'verbose', + context.module.name + ' using-node', resolved); next(null, context); }); return; } - context.emit('data', 'verbose', context.module.name + ' using-' + app, - resolved); + context.emit('data', 'verbose', context.module.name + ' using-node', + resolved); + next(null, context); + }); +} + +function findPackageManagers(context, next) { + packageManager.getPackageManagers((err, res) => { + if (err) { + next(err); + return; + } + + context.npmPath = res.npm; + context.yarnPath = res.yarn; + next(null, context); }); } @@ -56,13 +71,13 @@ function init(context, next) { if (!windows) { if (context.options.uid) context.emit('data', 'verbose', context.module.name + ' using-uid', - context.options.uid); + context.options.uid); if (context.options.gid) context.emit('data', 'verbose', context.module.name + ' using-gid', - context.options.gid); + context.options.gid); } context.emit('data', 'silly', context.module.name + ' init-detail', - context.module); + context.module); next(null, context); // Inject the context } @@ -108,9 +123,8 @@ Tester.prototype.run = function() { async.waterfall([ init.bind(null, this), - find.bind(null, 'node'), - find.bind(null, 'npm'), - find.bind(null, 'yarn'), + findNode.bind(null), + findPackageManagers.bind(null), tempDirectory.create, grabModuleData, lookup, @@ -147,7 +161,7 @@ Tester.prototype.run = function() { }); }; -Tester.prototype.cleanup = function () { +Tester.prototype.cleanup = function() { this.cleanexit = true; const payload = { name: this.module.name || this.module.raw, diff --git a/lib/package-manager/get-executable.js b/lib/package-manager/get-executable.js index 600e9b7da..34a856587 100644 --- a/lib/package-manager/get-executable.js +++ b/lib/package-manager/get-executable.js @@ -1,24 +1,30 @@ 'use strict'; const path = require('path'); -const which = require('which').sync; -const npmWhich = require('npm-which')(__dirname).sync; +const which = require('which'); +const npmWhich = require('npm-which')(__dirname); const windows = (process.platform === 'win32'); -module.exports = function getExecutable(binaryName, options) { +module.exports = function getExecutable(binaryName, next) { if (binaryName === 'yarn') { // Use `npm-which` for yarn to get the locally version - return npmWhich(binaryName, {path: options.env.PATH - || process.env.PATH}); + npmWhich(binaryName, next); + + return; } - let packageManagerBin = which(binaryName, {path: options.env.PATH - || process.env.PATH}); - if (windows) { - packageManagerBin = path.join(path.dirname(packageManagerBin), + which(binaryName, (err, packageManagerBin) => { + if (err) { + next(err); + return; + } + + if (windows) { + packageManagerBin = path.join(path.dirname(packageManagerBin), 'node_modules', 'npm', 'bin', 'npm-cli.js'); - } + } - return packageManagerBin; + next(null, packageManagerBin); + }); }; diff --git a/lib/package-manager/index.js b/lib/package-manager/index.js index d6282adff..6bc142020 100644 --- a/lib/package-manager/index.js +++ b/lib/package-manager/index.js @@ -1,6 +1,10 @@ 'use strict'; + +const async = require('async'); + const install = require('./install'); const test = require('./test'); +const getExecutable = require('./get-executable'); function pkgInstall(context, next) { if (context.options.yarn || context.module.useYarn) { @@ -20,5 +24,18 @@ function pkgTest(context, next) { module.exports = { install: pkgInstall, - test: pkgTest + test: pkgTest, + getPackageManagers: function(next) { + async.parallel([ + getExecutable.bind(null, 'npm'), + getExecutable.bind(null, 'yarn') + ], (err, res) => { + if (err) { + next(err); + return; + } + + next(null, { npm: res[0], yarn: res[1] }); + }); + } }; diff --git a/lib/package-manager/install.js b/lib/package-manager/install.js index 1b45485c5..010a1c3bd 100644 --- a/lib/package-manager/install.js +++ b/lib/package-manager/install.js @@ -4,7 +4,6 @@ const path = require('path'); const stripAnsi = require('strip-ansi'); const createOptions = require('../create-options'); -const getExecutable = require('./get-executable'); const spawn = require('../spawn'); const timeout = require('../timeout'); @@ -25,7 +24,9 @@ function install(packageManager, context, next) { args = args.concat(context.module.install); } - const packageManagerBin = getExecutable(packageManager, options); + const packageManagerBin = packageManager === 'npm' + ? context.npmPath + : context.yarnPath; const binDirectory = path.dirname(packageManagerBin); options.env.PATH = binDirectory + ':' + process.env.PATH; diff --git a/lib/package-manager/test.js b/lib/package-manager/test.js index 9aa521e83..719707465 100644 --- a/lib/package-manager/test.js +++ b/lib/package-manager/test.js @@ -6,7 +6,6 @@ const stripAnsi = require('strip-ansi'); const which = require('which').sync; const createOptions = require('../create-options'); -const getExecutable = require('./get-executable'); const spawn = require('../spawn'); const timeout = require('../timeout'); @@ -49,7 +48,9 @@ function test(packageManager, context, next) { || process.env.PATH}); } - const packageManagerBin = getExecutable(packageManager, options); + const packageManagerBin = packageManager === 'npm' + ? context.npmPath + : context.yarnPath; const binDirectory = path.dirname(packageManagerBin); options.env.PATH = binDirectory + ':' + process.env.PATH; diff --git a/test/helpers/make-context.js b/test/helpers/make-context.js index ff412d412..77315907d 100644 --- a/test/helpers/make-context.js +++ b/test/helpers/make-context.js @@ -2,7 +2,7 @@ const BufferList = require('bl'); -function npmContext(mod, path, options) { +function npmContext(mod, packageManagers, path, options) { if (typeof mod === 'string') { mod = { name: mod @@ -16,7 +16,9 @@ function npmContext(mod, path, options) { testOutput: new BufferList(), testError: new BufferList(), meta: {}, - options: options + options: options, + npmPath: packageManagers.npm, + yarnPath: packageManagers.yarn }; return context; } diff --git a/test/npm/test-npm-install.js b/test/npm/test-npm-install.js index a3bf66584..d93cd46c9 100644 --- a/test/npm/test-npm-install.js +++ b/test/npm/test-npm-install.js @@ -8,6 +8,7 @@ const mkdirp = require('mkdirp'); const rimraf = require('rimraf'); const ncp = require('ncp'); +const packageManager = require('../../lib/package-manager'); const packageManagerInstall = require('../../lib/package-manager/install'); const makeContext = require('../helpers/make-context'); @@ -20,8 +21,14 @@ const extraParamTemp = path.join(sandbox, 'omg-i-pass-with-install-param'); const badFixtures = path.join(fixtures, 'omg-bad-tree'); const badTemp = path.join(sandbox, 'omg-bad-tree'); +let packageManagers; + test('npm-install: setup', function (t) { - t.plan(7); + t.plan(8); + packageManager.getPackageManagers((e, res) => { + packageManagers = res; + t.error(e); + }); mkdirp(sandbox, function (err) { t.error(err); ncp(moduleFixtures, moduleTemp, function (e) { @@ -40,9 +47,10 @@ test('npm-install: setup', function (t) { }); test('npm-install: basic module', function (t) { - const context = makeContext.npmContext('omg-i-pass', sandbox, { - npmLevel: 'silly' - }); + const context = makeContext.npmContext('omg-i-pass', packageManagers, + sandbox, { + npmLevel: 'silly' + }); packageManagerInstall('npm', context, function (err) { t.error(err); t.end(); @@ -53,7 +61,7 @@ test('npm-install: extra install parameters', function (t) { const context = makeContext.npmContext({ name: 'omg-i-pass-with-install-param', install: ['--extra-param'] - }, sandbox, { + }, packageManagers, sandbox, { npmLevel: 'silly' }); packageManagerInstall('npm', context, function (err) { @@ -64,9 +72,10 @@ test('npm-install: extra install parameters', function (t) { }); test('npm-install: no package.json', function (t) { - const context = makeContext.npmContext('omg-i-fail', sandbox, { - npmLevel: 'silly' - }); + const context = makeContext.npmContext('omg-i-fail', packageManagers, + sandbox, { + npmLevel: 'silly' + }); packageManagerInstall('npm', context, function (err) { t.equals(err && err.message, 'Install Failed'); t.notOk(context.module.flaky, 'Module failed but is not flaky'); @@ -75,10 +84,11 @@ test('npm-install: no package.json', function (t) { }); test('npm-install: timeout', function (t) { - const context = makeContext.npmContext('omg-i-pass', sandbox, { - npmLevel: 'silly', - timeoutLength: 100 - }); + const context = makeContext.npmContext('omg-i-pass', packageManagers, + sandbox, { + npmLevel: 'silly', + timeoutLength: 100 + }); packageManagerInstall('npm', context, function (err) { t.ok(context.module.flaky, 'Module is Flaky because install timed out'); t.equals(err && err.message, 'Install Timed Out'); @@ -87,9 +97,10 @@ test('npm-install: timeout', function (t) { }); test('npm-install: failed install', function (t) { - const context = makeContext.npmContext('omg-bad-tree', sandbox, { - npmLevel: 'http' - }); + const context = makeContext.npmContext('omg-bad-tree', packageManagers, + sandbox, { + npmLevel: 'http' + }); const expected = { testOutput: /^$/, testError: /npm ERR! 404 Not [Ff]ound\s*: THIS-WILL-FAIL(@0\.0\.1)?/ diff --git a/test/npm/test-npm-test.js b/test/npm/test-npm-test.js index 352ac72ee..867150ce5 100644 --- a/test/npm/test-npm-test.js +++ b/test/npm/test-npm-test.js @@ -10,6 +10,7 @@ const ncp = require('ncp'); const rewire = require('rewire'); const makeContext = require('../helpers/make-context'); +const packageManager = require('../../lib/package-manager'); const packageManagerTest = rewire('../../lib/package-manager/test'); const sandbox = path.join(os.tmpdir(), 'citgm-' + Date.now()); @@ -24,8 +25,14 @@ const failTemp = path.join(sandbox, 'omg-i-fail'); const badFixtures = path.join(fixtures, 'omg-i-do-not-support-testing'); const badTemp = path.join(sandbox, 'omg-i-do-not-support-testing'); +let packageManagers; + test('npm-test: setup', function (t) { - t.plan(7); + t.plan(8); + packageManager.getPackageManagers((e, res) => { + packageManagers = res; + t.error(e); + }); mkdirp(sandbox, function (err) { t.error(err); ncp(passFixtures, passTemp, function (e) { @@ -44,9 +51,10 @@ test('npm-test: setup', function (t) { }); test('npm-test: basic module passing', function (t) { - const context = makeContext.npmContext('omg-i-pass', sandbox, { - npmLevel: 'silly' - }); + const context = makeContext.npmContext('omg-i-pass', packageManagers, + sandbox, { + npmLevel: 'silly' + }); packageManagerTest('npm', context, function (err) { t.error(err); t.end(); @@ -54,7 +62,8 @@ test('npm-test: basic module passing', function (t) { }); test('npm-test: basic module failing', function (t) { - const context = makeContext.npmContext('omg-i-fail', sandbox); + const context = makeContext.npmContext('omg-i-fail', packageManagers, + sandbox); packageManagerTest('npm', context, function (err) { t.equals(err && err.message, 'The canary is dead:'); t.end(); @@ -63,7 +72,8 @@ test('npm-test: basic module failing', function (t) { test('npm-test: basic module no test script', function (t) { const context = - makeContext.npmContext('omg-i-do-not-support-testing', sandbox); + makeContext.npmContext('omg-i-do-not-support-testing', packageManagers, + sandbox); packageManagerTest('npm', context, function (err) { t.equals(err && err.message, 'Module does not support npm-test!'); t.end(); @@ -71,7 +81,8 @@ test('npm-test: basic module no test script', function (t) { }); test('npm-test: no package.json', function (t) { - const context = makeContext.npmContext('omg-i-dont-exist', sandbox); + const context = makeContext.npmContext('omg-i-dont-exist', packageManagers, + sandbox); packageManagerTest('npm', context, function (err) { t.equals(err && err.message, 'Package.json Could not be found'); t.end(); @@ -82,10 +93,11 @@ test('npm-test: alternative test-path', function (t) { // Same test as 'basic module passing', except with alt node bin which fails. const nodeBinName = packageManagerTest.__get__('nodeBinName'); packageManagerTest.__set__('nodeBinName', 'fake-node'); - const context = makeContext.npmContext('omg-i-pass', sandbox, { - npmLevel: 'silly', - testPath: path.resolve(__dirname, '..', 'fixtures', 'fakenodebin') - }); + const context = makeContext.npmContext('omg-i-pass', packageManagers, + sandbox, { + npmLevel: 'silly', + testPath: path.resolve(__dirname, '..', 'fixtures', 'fakenodebin') + }); packageManagerTest('npm', context, function (err) { packageManagerTest.__set__('nodeBinName', nodeBinName); t.equals(err && err.message, 'The canary is dead:'); @@ -94,10 +106,11 @@ test('npm-test: alternative test-path', function (t) { }); test('npm-test: timeout', function (t) { - const context = makeContext.npmContext('omg-i-pass', sandbox, { - npmLevel: 'silly', - timeoutLength: 100 - }); + const context = makeContext.npmContext('omg-i-pass', packageManagers, + sandbox, { + npmLevel: 'silly', + timeoutLength: 100 + }); packageManagerTest('npm', context, function (err) { t.ok(context.module.flaky, 'Module is Flaky because tests timed out'); t.equals(err && err.message, 'Test Timed Out'); diff --git a/test/test-citgm.js b/test/test-citgm.js index 54b8d732b..d2b114ece 100644 --- a/test/test-citgm.js +++ b/test/test-citgm.js @@ -4,7 +4,6 @@ const test = require('tap').test; const rewire = require('rewire'); const citgm = rewire('../lib/citgm'); -const find = citgm.__get__('find'); test('citgm: omg-i-pass', function (t) { const options = { @@ -47,22 +46,3 @@ test('citgm: omg-i-pass from git url', function (t) { t.end(); }).run(); }); - -test('citgm: internal function find with error', function (t) { - const which = citgm.__get__('which'); - const npmWhich = citgm.__get__('npmWhich'); - citgm.__set__('which', function (app, next) { - return next('Error'); - }); - citgm.__set__('npmWhich', function () { - return function (app, next) { - return next('Error'); - }; - }); - find(undefined, undefined, function (err) { - t.equals(err && err.message, 'undefined not found in path!'); - citgm.__set__('which', which); - citgm.__set__('npmWhich', npmWhich); - t.end(); - }); -}); diff --git a/test/yarn/test-yarn-install.js b/test/yarn/test-yarn-install.js index a81d020b5..d7d07e573 100644 --- a/test/yarn/test-yarn-install.js +++ b/test/yarn/test-yarn-install.js @@ -8,6 +8,7 @@ const mkdirp = require('mkdirp'); const rimraf = require('rimraf'); const ncp = require('ncp'); +const packageManager = require('../../lib/package-manager'); const packageManagerInstall = require('../../lib/package-manager/install'); const makeContext = require('../helpers/make-context'); @@ -20,8 +21,14 @@ const extraParamTemp = path.join(sandbox, 'omg-i-pass-with-install-param'); const badFixtures = path.join(fixtures, 'omg-bad-tree'); const badTemp = path.join(sandbox, 'omg-bad-tree'); +let packageManagers; + test('yarn-install: setup', function (t) { - t.plan(7); + t.plan(8); + packageManager.getPackageManagers((e, res) => { + packageManagers = res; + t.error(e); + }); mkdirp(sandbox, function (err) { t.error(err); ncp(moduleFixtures, moduleTemp, function (e) { @@ -40,7 +47,8 @@ test('yarn-install: setup', function (t) { }); test('yarn-install: basic module', function (t) { - const context = makeContext.npmContext('omg-i-pass', sandbox); + const context = makeContext.npmContext('omg-i-pass', packageManagers, + sandbox); packageManagerInstall('yarn', context, function (err) { context.testOutput = context.testOutput.toString(); context.testError = context.testError.toString(); @@ -50,7 +58,8 @@ test('yarn-install: basic module', function (t) { }); test('yarn-install: no package.json', function (t) { - const context = makeContext.npmContext('omg-i-fail', sandbox); + const context = makeContext.npmContext('omg-i-fail', packageManagers, + sandbox); packageManagerInstall('yarn', context, function (err) { context.testOutput = context.testOutput.toString(); context.testError = context.testError.toString(); @@ -61,9 +70,10 @@ test('yarn-install: no package.json', function (t) { }); test('yarn-install: timeout', function (t) { - const context = makeContext.npmContext('omg-i-pass', sandbox, { - timeoutLength: 100 - }); + const context = makeContext.npmContext('omg-i-pass', packageManagers, + sandbox, { + timeoutLength: 100 + }); packageManagerInstall('yarn', context, function (err) { context.testOutput = context.testOutput.toString(); context.testError = context.testError.toString(); @@ -74,7 +84,8 @@ test('yarn-install: timeout', function (t) { }); test('yarn-install: failed install', function (t) { - const context = makeContext.npmContext('omg-bad-tree', sandbox); + const context = makeContext.npmContext('omg-bad-tree', packageManagers, + sandbox); const expected = { testError: /\/THIS-WILL-FAIL: Not found/ }; diff --git a/test/yarn/test-yarn-test.js b/test/yarn/test-yarn-test.js index 08709eeaa..154f1f387 100644 --- a/test/yarn/test-yarn-test.js +++ b/test/yarn/test-yarn-test.js @@ -10,6 +10,7 @@ const ncp = require('ncp'); const rewire = require('rewire'); const makeContext = require('../helpers/make-context'); +const packageManager = require('../../lib/package-manager'); const packageManagerTest = rewire('../../lib/package-manager/test'); const sandbox = path.join(os.tmpdir(), 'citgm-' + Date.now()); @@ -24,8 +25,14 @@ const failTemp = path.join(sandbox, 'omg-i-fail'); const badFixtures = path.join(fixtures, 'omg-i-do-not-support-testing'); const badTemp = path.join(sandbox, 'omg-i-do-not-support-testing'); +let packageManagers; + test('yarn-test: setup', function (t) { - t.plan(7); + t.plan(8); + packageManager.getPackageManagers((e, res) => { + packageManagers = res; + t.error(e); + }); mkdirp(sandbox, function (err) { t.error(err); ncp(passFixtures, passTemp, function (e) { @@ -44,7 +51,8 @@ test('yarn-test: setup', function (t) { }); test('yarn-test: basic module passing', function (t) { - const context = makeContext.npmContext('omg-i-pass', sandbox); + const context = makeContext.npmContext('omg-i-pass', + packageManagers, sandbox); packageManagerTest('yarn', context, function (err) { t.error(err); t.end(); @@ -52,7 +60,8 @@ test('yarn-test: basic module passing', function (t) { }); test('yarn-test: basic module failing', function (t) { - const context = makeContext.npmContext('omg-i-fail', sandbox); + const context = makeContext.npmContext('omg-i-fail', + packageManagers, sandbox); packageManagerTest('yarn', context, function (err) { t.equals(err && err.message, 'The canary is dead:'); t.end(); @@ -61,7 +70,8 @@ test('yarn-test: basic module failing', function (t) { test('yarn-test: basic module no test script', function (t) { const context = - makeContext.npmContext('omg-i-do-not-support-testing', sandbox); + makeContext.npmContext('omg-i-do-not-support-testing', + packageManagers, sandbox); packageManagerTest('yarn', context, function (err) { t.equals(err && err.message, 'Module does not support yarn-test!'); t.end(); @@ -69,7 +79,8 @@ test('yarn-test: basic module no test script', function (t) { }); test('yarn-test: no package.json', function (t) { - const context = makeContext.npmContext('omg-i-dont-exist', sandbox); + const context = makeContext.npmContext('omg-i-dont-exist', + packageManagers, sandbox); packageManagerTest('yarn', context, function (err) { t.equals(err && err.message, 'Package.json Could not be found'); t.end(); @@ -80,9 +91,10 @@ test('yarn-test: alternative test-path', function (t) { // Same test as 'basic module passing', except with alt node bin which fails. const nodeBinName = packageManagerTest.__get__('nodeBinName'); packageManagerTest.__set__('nodeBinName', 'fake-node'); - const context = makeContext.npmContext('omg-i-pass', sandbox, { - testPath: path.resolve(__dirname, '..', 'fixtures', 'fakenodebin') - }); + const context = makeContext.npmContext('omg-i-pass', packageManagers, + sandbox, { + testPath: path.resolve(__dirname, '..', 'fixtures', 'fakenodebin') + }); packageManagerTest('yarn', context, function (err) { packageManagerTest.__set__('nodeBinName', nodeBinName); t.equals(err && err.message, 'The canary is dead:'); @@ -91,9 +103,10 @@ test('yarn-test: alternative test-path', function (t) { }); test('yarn-test: timeout', function (t) { - const context = makeContext.npmContext('omg-i-pass', sandbox, { - timeoutLength: 100 - }); + const context = makeContext.npmContext('omg-i-pass', packageManagers, + sandbox, { + timeoutLength: 100 + }); packageManagerTest('yarn', context, function (err) { t.ok(context.module.flaky, 'Module is Flaky because tests timed out'); t.equals(err && err.message, 'Test Timed Out'); From 792e67311386cdda112ac505985bdd4f0fa5ed3c Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 21 Nov 2018 17:20:06 +0100 Subject: [PATCH 26/28] fix failing test --- test/test-timeout.js | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/test/test-timeout.js b/test/test-timeout.js index 2f591024d..80114ef55 100644 --- a/test/test-timeout.js +++ b/test/test-timeout.js @@ -5,15 +5,27 @@ const path = require('path'); const test = require('tap').test; const rewire = require('rewire'); +const packageManager = require('../lib/package-manager'); const timeout = rewire('../lib/timeout'); const makeContext = require('./helpers/make-context'); const sandbox = path.join(os.tmpdir(), 'citgm-' + Date.now()); -test('timeout:', function (t) { - const context = makeContext.npmContext('omg-i-pass', sandbox, { - npmLevel: 'silly', - timeoutLength: 100 +let packageManagers; + +test('timeout: setup', function (t) { + t.plan(1); + packageManager.getPackageManagers((e, res) => { + packageManagers = res; + t.error(e); }); +}); + +test('timeout:', function (t) { + const context = makeContext.npmContext('omg-i-pass', packageManagers, + sandbox, { + npmLevel: 'silly', + timeoutLength: 100 + }); const proc = { kill() { this.killed++; @@ -42,10 +54,11 @@ test('timeout:', function (t) { }); test('timeout:', function (t) { - const context = makeContext.npmContext('omg-i-pass', sandbox, { - npmLevel: 'silly', - timeoutLength: 100 - }); + const context = makeContext.npmContext('omg-i-pass', packageManagers, + sandbox, { + npmLevel: 'silly', + timeoutLength: 100 + }); const proc = { kill() { this.killed++; From 669492e8ec121880b60640b51d0ceb6c8c43cf7f Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 21 Nov 2018 17:21:38 +0100 Subject: [PATCH 27/28] PR feedback --- lib/citgm.js | 16 +++------------- lib/package-manager/index.js | 28 +++++++++++++++------------- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/lib/citgm.js b/lib/citgm.js index c50a4f851..3bba41513 100644 --- a/lib/citgm.js +++ b/lib/citgm.js @@ -33,17 +33,7 @@ exports.windows = windows; function findNode(context, next) { which('node', function(err, resolved) { if (err) { - npmWhich(__dirname)('node', function(err, resolved) { - if (err) { - next(Error('node not found in path!')); - return; - } - - context.emit('data', 'verbose', - context.module.name + ' using-node', - resolved); - next(null, context); - }); + next(err); return; } context.emit('data', 'verbose', context.module.name + ' using-node', @@ -123,8 +113,8 @@ Tester.prototype.run = function() { async.waterfall([ init.bind(null, this), - findNode.bind(null), - findPackageManagers.bind(null), + findNode, + findPackageManagers, tempDirectory.create, grabModuleData, lookup, diff --git a/lib/package-manager/index.js b/lib/package-manager/index.js index 6bc142020..ac50df480 100644 --- a/lib/package-manager/index.js +++ b/lib/package-manager/index.js @@ -22,20 +22,22 @@ function pkgTest(context, next) { } } +function getPackageManagers(next) { + async.parallel([ + getExecutable.bind(null, 'npm'), + getExecutable.bind(null, 'yarn') + ], (err, res) => { + if (err) { + next(err); + return; + } + + next(null, { npm: res[0], yarn: res[1] }); + }); +} + module.exports = { install: pkgInstall, test: pkgTest, - getPackageManagers: function(next) { - async.parallel([ - getExecutable.bind(null, 'npm'), - getExecutable.bind(null, 'yarn') - ], (err, res) => { - if (err) { - next(err); - return; - } - - next(null, { npm: res[0], yarn: res[1] }); - }); - } + getPackageManagers: getPackageManagers }; From 04964a37584e5c88aad2a4753c68eba4a3c13161 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 21 Nov 2018 17:22:53 +0100 Subject: [PATCH 28/28] lint --- lib/citgm.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/citgm.js b/lib/citgm.js index 3bba41513..352a90c51 100644 --- a/lib/citgm.js +++ b/lib/citgm.js @@ -6,7 +6,6 @@ const async = require('async'); const npa = require('npm-package-arg'); const BufferList = require('bl'); let which = require('which'); // Mocked in tests -let npmWhich = require('npm-which'); // Mocked in tests const grabModuleData = require('./grab-module-data'); const grabProject = require('./grab-project');