diff --git a/CHANGELOG.md b/CHANGELOG.md index 3894d312c..bd878a8b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange ## [Unreleased] +### Changed +- [Tests] `no-nodejs-modules`: add tests for node protocol URL ([#2367], thanks [@sosukesuzuki]) + ## [2.25.4] - 2022-01-02 ### Fixed @@ -955,6 +958,7 @@ for info on changes for earlier releases. [`memo-parser`]: ./memo-parser/README.md +[#2367]: https://github.com/import-js/eslint-plugin-import/pull/2367 [#2341]: https://github.com/import-js/eslint-plugin-import/pull/2341 [#2334]: https://github.com/import-js/eslint-plugin-import/pull/2334 [#2305]: https://github.com/import-js/eslint-plugin-import/pull/2305 @@ -1618,6 +1622,7 @@ for info on changes for earlier releases. [@skyrpex]: https://github.com/skyrpex [@sompylasar]: https://github.com/sompylasar [@soryy708]: https://github.com/soryy708 +[@sosukesuzuki]: https://github.com/sosukesuzuki [@spalger]: https://github.com/spalger [@st-sloth]: https://github.com/st-sloth [@stekycz]: https://github.com/stekycz @@ -1646,4 +1651,4 @@ for info on changes for earlier releases. [@wtgtybhertgeghgtwtg]: https://github.com/wtgtybhertgeghgtwtg [@xpl]: https://github.com/xpl [@yordis]: https://github.com/yordis -[@zloirock]: https://github.com/zloirock +[@zloirock]: https://github.com/zloirock \ No newline at end of file diff --git a/tests/src/rules/no-nodejs-modules.js b/tests/src/rules/no-nodejs-modules.js index 3587a71dc..9be605709 100644 --- a/tests/src/rules/no-nodejs-modules.js +++ b/tests/src/rules/no-nodejs-modules.js @@ -1,6 +1,7 @@ import { test } from '../utils'; import { RuleTester } from 'eslint'; +const isCore = require('is-core-module'); const ruleTester = new RuleTester(); const rule = require('rules/no-nodejs-modules'); @@ -10,7 +11,7 @@ const error = message => ({ }); ruleTester.run('no-nodejs-modules', rule, { - valid: [ + valid: [].concat( test({ code: 'import _ from "lodash"' }), test({ code: 'import find from "lodash.find"' }), test({ code: 'import foo from "./foo"' }), @@ -55,8 +56,42 @@ ruleTester.run('no-nodejs-modules', rule, { allow: ['path', 'events'], }], }), - ], - invalid: [ + isCore('node:events') ? [ + test({ + code: 'import events from "node:events"', + options: [{ + allow: ['node:events'], + }], + }), + test({ + code: 'var events = require("node:events")', + options: [{ + allow: ['node:events'], + }], + }), + ]: [], + isCore('node:path') ? [ + test({ + code: 'import path from "node:path"', + options: [{ + allow: ['node:path'], + }], + }), + test({ + code: 'var path = require("node:path")', + options: [{ + allow: ['node:path'], + }], + }), + ] : [], + isCore('node:path') && isCore('node:events') ? test({ + code: 'import path from "node:path";import events from "node:events"', + options: [{ + allow: ['node:path', 'node:events'], + }], + }) : [], + ), + invalid: [].concat( test({ code: 'import path from "path"', errors: [error('Do not import Node.js builtin module "path"')], @@ -80,5 +115,32 @@ ruleTester.run('no-nodejs-modules', rule, { }], errors: [error('Do not import Node.js builtin module "fs"')], }), - ], + isCore('node:path') ? [ + test({ + code: 'import path from "node:path"', + errors: [error('Do not import Node.js builtin module "node:path"')], + }), + test({ + code: 'var path = require("node:path")', + errors: [error('Do not import Node.js builtin module "node:path"')], + }), + ] : [], + isCore('node:fs') ? [ + test({ + code: 'import fs from "node:fs"', + errors: [error('Do not import Node.js builtin module "node:fs"')], + }), + test({ + code: 'var fs = require("node:fs")', + errors: [error('Do not import Node.js builtin module "node:fs"')], + }), + test({ + code: 'import fs from "node:fs"', + options: [{ + allow: ['node:path'], + }], + errors: [error('Do not import Node.js builtin module "node:fs"')], + }), + ] : [], + ), });