Skip to content

Commit

Permalink
fix: move fetch to node-builtins && add more tests
Browse files Browse the repository at this point in the history
Signed-off-by: 唯然 <weiran.zsd@outlook.com>
  • Loading branch information
aladdin-add committed Apr 29, 2024
1 parent 3a54507 commit 01e3bec
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 9 deletions.
3 changes: 0 additions & 3 deletions lib/rules/no-unsupported-features/es-builtins.js
Original file line number Diff line number Diff line change
Expand Up @@ -601,9 +601,6 @@ const traceMap = {
trace: { [READ]: { supported: ["0.10.0"] } },
warn: { [READ]: { supported: ["0.10.0"] } },
},
fetch: {
[READ]: { supported: ["18.0.0"] },
},
queueMicrotask: {
[READ]: { supported: ["11.0.0"] },
},
Expand Down
3 changes: 3 additions & 0 deletions lib/rules/no-unsupported-features/node-builtins.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ const traceMap = {
paths: { [READ]: { supported: ["8.9.0"] } },
},
},
fetch: {
[READ]: { supported: ["18.0.0"] },
},
},
modules: NodeBuiltinModules,
}
Expand Down
60 changes: 54 additions & 6 deletions tests/lib/rules/no-unsupported-features/node-builtins.js
Original file line number Diff line number Diff line change
Expand Up @@ -5305,12 +5305,6 @@ new RuleTester({ languageOptions: { sourceType: "module" } }).run(
node: { version: "12.11.0" },
},
},

// https://github.com/eslint-community/eslint-plugin-n/issues/253
{
code: `fetch("/api/xxx");`,
settings: { node: { version: ">=18.2.0" } },
},
],
invalid: [
{
Expand Down Expand Up @@ -5373,5 +5367,59 @@ new RuleTester({ languageOptions: { sourceType: "module" } }).run(
},
],
},

//----------------------------------------------------------------------
// fetch
//----------------------------------------------------------------------
{
valid: [
{
code: `fetch("/api/xxx");`,
options: [{ version: ">=18.2.0" }],
},
{
code: `fetch("/api/xxx");`,
options: [{ version: ">=18.0.0" }],
},
{
code: `fetch("/api/xxx");`,
options: [{ version: "^18.0.0" }],
},
{
code: `fetch("/api/xxx");`,
options: [{ version: ">18.0.0" }],
},
{
code: `fetch("/api/xxx");`,
options: [{ version: ">=19.0.0" }],
},
{
code: `fetch("/api/xxx");`,
options: [{ version: ">19.0.0" }],
},
],
invalid: [
{
code: `fetch("/api/xxx");`,
options: [{ version: ">=17.0.0" }],
errors: [{ messageId: "not-supported-till" }],
},
{
code: `fetch("/api/xxx");`,
options: [{ version: "^17.0.0" }],
errors: [{ messageId: "not-supported-till" }],
},
{
code: `fetch("/api/xxx");`,
options: [{ version: "^17.2.0" }],
errors: [{ messageId: "not-supported-till" }],
},
{
code: `fetch("/api/xxx");`,
options: [{ version: "^17.2.0||18.x" }],
errors: [{ messageId: "not-supported-till" }],
},
],
},
])
)

0 comments on commit 01e3bec

Please sign in to comment.