Skip to content

Commit

Permalink
test: add test cases for un-ts#123
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Aug 26, 2024
1 parent 9948c78 commit 05f36a8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
1 change: 0 additions & 1 deletion test/package.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ describe('package', () => {
continue
}
for (const rule of Object.keys(config.rules)) {
console.log({ rule, preamble })
expect(() =>
require(getRulePath(rule.slice(preamble.length))),
).not.toThrow()
Expand Down
13 changes: 9 additions & 4 deletions test/rules/no-named-as-default.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,22 @@ import rule from 'eslint-plugin-import-x/rules/no-named-as-default'

const ruleTester = new TSESLintRuleTester()

console.log({ babel: require(parsers.BABEL) })

ruleTester.run('no-named-as-default', rule, {
valid: [
// https://github.com/un-ts/eslint-plugin-import-x/issues/123
'import klawSync from "klaw-sync";',
'import ts from "typescript";',
`import React from 'react';`,
`import z from 'zod';`,
`import classNames from 'classnames';`,

test({
code: 'import "./malformed.js"',
languageOptions: { parser: require(parsers.ESPREE) },
}),

test({ code: 'import bar, { foo } from "./bar";' }),
test({ code: 'import bar, { foo } from "./empty-folder";' }),
'import bar, { foo } from "./bar";',
'import bar, { foo } from "./empty-folder";',

// es7
test({
Expand Down
24 changes: 12 additions & 12 deletions test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,29 +109,29 @@ export function testContext(settings?: PluginSettings) {
* to crash at runtime
*/
export const SYNTAX_CASES = [
test({ code: 'for (let { foo, bar } of baz) {}' }),
test({ code: 'for (let [ foo, bar ] of baz) {}' }),
'for (let { foo, bar } of baz) {}',
'for (let [ foo, bar ] of baz) {}',

test({ code: 'const { x, y } = bar' }),
'const { x, y } = bar',
test({
code: 'const { x, y, ...z } = bar',
languageOptions: { parser: require(parsers.BABEL) },
}),

// all the exports
test({ code: 'let x; export { x }' }),
test({ code: 'let x; export { x as y }' }),
'let x; export { x }',
'let x; export { x as y }',

// not sure about these since they reference a file
// test({ code: 'export { x } from "./y.js"'}),
// test({ code: 'export * as y from "./y.js"', languageOptions: { parser: require(parsers.BABEL) } }),
// 'export { x } from "./y.js"'}),
// 'export * as y from "./y.js"', languageOptions: { parser: require(parsers.BABEL) } }),

test({ code: 'export const x = null' }),
test({ code: 'export var x = null' }),
test({ code: 'export let x = null' }),
'export const x = null',
'export var x = null',
'export let x = null',

test({ code: 'export default x' }),
test({ code: 'export default class x {}' }),
'export default x',
'export default class x {}',

// issue #267: parser opt-in extension list
test({
Expand Down

0 comments on commit 05f36a8

Please sign in to comment.