From 474d7763d97d27b28cdf80324c60a5d0a2375fed 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-alphabetize-errors.js | 4 +++- test/parallel/test-eslint-buffer-constructor.js | 4 +++- test/parallel/test-eslint-crypto-check.js | 4 +++- test/parallel/test-eslint-inspector-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-mustnotcall.js | 4 +++- test/parallel/test-eslint-require-buffer.js | 4 +++- test/parallel/test-eslint-required-modules.js | 4 +++- 15 files changed, 52 insertions(+), 13 deletions(-) diff --git a/test/common/README.md b/test/common/README.md index 86027da4316954..85c912b0a7805c 100644 --- a/test/common/README.md +++ b/test/common/README.md @@ -351,6 +351,11 @@ Path to the project directory. 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 0517a6bdc8876c..ceb909ed909c4d 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -551,6 +551,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-alphabetize-errors.js b/test/parallel/test-eslint-alphabetize-errors.js index 83c73fc78c8486..97cf3f89edbbce 100644 --- a/test/parallel/test-eslint-alphabetize-errors.js +++ b/test/parallel/test-eslint-alphabetize-errors.js @@ -1,6 +1,8 @@ 'use strict'; -require('../common'); +const common = require('../common'); + +common.skipIfEslintMissing(); const RuleTester = require('../../tools/eslint').RuleTester; const rule = require('../../tools/eslint-rules/alphabetize-errors'); diff --git a/test/parallel/test-eslint-buffer-constructor.js b/test/parallel/test-eslint-buffer-constructor.js index dfff1374c1b9c0..cd37808b4d9122 100644 --- a/test/parallel/test-eslint-buffer-constructor.js +++ b/test/parallel/test-eslint-buffer-constructor.js @@ -1,6 +1,8 @@ 'use strict'; -require('../common'); +const common = require('../common'); + +common.skipIfEslintMissing(); const RuleTester = require('../../tools/eslint').RuleTester; const rule = require('../../tools/eslint-rules/buffer-constructor'); diff --git a/test/parallel/test-eslint-crypto-check.js b/test/parallel/test-eslint-crypto-check.js index 102560e78ecee7..7feea0d8715131 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/eslint').RuleTester; const rule = require('../../tools/eslint-rules/crypto-check'); diff --git a/test/parallel/test-eslint-inspector-check.js b/test/parallel/test-eslint-inspector-check.js index 20774284abccdd..ff956cb64ed43f 100644 --- a/test/parallel/test-eslint-inspector-check.js +++ b/test/parallel/test-eslint-inspector-check.js @@ -1,6 +1,8 @@ 'use strict'; -require('../common'); +const common = require('../common'); + +common.skipIfEslintMissing(); const RuleTester = require('../../tools/eslint').RuleTester; const rule = require('../../tools/eslint-rules/inspector-check'); diff --git a/test/parallel/test-eslint-lowercase-name-for-primitive.js b/test/parallel/test-eslint-lowercase-name-for-primitive.js index 3eb0d838346865..82133aa075c9b6 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/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 c3c1e17a729252..0cf45a2da6bd60 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/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 5dbd355e71f47d..40bb7173254b54 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/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 deeac48bcccb68..c02c41777edfa2 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/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 00df47975b8007..790207bc30cd43 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/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 2129c083224f0e..ea1501ed8401eb 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/eslint').RuleTester; const rule = require('../../tools/eslint-rules/prefer-assert-methods'); diff --git a/test/parallel/test-eslint-prefer-common-mustnotcall.js b/test/parallel/test-eslint-prefer-common-mustnotcall.js index 848e762ce38ff2..48ddaf430c1d6c 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/eslint').RuleTester; const rule = require('../../tools/eslint-rules/prefer-common-mustnotcall'); diff --git a/test/parallel/test-eslint-require-buffer.js b/test/parallel/test-eslint-require-buffer.js index 282f983c782d4e..005891e9ee2941 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/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 8203cd0d0a0317..755ca85aa12e8b 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/eslint').RuleTester; const rule = require('../../tools/eslint-rules/required-modules');