-
Notifications
You must be signed in to change notification settings - Fork 24
/
test.js
76 lines (69 loc) · 2.31 KB
/
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
const mock = require("mock-fs");
const assert = require("assert");
const fs = require("fs");
const {
onCreateWebpackConfig, // no need to test this.
onPostBuild,
} = require("./gatsby-node");
describe("onPostBuild", function () {
beforeEach(function () {
mock({
public: {
"script.js": "javascript",
"style.css": "css",
"image.png": "png",
static: {
"one.jpg": "jpeg",
"two.png": "png",
},
resources: {
"textfile.txt": "text",
},
},
});
});
afterEach(mock.restore);
after(mock.restore); // for nyc to run...
it("should copy files with path", function (done) {
onPostBuild({ pathPrefix: "/target/" }, {}).then(function () {
const files = fs.readdirSync("public/target");
const static = fs.readdirSync("public/target/static");
assert.deepEqual(files, ["script.js", "static", "style.css"]);
assert.deepEqual(static, ["one.jpg", "two.png"]);
done();
});
});
it("should copy files with domain", function (done) {
onPostBuild({ pathPrefix: "http://www.domain.com/target/" }, {}).then(
function () {
const files = fs.readdirSync("public/target");
const static = fs.readdirSync("public/target/static");
assert.deepEqual(files, ["script.js", "static", "style.css"]);
assert.deepEqual(static, ["one.jpg", "two.png"]);
done();
},
);
});
it("should copy specific fileTypes other than static files", function (done) {
onPostBuild({ pathPrefix: "/assets/" }, { fileTypes: ["css", "png"] }).then(
function () {
const files = fs.readdirSync("public/assets");
const static = fs.readdirSync("public/assets/static");
assert.deepEqual(files, ["image.png", "static", "style.css"]);
assert.deepEqual(static, ["one.jpg", "two.png"]);
done();
},
);
});
it("should copy specific paths", function (done) {
onPostBuild({ pathPrefix: "/assets/" }, { paths: ["resources"] }).then(
function () {
const files = fs.readdirSync("public/assets");
const resources = fs.readdirSync("public/assets/resources");
assert.deepEqual(files, ["resources", "script.js", "style.css"]);
assert.deepEqual(resources, ["textfile.txt"]);
done();
},
);
});
});