Skip to content
Permalink
Browse files
Chore: Refactor comments of tests (#14956)
  • Loading branch information
wafuwafu13 committed Aug 25, 2021
1 parent 396a0e3 commit db1518374a5e88efedf1ed4609d879f3091af74f
Show file tree
Hide file tree
Showing 73 changed files with 312 additions and 27 deletions.
@@ -4,9 +4,17 @@
*/
"use strict";

//-----------------------------------------------------------------------------
// Requirements
//-----------------------------------------------------------------------------

const path = require("path");
const { Volume, createFsFromVolume } = require("memfs");

//-----------------------------------------------------------------------------
// Helpers
//-----------------------------------------------------------------------------

/**
* Define in-memory file system.
* @param {Object} options The options.
@@ -52,6 +60,10 @@ function defineInMemoryFs({
return fs;
}

//-----------------------------------------------------------------------------
// Exports
//-----------------------------------------------------------------------------

module.exports = {
defineInMemoryFs
};
@@ -5,13 +5,25 @@

"use strict";

//-----------------------------------------------------------------------------
// Requirements
//-----------------------------------------------------------------------------

const childProcess = require("child_process");
const fs = require("fs");
const assert = require("chai").assert;
const path = require("path");

//------------------------------------------------------------------------------
// Data
//------------------------------------------------------------------------------

const EXECUTABLE_PATH = path.resolve(path.join(__dirname, "../../bin/eslint.js"));

//-----------------------------------------------------------------------------
// Helpers
//-----------------------------------------------------------------------------

/**
* Returns a Promise for when a child process exits
* @param {ChildProcess} exitingProcess The child process
@@ -48,6 +60,10 @@ function getOutput(runningProcess) {
return awaitExit(runningProcess).then(() => ({ stdout, stderr }));
}

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

describe("bin/eslint.js", () => {
const forkedProcesses = new Set();

@@ -13,6 +13,10 @@ const assert = require("chai").assert;
const eslintAll = require("../../conf/eslint-all");
const rules = eslintAll.rules;

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

describe("eslint-all", () => {
it("should only include rules", () => {
const ruleNames = Object.keys(rules);
@@ -13,6 +13,10 @@ const assert = require("chai").assert;
const eslintRecommended = require("../../conf/eslint-recommended");
const rules = eslintRecommended.rules;

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

describe("eslint-recommended", () => {
it("should configure recommended rules as error", () => {
assert.strictEqual(rules["no-undef"], "error");
@@ -4,6 +4,10 @@
*/
"use strict";

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

const fs = require("fs");
const path = require("path");
const os = require("os");
@@ -17,6 +21,10 @@ const {
const { createCustomTeardown } = require("../../_utils");
const { FileEnumerator } = require("../../../lib/cli-engine/file-enumerator");

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

describe("FileEnumerator", () => {
describe("'iterateFiles(patterns)' method should iterate files and configs.", () => {
describe("with three directories ('lib', 'lib/nested', 'test') that contains 'one.js' and 'two.js'", () => {
@@ -14,6 +14,10 @@ const assert = require("chai").assert,
proxyquire = require("proxyquire"),
sinon = require("sinon");

//-----------------------------------------------------------------------------
// Helpers
//-----------------------------------------------------------------------------

/*
* Chalk protects its methods so we need to inherit from it
* for Sinon to work.
@@ -5,9 +5,17 @@

"use strict";

//-----------------------------------------------------------------------------
// Requirements
//-----------------------------------------------------------------------------

const assert = require("chai").assert;
const loadRules = require("../../../lib/cli-engine/load-rules");

//-----------------------------------------------------------------------------
// Tests
//-----------------------------------------------------------------------------

describe("when given an invalid rules directory", () => {
it("should throw an error", () => {
assert.throws(() => {
@@ -5,9 +5,17 @@

"use strict";

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

const assert = require("chai").assert;
const applyDisableDirectives = require("../../../lib/linter/apply-disable-directives");

//-----------------------------------------------------------------------------
// Helpers
//-----------------------------------------------------------------------------

/**
* Creates a ParentComment for a given range.
* @param {[number, number]} range total range of the comment
@@ -22,6 +30,10 @@ function createParentComment(range, value, ruleIds = []) {
};
}

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

describe("apply-disable-directives", () => {
describe("/* eslint-disable */ comments without rules", () => {
it("keeps problems before the comment on the same line", () => {
@@ -1,8 +1,16 @@
"use strict";

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

const assert = require("chai").assert;
const interpolate = require("../../../lib/linter/interpolate");

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

describe("interpolate()", () => {
it("passes through text without {{ }}", () => {
const message = "This is a very important message!";
@@ -17,8 +17,9 @@ const assert = require("assert"),
createEmitter = require("../../../lib/linter/safe-emitter"),
NodeEventGenerator = require("../../../lib/linter/node-event-generator");


//------------------------------------------------------------------------------
// Tests
// Constants
//------------------------------------------------------------------------------

const ESPREE_CONFIG = {
@@ -31,6 +32,10 @@ const ESPREE_CONFIG = {

const STANDARD_ESQUERY_OPTION = { visitorKeys: vk.KEYS, fallback: Traverser.getKeys };

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

describe("NodeEventGenerator", () => {
EventGeneratorTester.testEventGeneratorInterface(
new NodeEventGenerator(createEmitter(), STANDARD_ESQUERY_OPTION)
@@ -5,9 +5,17 @@

"use strict";

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

const createEmitter = require("../../../lib/linter/safe-emitter");
const assert = require("chai").assert;

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

describe("safe-emitter", () => {
describe("emit() and on()", () => {
it("allows listeners to be registered calls them when emitted", () => {
@@ -1,8 +1,16 @@
"use strict";

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

const { getListSize } = require("../../../lib/linter/timing");
const assert = require("chai").assert;

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

describe("timing", () => {
describe("getListSize()", () => {
after(() => {
@@ -12,6 +12,10 @@
const rule = require("../../../lib/rules/array-callback-return"),
{ RuleTester } = require("../../../lib/rule-tester");

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

const ruleTester = new RuleTester();

const allowImplicitOptions = [{ allowImplicit: true }];
@@ -18,6 +18,7 @@ const parser = baseParser.bind(null, "arrow-parens");
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } });

const valid = [
@@ -48,6 +48,10 @@ function makeError(name, complexity, max) {
};
}

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2021 } });

ruleTester.run("complexity", rule, {
@@ -13,7 +13,7 @@ const rule = require("../../../lib/rules/curly"),
{ RuleTester } = require("../../../lib/rule-tester");

//------------------------------------------------------------------------------
// Helpers
// Tests
//------------------------------------------------------------------------------

const ruleTester = new RuleTester();
@@ -4,9 +4,17 @@
*/
"use strict";

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

const rule = require("../../../lib/rules/default-param-last");
const { RuleTester } = require("../../../lib/rule-tester");

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

const SHOULD_BE_LAST = "shouldBeLast";

const ruleTester = new RuleTester({
@@ -28,6 +28,10 @@ function q(str) {
return `"${str}"`;
}

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

ruleTester.run("dot-notation", rule, {
valid: [
"a.b;",
@@ -13,7 +13,7 @@ const rule = require("../../../lib/rules/for-direction");
const { RuleTester } = require("../../../lib/rule-tester");

//------------------------------------------------------------------------------
// Helpers
// Tests
//------------------------------------------------------------------------------

const ruleTester = new RuleTester();
@@ -15,6 +15,7 @@ const rule = require("../../../lib/rules/global-require"),
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

const ruleTester = new RuleTester();

const valid = [
@@ -15,7 +15,7 @@ const fs = require("fs");
const path = require("path");

//------------------------------------------------------------------------------
// Tests
// Helpers
//------------------------------------------------------------------------------

const fixture = fs.readFileSync(path.join(__dirname, "../../fixtures/rules/indent/indent-invalid-fixture-1.js"), "utf8");
@@ -56,6 +56,10 @@ function expectedErrors(providedIndentType, providedErrors) {
}));
}

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 8, ecmaFeatures: { jsx: true } } });

ruleTester.run("indent", rule, {
@@ -12,6 +12,10 @@
const rule = require("../../../lib/rules/init-declarations"),
{ RuleTester } = require("../../../lib/rule-tester");

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

const ruleTester = new RuleTester();

ruleTester.run("init-declarations", rule, {
@@ -12,6 +12,10 @@
const rule = require("../../../lib/rules/jsx-quotes"),
{ RuleTester } = require("../../../lib/rule-tester");

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } });

ruleTester.run("jsx-quotes", rule, {
@@ -12,6 +12,10 @@
const rule = require("../../../lib/rules/key-spacing"),
{ RuleTester } = require("../../../lib/rule-tester");

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

const ruleTester = new RuleTester();

ruleTester.run("key-spacing", rule, {
@@ -15,6 +15,7 @@ const { RuleTester } = require("../../../lib/rule-tester");
//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------

const alwaysError = { messageId: "always" };
const neverError = { messageId: "never" };

@@ -7,6 +7,7 @@
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

const rule = require("../../../lib/rules/max-lines-per-function");
const { RuleTester } = require("../../../lib/rule-tester");

0 comments on commit db15183

Please sign in to comment.