Skip to content

Commit

Permalink
Chore: Test fixes for config-array-factory.js (#13)
Browse files Browse the repository at this point in the history
* Chore: Fix ConfigArrayFactory tests

* Make more tests pass

* More tests passing

* Fix failing tests

* Normalize file paths in tests

* Add longer timeout for CI

* Try to fix tests again

* Adjust tests

* small test

* Use temp-dir to get actual temp directory
  • Loading branch information
nzakas committed Oct 27, 2020
1 parent 62e7738 commit 7890e02
Show file tree
Hide file tree
Showing 5 changed files with 588 additions and 273 deletions.
7 changes: 5 additions & 2 deletions package.json
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
@@ -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
@@ -0,0 +1,6 @@
module.exports = {
rules: {
"eqeqeq": ["error"],
"curly": ["error"]
}
};
5 changes: 5 additions & 0 deletions tests/fixtures/eslint-recommended.js
@@ -0,0 +1,5 @@
module.exports = {
rules: {
"bar": "error"
}
};

0 comments on commit 7890e02

Please sign in to comment.