From 411af62ae3b0ecac63469eb639d6b193327ac232 Mon Sep 17 00:00:00 2001 From: Gio d'Amelio Date: Sun, 22 Jan 2017 14:52:43 -0800 Subject: [PATCH] Add test --- tests/src/rules/no-self-import.js | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/src/rules/no-self-import.js diff --git a/tests/src/rules/no-self-import.js b/tests/src/rules/no-self-import.js new file mode 100644 index 0000000000..d879a10845 --- /dev/null +++ b/tests/src/rules/no-self-import.js @@ -0,0 +1,42 @@ +import { test, testFilePath } from '../utils' + +import { RuleTester } from 'eslint' + +const ruleTester = new RuleTester() + , rule = require('rules/no-self-import') + +const error = { + ruleId: 'no-self-import', + message: 'Module imports itself', +} + +ruleTester.run('no-self-import', rule, { + valid: [ + test({ code: 'import _ from "lodash"'}), + test({ code: 'import find from "lodash.find"'}), + test({ code: 'import foo from "./foo"'}), + test({ code: 'import foo from "../foo"'}), + test({ code: 'import foo from "foo"'}), + test({ code: 'import foo from "./"'}), + test({ code: 'import foo from "@scope/foo"'}), + test({ code: 'var _ = require("lodash")'}), + test({ code: 'var find = require("lodash.find")'}), + test({ code: 'var foo = require("./foo")'}), + test({ code: 'var foo = require("../foo")'}), + test({ code: 'var foo = require("foo")'}), + test({ code: 'var foo = require("./")'}), + test({ code: 'var foo = require("@scope/foo")'}), + ], + invalid: [ + test({ + code: 'import bar from "./bar"', + errors: [error], + filename: testFilePath('./bar.js'), + }), + test({ + code: 'var bar = require("./bar")', + errors: [error], + filename: testFilePath('./bar.js'), + }), + ], +})