|
| 1 | +const { RuleTester } = require("./support/RuleTester.cjs"); |
| 2 | +const rule = require("../rules/js-extensions.cjs"); |
| 3 | + |
| 4 | +const ruleTester = new RuleTester({ |
| 5 | + parserOptions: { |
| 6 | + warnOnUnsupportedTypeScriptVersion: false, |
| 7 | + }, |
| 8 | + parser: require.resolve("@typescript-eslint/parser"), |
| 9 | +}); |
| 10 | + |
| 11 | +ruleTester.run("js-extensions", rule, { |
| 12 | + valid: [ |
| 13 | + { |
| 14 | + code: ` |
| 15 | +import "some-library"; |
| 16 | +import "./a.js"; |
| 17 | +import "./a.mjs"; |
| 18 | +import "./a.cjs"; |
| 19 | +import "../foo/a.js"; |
| 20 | +import "../foo/a.mjs"; |
| 21 | +import "../foo/a.cjs"; |
| 22 | + `, |
| 23 | + }, |
| 24 | + { |
| 25 | + code: ` |
| 26 | +import * as blah from "some-library"; |
| 27 | +import * as blah from "./a.js"; |
| 28 | +import * as blah from "./a.mjs"; |
| 29 | +import * as blah from "./a.cjs"; |
| 30 | +import * as blah from "../foo/a.js"; |
| 31 | +import * as blah from "../foo/a.mjs"; |
| 32 | +import * as blah from "../foo/a.cjs"; |
| 33 | + `, |
| 34 | + }, |
| 35 | + { |
| 36 | + code: ` |
| 37 | +export * from "some-library"; |
| 38 | +export * from "./a.js"; |
| 39 | +export * from "./a.mjs"; |
| 40 | +export * from "./a.cjs"; |
| 41 | +export * from "../foo/a.js"; |
| 42 | +export * from "../foo/a.mjs"; |
| 43 | +export * from "../foo/a.cjs"; |
| 44 | + `, |
| 45 | + }, |
| 46 | + { |
| 47 | + code: ` |
| 48 | +import blah = require("some-library"); |
| 49 | +import blah = require("./a.js"); |
| 50 | +import blah = require("./a.mjs"); |
| 51 | +import blah = require("./a.cjs"); |
| 52 | +import blah = require("../foo/a.js"); |
| 53 | +import blah = require("../foo/a.mjs"); |
| 54 | +import blah = require("../foo/a.cjs"); |
| 55 | + `, |
| 56 | + }, |
| 57 | + ], |
| 58 | + |
| 59 | + invalid: [ |
| 60 | + { |
| 61 | + code: ` |
| 62 | +import "./a"; |
| 63 | +import "../foo/a"; |
| 64 | + `, |
| 65 | + errors: [ |
| 66 | + { |
| 67 | + messageId: "missingJsExtension", |
| 68 | + line: 2, |
| 69 | + column: 8, |
| 70 | + }, |
| 71 | + { |
| 72 | + messageId: "missingJsExtension", |
| 73 | + line: 3, |
| 74 | + column: 8, |
| 75 | + }, |
| 76 | + ], |
| 77 | + output: ` |
| 78 | +import "./a.js"; |
| 79 | +import "../foo/a.js"; |
| 80 | + `, |
| 81 | + }, |
| 82 | + { |
| 83 | + code: ` |
| 84 | +import * as blah from "./a"; |
| 85 | +import * as blah from "../foo/a"; |
| 86 | + `, |
| 87 | + errors: [ |
| 88 | + { |
| 89 | + messageId: "missingJsExtension", |
| 90 | + line: 2, |
| 91 | + column: 23, |
| 92 | + }, |
| 93 | + { |
| 94 | + messageId: "missingJsExtension", |
| 95 | + line: 3, |
| 96 | + column: 23, |
| 97 | + }, |
| 98 | + ], |
| 99 | + output: ` |
| 100 | +import * as blah from "./a.js"; |
| 101 | +import * as blah from "../foo/a.js"; |
| 102 | + `, |
| 103 | + }, |
| 104 | + { |
| 105 | + code: ` |
| 106 | +export * from "./a"; |
| 107 | +export * from "../foo/a"; |
| 108 | + `, |
| 109 | + errors: [ |
| 110 | + { |
| 111 | + messageId: "missingJsExtension", |
| 112 | + line: 2, |
| 113 | + column: 15, |
| 114 | + }, |
| 115 | + { |
| 116 | + messageId: "missingJsExtension", |
| 117 | + line: 3, |
| 118 | + column: 15, |
| 119 | + }, |
| 120 | + ], |
| 121 | + output: ` |
| 122 | +export * from "./a.js"; |
| 123 | +export * from "../foo/a.js"; |
| 124 | + `, |
| 125 | + }, |
| 126 | + { |
| 127 | + code: ` |
| 128 | +import blah = require("./a"); |
| 129 | +import blah = require("../foo/a"); |
| 130 | + `, |
| 131 | + errors: [ |
| 132 | + { |
| 133 | + messageId: "missingJsExtension", |
| 134 | + line: 2, |
| 135 | + column: 23, |
| 136 | + }, |
| 137 | + { |
| 138 | + messageId: "missingJsExtension", |
| 139 | + line: 3, |
| 140 | + column: 23, |
| 141 | + }, |
| 142 | + ], |
| 143 | + output: ` |
| 144 | +import blah = require("./a.js"); |
| 145 | +import blah = require("../foo/a.js"); |
| 146 | + `, |
| 147 | + }, |
| 148 | + ], |
| 149 | +}); |
0 commit comments