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

Chore: Test fixes for config-array-factory.js #13

Merged
merged 10 commits into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"scripts": {
"lint": "eslint .",
"test": "mocha -R progress -c tests/lib/shared",
"test": "mocha -R progress -c tests/lib/shared tests/lib/config-array-factory.js",
"generate-release": "eslint-generate-release",
"generate-alpharelease": "eslint-generate-prerelease alpha",
"generate-betarelease": "eslint-generate-prerelease beta",
Expand All @@ -39,7 +39,10 @@
"eslint-plugin-jsdoc": "^22.1.0",
"eslint-plugin-node": "^11.1.0",
"eslint-release": "^3.1.2",
"mocha": "^8.1.1"
"fs-teardown": "^0.1.0",
"mocha": "^8.1.1",
"sinon": "^9.2.0",
"temp-dir": "^2.0.0"
},
"dependencies": {
"ajv": "^6.12.4",
Expand Down
58 changes: 58 additions & 0 deletions tests/_utils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* @fileoverview Utilities used in tests
*/

"use strict";

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

const { createTeardown, addFile } = require("fs-teardown");

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

/**
* Prevents leading spaces in a multiline template literal from appearing in the resulting string
* @param {string[]} strings The strings in the template literal
* @param {any[]} values The interpolation values in the template literal.
* @returns {string} The template literal, with spaces removed from all lines
*/
function unIndent(strings, ...values) {
const text = strings
.map((s, i) => (i === 0 ? s : values[i - 1] + s))
.join("");
const lines = text.replace(/^\n/u, "").replace(/\n\s*$/u, "").split("\n");
const lineIndents = lines.filter(line => line.trim()).map(line => line.match(/ */u)[0].length);
const minLineIndent = Math.min(...lineIndents);

return lines.map(line => line.slice(minLineIndent)).join("\n");
}

/**
* Creates a new filesystem volume at the given location with the given files.
* @param {Object} desc A description of the filesystem volume to create.
* @param {string} desc.cwd The current working directory ESLint is using.
* @param {Object} desc.files A map of filename to file contents to create.
* @returns {Teardown} An object with prepare(), cleanup(), and getPath()
* methods.
*/
function createCustomTeardown({ cwd, files = {} }) {
const { prepare, cleanup, getPath } = createTeardown(
cwd,
...Object.keys(files).map(filename => addFile(filename, files[filename]))
);

return { prepare, cleanup, getPath };
}

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

module.exports = {
unIndent,
createCustomTeardown
};
6 changes: 6 additions & 0 deletions tests/fixtures/eslint-all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
rules: {
"eqeqeq": ["error"],
"curly": ["error"]
}
};
5 changes: 5 additions & 0 deletions tests/fixtures/eslint-recommended.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
rules: {
"bar": "error"
}
};