From 1fd69872e6c4d2dd8127560ae078b4cbf8b7badb Mon Sep 17 00:00:00 2001 From: Myles Borins Date: Thu, 15 Feb 2018 18:47:10 -0500 Subject: [PATCH] test: add common.skipIfEslintMissing We've added a number of tests that hook into ESLint which can error when running the test suite with the distributed tarball. This PR adds a new test helper `common.skipIfEslintMissing` and will skip remaining tests in a file when `ESLint` is not available at `tools/node_modules/eslint` PR-URL: https://github.com/nodejs/node/pull/18807 Reviewed-By: Rich Trott Reviewed-By: Richard Lau Reviewed-By: James M Snell Reviewed-By: Yuta Hiroto Reviewed-By: Colin Ihrig Reviewed-By: Ruben Bridgewater --- test/common/README.md | 5 +++++ test/common/index.js | 8 ++++++++ test/parallel/test-eslint-crypto-check.js | 4 +++- test/parallel/test-eslint-lowercase-name-for-primitive.js | 4 +++- test/parallel/test-eslint-no-let-in-for-declaration.js | 4 +++- test/parallel/test-eslint-no-unescaped-regexp-dot.js | 4 +++- test/parallel/test-eslint-number-isnan.js | 4 +++- test/parallel/test-eslint-prefer-assert-iferror.js | 4 +++- test/parallel/test-eslint-prefer-assert-methods.js | 4 +++- test/parallel/test-eslint-prefer-common-expectserror.js | 4 +++- test/parallel/test-eslint-prefer-common-mustnotcall.js | 4 +++- test/parallel/test-eslint-prefer-util-format-errors.js | 4 +++- test/parallel/test-eslint-require-buffer.js | 4 +++- test/parallel/test-eslint-required-modules.js | 4 +++- 14 files changed, 49 insertions(+), 12 deletions(-) diff --git a/test/common/README.md b/test/common/README.md index f0bbe7d13dc..18f0e4915b1 100644 --- a/test/common/README.md +++ b/test/common/README.md @@ -353,6 +353,11 @@ Path to the 'root' directory. either `/` or `c:\\` (windows) Logs '1..0 # Skipped: ' + `msg` and exits with exit code `0`. +### skipIfEslintMissing() + +Skip the rest of the tests in the current file when `ESLint` is not available +at `tools/node_modules/eslint` + ### skipIfInspectorDisabled() Skip the rest of the tests in the current file when the Inspector diff --git a/test/common/index.js b/test/common/index.js index 4c2c548830f..a38b9852086 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -494,6 +494,14 @@ exports.fileExists = function(pathname) { } }; +exports.skipIfEslintMissing = function() { + if (!exports.fileExists( + path.join('..', '..', 'tools', 'node_modules', 'eslint') + )) { + exports.skip('missing ESLint'); + } +}; + exports.canCreateSymLink = function() { // On Windows, creating symlinks requires admin privileges. // We'll only try to run symlink test if we have enough privileges. diff --git a/test/parallel/test-eslint-crypto-check.js b/test/parallel/test-eslint-crypto-check.js index 325fb7a057c..f7549f171d6 100644 --- a/test/parallel/test-eslint-crypto-check.js +++ b/test/parallel/test-eslint-crypto-check.js @@ -1,6 +1,8 @@ 'use strict'; -require('../common'); +const common = require('../common'); + +common.skipIfEslintMissing(); const RuleTester = require('../../tools/node_modules/eslint').RuleTester; const rule = require('../../tools/eslint-rules/crypto-check'); diff --git a/test/parallel/test-eslint-lowercase-name-for-primitive.js b/test/parallel/test-eslint-lowercase-name-for-primitive.js index 3449095d663..929ff03c656 100644 --- a/test/parallel/test-eslint-lowercase-name-for-primitive.js +++ b/test/parallel/test-eslint-lowercase-name-for-primitive.js @@ -1,6 +1,8 @@ 'use strict'; -require('../common'); +const common = require('../common'); + +common.skipIfEslintMissing(); const RuleTester = require('../../tools/node_modules/eslint').RuleTester; const rule = require('../../tools/eslint-rules/lowercase-name-for-primitive'); diff --git a/test/parallel/test-eslint-no-let-in-for-declaration.js b/test/parallel/test-eslint-no-let-in-for-declaration.js index ea5b6818546..ed8f306eea8 100644 --- a/test/parallel/test-eslint-no-let-in-for-declaration.js +++ b/test/parallel/test-eslint-no-let-in-for-declaration.js @@ -1,6 +1,8 @@ 'use strict'; -require('../common'); +const common = require('../common'); + +common.skipIfEslintMissing(); const RuleTester = require('../../tools/node_modules/eslint').RuleTester; const rule = require('../../tools/eslint-rules/no-let-in-for-declaration'); diff --git a/test/parallel/test-eslint-no-unescaped-regexp-dot.js b/test/parallel/test-eslint-no-unescaped-regexp-dot.js index 38a9f3efcc6..e6f09291b08 100644 --- a/test/parallel/test-eslint-no-unescaped-regexp-dot.js +++ b/test/parallel/test-eslint-no-unescaped-regexp-dot.js @@ -1,6 +1,8 @@ 'use strict'; -require('../common'); +const common = require('../common'); + +common.skipIfEslintMissing(); const RuleTester = require('../../tools/node_modules/eslint').RuleTester; const rule = require('../../tools/eslint-rules/no-unescaped-regexp-dot'); diff --git a/test/parallel/test-eslint-number-isnan.js b/test/parallel/test-eslint-number-isnan.js index 9f6af407e46..b290a48a895 100644 --- a/test/parallel/test-eslint-number-isnan.js +++ b/test/parallel/test-eslint-number-isnan.js @@ -1,6 +1,8 @@ 'use strict'; -require('../common'); +const common = require('../common'); + +common.skipIfEslintMissing(); const RuleTester = require('../../tools/node_modules/eslint').RuleTester; const rule = require('../../tools/eslint-rules/number-isnan'); diff --git a/test/parallel/test-eslint-prefer-assert-iferror.js b/test/parallel/test-eslint-prefer-assert-iferror.js index 8a9723f4b21..7dc3bbe7bcd 100644 --- a/test/parallel/test-eslint-prefer-assert-iferror.js +++ b/test/parallel/test-eslint-prefer-assert-iferror.js @@ -1,6 +1,8 @@ 'use strict'; -require('../common'); +const common = require('../common'); + +common.skipIfEslintMissing(); const RuleTester = require('../../tools/node_modules/eslint').RuleTester; const rule = require('../../tools/eslint-rules/prefer-assert-iferror'); diff --git a/test/parallel/test-eslint-prefer-assert-methods.js b/test/parallel/test-eslint-prefer-assert-methods.js index 2d05a4851bf..3ad1cd5c376 100644 --- a/test/parallel/test-eslint-prefer-assert-methods.js +++ b/test/parallel/test-eslint-prefer-assert-methods.js @@ -1,6 +1,8 @@ 'use strict'; -require('../common'); +const common = require('../common'); + +common.skipIfEslintMissing(); const RuleTester = require('../../tools/node_modules/eslint').RuleTester; const rule = require('../../tools/eslint-rules/prefer-assert-methods'); diff --git a/test/parallel/test-eslint-prefer-common-expectserror.js b/test/parallel/test-eslint-prefer-common-expectserror.js index 1fe7b1bc976..e0d208b68bb 100644 --- a/test/parallel/test-eslint-prefer-common-expectserror.js +++ b/test/parallel/test-eslint-prefer-common-expectserror.js @@ -1,6 +1,8 @@ 'use strict'; -require('../common'); +const common = require('../common'); + +common.skipIfEslintMissing(); const RuleTester = require('../../tools/node_modules/eslint').RuleTester; const rule = require('../../tools/eslint-rules/prefer-common-expectserror'); diff --git a/test/parallel/test-eslint-prefer-common-mustnotcall.js b/test/parallel/test-eslint-prefer-common-mustnotcall.js index c2e298cde21..e6e9d1d2f88 100644 --- a/test/parallel/test-eslint-prefer-common-mustnotcall.js +++ b/test/parallel/test-eslint-prefer-common-mustnotcall.js @@ -1,6 +1,8 @@ 'use strict'; -require('../common'); +const common = require('../common'); + +common.skipIfEslintMissing(); const RuleTester = require('../../tools/node_modules/eslint').RuleTester; const rule = require('../../tools/eslint-rules/prefer-common-mustnotcall'); diff --git a/test/parallel/test-eslint-prefer-util-format-errors.js b/test/parallel/test-eslint-prefer-util-format-errors.js index 7ccbb8a1335..560222438b9 100644 --- a/test/parallel/test-eslint-prefer-util-format-errors.js +++ b/test/parallel/test-eslint-prefer-util-format-errors.js @@ -2,7 +2,9 @@ /* eslint-disable no-template-curly-in-string */ -require('../common'); +const common = require('../common'); + +common.skipIfEslintMissing(); const RuleTester = require('../../tools/node_modules/eslint').RuleTester; const rule = require('../../tools/eslint-rules/prefer-util-format-errors'); diff --git a/test/parallel/test-eslint-require-buffer.js b/test/parallel/test-eslint-require-buffer.js index 23bf7c0afa0..ca2c44cb322 100644 --- a/test/parallel/test-eslint-require-buffer.js +++ b/test/parallel/test-eslint-require-buffer.js @@ -1,6 +1,8 @@ 'use strict'; -require('../common'); +const common = require('../common'); + +common.skipIfEslintMissing(); const RuleTester = require('../../tools/node_modules/eslint').RuleTester; const rule = require('../../tools/eslint-rules/require-buffer'); diff --git a/test/parallel/test-eslint-required-modules.js b/test/parallel/test-eslint-required-modules.js index 1ef96521ec7..dbdc135ccf6 100644 --- a/test/parallel/test-eslint-required-modules.js +++ b/test/parallel/test-eslint-required-modules.js @@ -1,6 +1,8 @@ 'use strict'; -require('../common'); +const common = require('../common'); + +common.skipIfEslintMissing(); const RuleTester = require('../../tools/node_modules/eslint').RuleTester; const rule = require('../../tools/eslint-rules/required-modules');