Skip to content

Commit

Permalink
Add test cases for jsx files
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Lau committed Oct 18, 2016
1 parent 1e6e5a2 commit 2db1344
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -7,7 +7,7 @@

Adds [eslint](http://eslint.org/) rules to ensure consistent filenames for your javascript files.

__Please note__: This plugin will only lint the filenames of the `.js`-files you are linting with eslint. It will ignore all other files (e.g. non-js files, files not linted with eslint).
__Please note__: This plugin will only lint the filenames of the `.js`, `.jsx` files you are linting with eslint. It will ignore other files that are not linted with eslint.

## Enabling the plugin

Expand Down
61 changes: 61 additions & 0 deletions test/rules/match-exported.js
Expand Up @@ -4,11 +4,15 @@ var exportedRule = require("../../lib/rules/match-exported"),
var testCode = "var foo = 'bar';",
testCallCode = "export default foo();",
exportedVariableCode = "module.exports = exported;",
exportedJsxClassCode = "module.exports = class Foo { render() { return <span>Test Class</span>; } };",
exportedClassCode = "module.exports = class Foo {};",
exportedFunctionCode = "module.exports = function foo() {};",
exportedJsxFunctionCode = "module.exports = function foo() { return <span>Test Fn</span> };",
exportedEs6VariableCode = "export default exported;",
exportedEs6ClassCode = "export default class Foo {};",
exportedEs6JsxClassCode = "export default class Foo { render() { return <span>Test Class</span>; } };",
exportedEs6FunctionCode = "export default function foo() {};",
exportedEs6JsxFunctionCode = "export default function foo() { return <span>Test Fn</span> };",
exportedEs6Index = "export default function index() {};",
camelCaseCommonJS = "module.exports = variableName;",
snakeCaseCommonJS = "module.exports = variable_name;",
Expand Down Expand Up @@ -44,10 +48,20 @@ ruleTester.run("lib/rules/match-exported", exportedRule, {
filename: "/some/dir/Foo.js",
parserOptions: { ecmaVersion: 6 }
},
{
code: exportedJsxClassCode,
filename: "/some/dir/Foo.js",
parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }
},
{
code: exportedFunctionCode,
filename: "/some/dir/foo.js"
},
{
code: exportedJsxFunctionCode,
filename: "/some/dir/foo.js",
parserOptions: { ecmaFeatures: { jsx: true } }
},
{
code: exportedEs6VariableCode,
filename: "/some/dir/exported.js",
Expand All @@ -58,16 +72,31 @@ ruleTester.run("lib/rules/match-exported", exportedRule, {
filename: "/some/dir/Foo.js",
parserOptions: { ecmaVersion: 6, sourceType: "module" }
},
{
code: exportedEs6JsxClassCode,
filename: "/some/dir/Foo.js",
parserOptions: { ecmaVersion: 6, sourceType: "module", ecmaFeatures: { jsx: true } }
},
{
code: exportedEs6FunctionCode,
filename: "/some/dir/foo.js",
parserOptions: { ecmaVersion: 6, sourceType: "module" }
},
{
code: exportedEs6JsxFunctionCode,
filename: "/some/dir/foo.js",
parserOptions: { ecmaVersion: 6, sourceType: "module", ecmaFeatures: { jsx: true } }
},
{
code: exportedEs6FunctionCode,
filename: "/some/dir/foo/index.js",
parserOptions: { ecmaVersion: 6, sourceType: "module" }
},
{
code: exportedEs6JsxFunctionCode,
filename: "/some/dir/foo/index.js",
parserOptions: { ecmaVersion: 6, sourceType: "module", ecmaFeatures: { jsx: true } }
},
{
code: exportedEs6FunctionCode,
// /foo is used as cwd for test setup so full path will be /foo/index.js
Expand Down Expand Up @@ -98,13 +127,29 @@ ruleTester.run("lib/rules/match-exported", exportedRule, {
{ message: "Filename 'foo' must match the exported name 'Foo'.", column: 1, line: 1 }
]
},
{
code: exportedJsxClassCode,
filename: "/some/dir/foo.js",
parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } },
errors: [
{ message: "Filename 'foo' must match the exported name 'Foo'.", column: 1, line: 1 }
]
},
{
code: exportedFunctionCode,
filename: "/some/dir/bar.js",
errors: [
{ message: "Filename 'bar' must match the exported name 'foo'.", column: 1, line: 1 }
]
},
{
code: exportedJsxFunctionCode,
filename: "/some/dir/bar.js",
parserOptions: { ecmaFeatures: { jsx: true } },
errors: [
{ message: "Filename 'bar' must match the exported name 'foo'.", column: 1, line: 1 }
]
},
{
code: exportedEs6VariableCode,
filename: "/some/dir/fooBar.js",
Expand All @@ -121,6 +166,14 @@ ruleTester.run("lib/rules/match-exported", exportedRule, {
{ message: "Filename 'bar' must match the exported name 'Foo'.", column: 1, line: 1 }
]
},
{
code: exportedEs6JsxClassCode,
filename: "/some/dir/bar.js",
parserOptions: { ecmaVersion: 6, sourceType: "module", ecmaFeatures: { jsx: true } },
errors: [
{ message: "Filename 'bar' must match the exported name 'Foo'.", column: 1, line: 1 }
]
},
{
code: exportedEs6FunctionCode,
filename: "/some/dir/fooBar/index.js",
Expand All @@ -129,6 +182,14 @@ ruleTester.run("lib/rules/match-exported", exportedRule, {
{ message: "The directory 'fooBar' must be named 'foo', after the exported value of its index file.", column: 1, line: 1 }
]
},
{
code: exportedEs6JsxFunctionCode,
filename: "/some/dir/fooBar/index.js",
parserOptions: { ecmaVersion: 6, sourceType: "module", ecmaFeatures: { jsx: true } },
errors: [
{ message: "The directory 'fooBar' must be named 'foo', after the exported value of its index file.", column: 1, line: 1 }
]
},
{
code: exportedVariableCode,
filename: "index.js",
Expand Down

0 comments on commit 2db1344

Please sign in to comment.