Files

102 lines
2.0 KiB
JavaScript

/**
* @fileoverview Tests for no-sync.
* @author Matt DuVall <http://www.mattduvall.com>
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const rule = require("../../../lib/rules/no-sync"),
RuleTester = require("../../../lib/rule-tester/rule-tester");
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
const ruleTester = new RuleTester();
ruleTester.run("no-sync", rule, {
valid: [
"var foo = fs.foo.foo();",
{
code: "var foo = fs.fooSync;",
options: [{ allowAtRootLevel: true }],
},
{
code: "if (true) {fs.fooSync();}",
options: [{ allowAtRootLevel: true }],
},
],
invalid: [
{
code: "var foo = fs.fooSync();",
errors: [
{
messageId: "noSync",
data: { propertyName: "fooSync" },
},
],
},
{
code: "var foo = fs.fooSync();",
options: [{ allowAtRootLevel: false }],
errors: [
{
messageId: "noSync",
data: { propertyName: "fooSync" },
},
],
},
{
code: "if (true) {fs.fooSync();}",
errors: [
{
messageId: "noSync",
data: { propertyName: "fooSync" },
},
],
},
{
code: "var foo = fs.fooSync;",
errors: [
{
messageId: "noSync",
data: { propertyName: "fooSync" },
},
],
},
{
code: "function someFunction() {fs.fooSync();}",
errors: [
{
messageId: "noSync",
data: { propertyName: "fooSync" },
},
],
},
{
code: "function someFunction() {fs.fooSync();}",
options: [{ allowAtRootLevel: true }],
errors: [
{
messageId: "noSync",
data: { propertyName: "fooSync" },
},
],
},
{
code: "var a = function someFunction() {fs.fooSync();}",
options: [{ allowAtRootLevel: true }],
errors: [
{
messageId: "noSync",
data: { propertyName: "fooSync" },
},
],
},
],
});