diff --git a/tests/src/rules/no-parent-barrel-import.js b/tests/src/rules/no-parent-barrel-import.js new file mode 100644 index 000000000..9cd3b0dbc --- /dev/null +++ b/tests/src/rules/no-parent-barrel-import.js @@ -0,0 +1,98 @@ +import { test, testFilePath } from '../utils'; + +import { RuleTester } from 'eslint'; + +const ruleTester = new RuleTester(); +const rule = require('rules/no-parent-barrel-import'); + +const error = { + message: 'Module imports from parent barrel file.', +}; + +ruleTester.run('no-parent-barrel-import', rule, { + valid: [ + test({ + code: 'import _ from "lodash"', + filename: testFilePath('./no-parent-barrel-import.js'), + }), + test({ + code: 'import find from "lodash.find"', + filename: testFilePath('./no-parent-barrel-import.js'), + }), + test({ + code: 'import foo from "./foo"', + filename: testFilePath('./no-parent-barrel-import.js'), + }), + test({ + code: 'import foo from "../foo"', + filename: testFilePath('./no-parent-barrel-import.js'), + }), + test({ + code: 'import foo from "foo"', + filename: testFilePath('./no-parent-barrel-import.js'), + }), + test({ + code: 'var _ = require("lodash")', + filename: testFilePath('./no-parent-barrel-import.js'), + }), + test({ + code: 'var find = require("lodash.find")', + filename: testFilePath('./no-parent-barrel-import.js'), + }), + test({ + code: 'var foo = require("./foo")', + filename: testFilePath('./no-parent-barrel-import.js'), + }), + test({ + code: 'var foo = require("../foo")', + filename: testFilePath('./no-parent-barrel-import.js'), + }), + test({ + code: 'var foo = require("foo")', + filename: testFilePath('./no-parent-barrel-import.js'), + }), + test({ + code: 'var foo = require("@scope/foo")', + filename: testFilePath('./no-parent-barrel-import.js'), + }), + test({ + code: 'var bar = require("./bar/index")', + filename: testFilePath('./no-parent-barrel-import.js'), + }), + test({ + code: 'var bar = require("./bar")', + filename: testFilePath('./bar/index.js'), + }), + test({ + code: 'var bar = require("./bar")', + filename: '', + }), + ], + invalid: [ + test({ + code: 'import foo from "."', + errors: [error], + filename: testFilePath('./no-parent-barrel-import.js'), + }), + test({ + code: 'var foo = require("./index.js")', + errors: [error], + filename: testFilePath('./no-parent-barrel-import.js'), + }), + test({ + code: 'var foo = require(".")', + errors: [error], + filename: testFilePath('./no-parent-barrel-import.js'), + }), + test({ + code: 'var foo = require("./")', + errors: [error], + filename: testFilePath('./no-parent-barrel-import.js'), + }), + test({ + code: 'var foo = require("././././")', + errors: [error], + filename: testFilePath('./no-parent-barrel-import.js'), + }), + ], +});