Skip to content

Commit

Permalink
test: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
jonioni committed May 8, 2023
1 parent d072265 commit c8ec0cf
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions tests/src/rules/no-parent-barrel-import.js
Original file line number Diff line number Diff line change
@@ -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: '<text>',
}),
],
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'),
}),
],
});

0 comments on commit c8ec0cf

Please sign in to comment.