Skip to content

Commit 474d776

Browse files
committed
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: #18807 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 8cc0ea7 commit 474d776

15 files changed

+52
-13
lines changed

test/common/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,11 @@ Path to the project directory.
351351

352352
Logs '1..0 # Skipped: ' + `msg` and exits with exit code `0`.
353353

354+
### skipIfEslintMissing()
355+
356+
Skip the rest of the tests in the current file when `ESLint` is not available
357+
at `tools/node_modules/eslint`
358+
354359
### skipIfInspectorDisabled()
355360

356361
Skip the rest of the tests in the current file when the Inspector

test/common/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,14 @@ exports.fileExists = function(pathname) {
551551
}
552552
};
553553

554+
exports.skipIfEslintMissing = function() {
555+
if (!exports.fileExists(
556+
path.join('..', '..', 'tools', 'node_modules', 'eslint')
557+
)) {
558+
exports.skip('missing ESLint');
559+
}
560+
};
561+
554562
exports.canCreateSymLink = function() {
555563
// On Windows, creating symlinks requires admin privileges.
556564
// We'll only try to run symlink test if we have enough privileges.

test/parallel/test-eslint-alphabetize-errors.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict';
22

3-
require('../common');
3+
const common = require('../common');
4+
5+
common.skipIfEslintMissing();
46

57
const RuleTester = require('../../tools/eslint').RuleTester;
68
const rule = require('../../tools/eslint-rules/alphabetize-errors');

test/parallel/test-eslint-buffer-constructor.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict';
22

3-
require('../common');
3+
const common = require('../common');
4+
5+
common.skipIfEslintMissing();
46

57
const RuleTester = require('../../tools/eslint').RuleTester;
68
const rule = require('../../tools/eslint-rules/buffer-constructor');

test/parallel/test-eslint-crypto-check.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict';
22

3-
require('../common');
3+
const common = require('../common');
4+
5+
common.skipIfEslintMissing();
46

57
const RuleTester = require('../../tools/eslint').RuleTester;
68
const rule = require('../../tools/eslint-rules/crypto-check');

test/parallel/test-eslint-inspector-check.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict';
22

3-
require('../common');
3+
const common = require('../common');
4+
5+
common.skipIfEslintMissing();
46

57
const RuleTester = require('../../tools/eslint').RuleTester;
68
const rule = require('../../tools/eslint-rules/inspector-check');

test/parallel/test-eslint-lowercase-name-for-primitive.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict';
22

3-
require('../common');
3+
const common = require('../common');
4+
5+
common.skipIfEslintMissing();
46

57
const RuleTester = require('../../tools/eslint').RuleTester;
68
const rule = require('../../tools/eslint-rules/lowercase-name-for-primitive');

test/parallel/test-eslint-no-let-in-for-declaration.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict';
22

3-
require('../common');
3+
const common = require('../common');
4+
5+
common.skipIfEslintMissing();
46

57
const RuleTester = require('../../tools/eslint').RuleTester;
68
const rule = require('../../tools/eslint-rules/no-let-in-for-declaration');

test/parallel/test-eslint-no-unescaped-regexp-dot.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict';
22

3-
require('../common');
3+
const common = require('../common');
4+
5+
common.skipIfEslintMissing();
46

57
const RuleTester = require('../../tools/eslint').RuleTester;
68
const rule = require('../../tools/eslint-rules/no-unescaped-regexp-dot');

test/parallel/test-eslint-number-isnan.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict';
22

3-
require('../common');
3+
const common = require('../common');
4+
5+
common.skipIfEslintMissing();
46

57
const RuleTester = require('../../tools/eslint').RuleTester;
68
const rule = require('../../tools/eslint-rules/number-isnan');

0 commit comments

Comments
 (0)