Debian Codegraph @

fs2/test/symlink.js

raw
1 "use strict";
2
3 const { promisify } = require("deferred")
4 , fs = require("fs")
5 , path = require("path")
6 , { resolve } = path
7 , lstat = promisify(fs.lstat)
8 , unlink = promisify(fs.unlink)
9 , rmdir = require("../rmdir")
10 , rootPath = resolve(__dirname, "./__playground/symlink")
11 , base = resolve(rootPath, "from")
12 , regular = resolve(rootPath, "foo")
13 , deep = resolve(rootPath, "foo/bar");
14
15 module.exports = function (t) {
16 return {
17 Regular(a, d) {
18 t(base, regular)
19 .then(result => {
20 a(result, true);
21 return lstat(regular);
22 })
23 .then(stats => { a(stats.isSymbolicLink(), true); })
24 .then(() => unlink(regular))
25 .done(d, d);
26 },
27 Intermediate(a, d) {
28 t(base, deep, { intermediate: true })
29 .then(result => {
30 a(result, true);
31 return lstat(deep);
32 })
33 .then(stats => { a(stats.isSymbolicLink(), true); })
34 .then(() => rmdir(path.dirname(deep), { force: true }))
35 .done(d, d);
36 },
37 Loose(a, d) {
38 t(base, regular)
39 .then(result => {
40 a(result, true);
41 return lstat(regular);
42 })
43 .then(stats => { a(stats.isSymbolicLink(), true); })
44 .then(() => t(base, regular, { loose: true }))
45 .then(result => {
46 a(result, false);
47 return unlink(regular);
48 })
49 .done(d, d);
50 },
51 Force(a, d) {
52 t(base, regular)
53 .then(result => {
54 a(result, true);
55 return lstat(regular);
56 })
57 .then(stats => { a(stats.isSymbolicLink(), true); })
58 .then(() => t(resolve(rootPath, "other"), regular, { force: true }))
59 .then(result => {
60 a(result, true);
61 return lstat(regular);
62 })
63 .then(stats => { a(stats.isSymbolicLink(), true); })
64 .then(() => unlink(regular))
65 .done(d, d);
66 },
67 Error(a, d) {
68 t(base, deep)(a.never, () => { a.ok(true, ""); }).done(d, d);
69 }
70 };
71 };