-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
116 lines (105 loc) · 2.64 KB
/
test.js
File metadata and controls
116 lines (105 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import mock from "mock-fs";
import fs from "fs";
import { join } from "path";
import test from "ava";
import globConcat, { MESSAGES } from "./index.js";
function readFile(filename) {
return mock.bypass(() =>
fs.readFileSync(join(process.cwd(), filename), "utf-8"),
);
}
test.beforeEach(() => {
mock({
"./fixtures": mock.load("./fixtures", { recursive: true }),
"./expected": {},
});
});
test("concatenate two files", async (t) => {
return (
globConcat(
["./fixtures/file-1.md", "./fixtures/file-2.md"],
"./expected/concat.md",
{ fs: fs },
)
.then((result) => {
t.is(
result.content,
readFile("./expected/concat.md"),
"content matches",
);
t.assert(result.map, "content matches");
})
// No errors should be thrown, so fail the test if one is
.catch((error) => {
t.fail(error.message);
})
);
});
test("concatenate with globs", async (t) => {
const output = "./expected/concat.md";
return (
globConcat(["./fixtures/*.md"], output, { fs: fs })
.then((result) => {
t.is(
result.inputFiles.length,
2,
"number of input files found matches expected",
);
t.is(result.content, readFile(output), "content matches");
t.assert(result.map, "sourcemap exists");
})
// No errors should be thrown, so fail the test if one is
.catch((error) => {
t.fail(error.message);
})
);
});
test("concatenate with globs to stdout", async (t) => {
return (
globConcat(["./fixtures/*.css"], undefined, { fs: fs })
.then((result) => {
t.is(
result.inputFiles.length,
2,
"number of input files found matches expected",
);
// Check the stdout for the expected content
t.is(
result.content,
readFile("./expected/concat-stdout.css"),
"content matches",
);
})
// No errors should be thrown, so fail the test if one is
.catch((error) => {
t.fail(error.message);
})
);
});
test("empty file with error", async (t) => {
const output = "./expected/concat.md";
return globConcat(["./fixtures/file-empty.md"], output, {
allowEmpty: false,
fs: fs,
})
.then((result) => {
t.is(result.content, readFile(output), "content matches");
t.assert(result.map, "sourcemap content matches");
})
.catch((error) => {
t.is(
error.message,
MESSAGES.empty_file("./fixtures/file-empty.md", process.cwd()),
);
});
});
test("no file input provided to script", async (t) => {
return globConcat([], undefined, { allowEmpty: false, fs: fs })
.then(() => t.fail("no input files should throw an error"))
.catch((error) => {
t.is(error.message, MESSAGES.no_input_files);
});
});
test.afterEach(() => {
mock.restore();
});