/
toType-option.test.js
106 lines (98 loc) · 2.31 KB
/
toType-option.test.js
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
import path from "path";
import { runEmit } from "./helpers/run";
const FIXTURES_DIR_NORMALIZED = path
.join(__dirname, "fixtures")
.replace(/\\/g, "/");
describe("toType option", () => {
it("should copy a file to a new file", (done) => {
runEmit({
expectedAssetKeys: ["new-file.txt"],
patterns: [
{
from: "file.txt",
to: "new-file.txt",
toType: "file",
},
],
})
.then(done)
.catch(done);
});
it("should copy a file to a new directory", (done) => {
runEmit({
expectedAssetKeys: ["new-file.txt/file.txt"],
patterns: [
{
from: "file.txt",
to: "new-file.txt",
toType: "dir",
},
],
})
.then(done)
.catch(done);
});
it("should copy a file to a new directory", (done) => {
runEmit({
expectedAssetKeys: [
"directory/directoryfile.txt-new-directoryfile.txt.5d7817ed5bc246756d73.ac7f6fcb65ddfcc43b2c-ac7f6fcb65ddfcc43b2c.txt",
],
patterns: [
{
from: "directory/directoryfile.*",
to: "[path][base]-new-[name][ext].[contenthash].[hash]-[fullhash][ext]",
toType: "template",
},
],
})
.then(done)
.catch(done);
});
it("should copy a file to a new file with no extension", (done) => {
runEmit({
expectedAssetKeys: ["newname"],
patterns: [
{
from: "file.txt",
to: "newname",
toType: "file",
},
],
})
.then(done)
.catch(done);
});
it("should copy a file to a new directory with an extension", (done) => {
runEmit({
expectedAssetKeys: ["newdirectory.ext/file.txt"],
patterns: [
{
from: "file.txt",
to: "newdirectory.ext",
toType: "dir",
},
],
})
.then(done)
.catch(done);
});
it("should warn when file not found and stats is undefined", (done) => {
runEmit({
expectedAssetKeys: [],
expectedErrors: [
new Error(
`unable to locate '${FIXTURES_DIR_NORMALIZED}/nonexistent.txt' glob`
),
],
patterns: [
{
from: "nonexistent.txt",
to: ".",
toType: "dir",
},
],
})
.then(done)
.catch(done);
});
});