]> git.proxmox.com Git - pve-eslint.git/blobdiff - eslint/tests/_utils/index.js
import 7.12.1 upstream release
[pve-eslint.git] / eslint / tests / _utils / index.js
index 0431e3aced4afd3369cda54ac6cf6ab3c4f8c0c4..7615613d25c21a2bb297521e494070d9d25ab515 100644 (file)
@@ -1,5 +1,13 @@
+/**
+ * @fileoverview Utilities used in tests
+ */
+
 "use strict";
 
+//-----------------------------------------------------------------------------
+// Requirements
+//-----------------------------------------------------------------------------
+
 const {
     defineInMemoryFs,
     defineConfigArrayFactoryWithInMemoryFileSystem,
@@ -9,6 +17,11 @@ const {
     defineESLintWithInMemoryFileSystem
 } = require("./in-memory-fs");
 
+const { createTeardown, addFile } = require("fs-teardown");
+
+//-----------------------------------------------------------------------------
+// Helpers
+//-----------------------------------------------------------------------------
 
 /**
  * Prevents leading spaces in a multiline template literal from appearing in the resulting string
@@ -27,6 +40,26 @@ function unIndent(strings, ...values) {
     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,
@@ -35,5 +68,6 @@ module.exports = {
     defineCascadingConfigArrayFactoryWithInMemoryFileSystem,
     defineFileEnumeratorWithInMemoryFileSystem,
     defineCLIEngineWithInMemoryFileSystem,
-    defineESLintWithInMemoryFileSystem
+    defineESLintWithInMemoryFileSystem,
+    createCustomTeardown
 };