Skip to content

Commit

Permalink
[Tests] no-nodejs-modules: add tests for node protocol URL
Browse files Browse the repository at this point in the history
  • Loading branch information
sosukesuzuki committed Jan 22, 2022
1 parent 9e4c9a9 commit 28517ff
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions tests/src/rules/no-nodejs-modules.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { test } from '../utils';

import { RuleTester } from 'eslint';
import semver from 'semver';

const ruleTester = new RuleTester();
const rule = require('rules/no-nodejs-modules');

const supportsNodePrefix = semver.satisfies(process.versions.node, '^14.18 || >= 16', { includePrerelease: true });

const error = message => ({
message,
});
Expand Down Expand Up @@ -55,6 +58,37 @@ ruleTester.run('no-nodejs-modules', rule, {
allow: ['path', 'events'],
}],
}),
...(supportsNodePrefix ? [
test({
code: 'import events from "node:events"',
options: [{
allow: ['node:events'],
}],
}),
test({
code: 'import path from "node:path"',
options: [{
allow: ['node:path'],
}],
}),
test({
code: 'var events = require("node:events")',
options: [{
allow: ['node:events'],
}],
}),
test({
code: 'var path = require("node:path")',
options: [{
allow: ['node:path'],
}],
}),
test({
code: 'import path from "node:path";import events from "node:events"',
options: [{
allow: ['node:path', 'node:events'],
}],
})] : []),
],
invalid: [
test({
Expand All @@ -80,5 +114,29 @@ ruleTester.run('no-nodejs-modules', rule, {
}],
errors: [error('Do not import Node.js builtin module "fs"')],
}),
...(supportsNodePrefix ? [
test({
code: 'import path from "node:path"',
errors: [error('Do not import Node.js builtin module "node:path"')],
}),
test({
code: 'import fs from "node:fs"',
errors: [error('Do not import Node.js builtin module "node:fs"')],
}),
test({
code: 'var path = require("node:path")',
errors: [error('Do not import Node.js builtin module "node:path"')],
}),
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"')],
})] : []),
],
});

0 comments on commit 28517ff

Please sign in to comment.