Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no-commonjs: add tests that show corner cases #1308

Merged
merged 1 commit into from
Mar 27, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions tests/src/rules/no-commonjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ ruleTester.run('no-commonjs', require('rules/no-commonjs'), {
{ code: 'var zero = require(0);' },
{ code: 'require("x")', options: [{ allowRequire: true }] },

// commonJS doesn't care how the path is built. You can use a function to
// dynamically build the module path.t st
{ code: 'require(rootRequire("x"))', options: [{ allowRequire: true }] },
{ code: 'require(String("x"))', options: [{ allowRequire: true }] },
{ code: 'require(["x", "y", "z"].join("/"))', options: [{ allowRequire: true }] },

// commonJS rules should be scoped to commonJS spec. `rootRequire` is not
// recognized by this commonJS plugin.
{ code: 'rootRequire("x")', options: [{ allowRequire: true }] },
{ code: 'rootRequire("x")', options: [{ allowRequire: false}] },

{ code: 'module.exports = function () {}', options: ['allow-primitive-modules'] },
{ code: 'module.exports = function () {}', options: [{ allowPrimitiveModules: true }] },
{ code: 'module.exports = "foo"', options: ['allow-primitive-modules'] },
Expand Down