Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'test/fixtures/clean-snapshot.js')
-rw-r--r--test/fixtures/clean-snapshot.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/fixtures/clean-snapshot.js b/test/fixtures/clean-snapshot.js
new file mode 100644
index 000000000..037155eea
--- /dev/null
+++ b/test/fixtures/clean-snapshot.js
@@ -0,0 +1,19 @@
+// XXX: this also cleans quoted " in json snapshots
+// ideally this could be avoided but its easier to just
+// run this command inside cleanSnapshot
+const normalizePath = (str) => str
+ .replace(/\r\n/g, '\n') // normalize line endings (for ini)
+ .replace(/[A-z]:\\/g, '\\') // turn windows roots to posix ones
+ .replace(/\\+/g, '/') // replace \ with /
+
+const cleanCwd = (path) => normalizePath(path)
+ .replace(new RegExp(normalizePath(process.cwd()), 'g'), '{CWD}')
+
+const cleanDate = (str) =>
+ str.replace(/\d{4}-\d{2}-\d{2}T\d{2}[_:]\d{2}[_:]\d{2}[_:]\d{3}Z/g, '{DATE}')
+
+module.exports = {
+ normalizePath,
+ cleanCwd,
+ cleanDate,
+}