UNPKG

2.88 kBPlain TextView Raw
1import * as fse from "fs-extra";
2import { expect } from "chai";
3import path from "./assert_path";
4import helper from "./helper";
5import * as jetpack from "..";
6
7describe("symlink", () => {
8 beforeEach(helper.setCleanTestCwd);
9 afterEach(helper.switchBackToCorrectCwd);
10
11 describe("can create a symlink", () => {
12 const expectations = () => {
13 expect(fse.lstatSync("symlink").isSymbolicLink()).to.equal(true);
14 expect(fse.readlinkSync("symlink")).to.equal("some_path");
15 };
16
17 it("sync", () => {
18 jetpack.symlink("some_path", "symlink");
19 expectations();
20 });
21
22 it("async", done => {
23 jetpack.symlinkAsync("some_path", "symlink").then(() => {
24 expectations();
25 done();
26 });
27 });
28 });
29
30 describe("can create nonexistent parent directories", () => {
31 const expectations = () => {
32 expect(fse.lstatSync("a/b/symlink").isSymbolicLink()).to.equal(true);
33 };
34
35 it("sync", () => {
36 jetpack.symlink("whatever", "a/b/symlink");
37 expectations();
38 });
39
40 it("async", done => {
41 jetpack.symlinkAsync("whatever", "a/b/symlink").then(() => {
42 expectations();
43 done();
44 });
45 });
46 });
47
48 describe("respects internal CWD of jetpack instance", () => {
49 const preparations = () => {
50 fse.mkdirsSync("a/b");
51 };
52
53 const expectations = () => {
54 expect(fse.lstatSync("a/b/symlink").isSymbolicLink()).to.equal(true);
55 };
56
57 it("sync", () => {
58 const jetContext = jetpack.cwd("a/b");
59 preparations();
60 jetContext.symlink("whatever", "symlink");
61 expectations();
62 });
63
64 it("async", done => {
65 const jetContext = jetpack.cwd("a/b");
66 preparations();
67 jetContext.symlinkAsync("whatever", "symlink").then(() => {
68 expectations();
69 done();
70 });
71 });
72 });
73
74 describe("input validation", () => {
75 const tests = [
76 { type: "sync", method: jetpack.symlink as any, methodName: "symlink" },
77 {
78 type: "async",
79 method: jetpack.symlinkAsync as any,
80 methodName: "symlinkAsync"
81 }
82 ];
83
84 describe('"symlinkValue" argument', () => {
85 tests.forEach(test => {
86 it(test.type, () => {
87 expect(() => {
88 test.method(undefined, "abc");
89 }).to.throw(
90 `Argument "symlinkValue" passed to ${
91 test.methodName
92 }(symlinkValue, path) must be a string. Received undefined`
93 );
94 });
95 });
96 });
97
98 describe('"path" argument', () => {
99 tests.forEach(test => {
100 it(test.type, () => {
101 expect(() => {
102 test.method("xyz", undefined);
103 }).to.throw(
104 `Argument "path" passed to ${
105 test.methodName
106 }(symlinkValue, path) must be a string. Received undefined`
107 );
108 });
109 });
110 });
111 });
112});