-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.spec.js
More file actions
73 lines (63 loc) · 1.91 KB
/
index.spec.js
File metadata and controls
73 lines (63 loc) · 1.91 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
/*jshint mocha:true*/
"use strict";
/**
* Tests for index.js
*
* @author George Borisov <git@gir.me.uk>
* @copyright George Borisov 2017
* @license LGPL-3.0
*/
const { strictEqual } = require("assert");
const subject = require("./index.js");
describe("index.js", function () {
const contents = {
"css/style1.css": "body { font-size: 12px; }",
"css/style2.css": "body { padding: 1em; }",
// tests the two different types of link definition and multiple stylesheets
"test1.html":
'<link rel="stylesheet" href="/css/style1.css" inline><link rel=stylesheet href=/css/style2.css inline>',
// tests multiple unavailable stylesheets
"test2.html":
'<link rel="stylesheet" href="/css/style3.css" inline><link rel="stylesheet" href="/css/style4.css" inline>',
// tests that non-matching link definition is ignored
"test3.html": '<link rel="stylesheet" href="/css/style1.css">',
};
const files = {
// tests that non HTML / CSS file is ignored
"foo.png": {},
};
const plugin = subject();
let file;
Object.keys(contents).forEach((file) => {
files[file] = {
contents: new Buffer.from(contents[file]),
path: file,
};
});
it("return a function", function () {
strictEqual(typeof plugin, "function");
});
plugin(files, undefined, function () {
it("inlines things that should be inlined", function () {
strictEqual(
files["test1.html"].contents.toString(),
"<style>" +
contents["css/style1.css"] +
"</style>" +
"<style>" +
contents["css/style2.css"] +
"</style>"
);
});
it("does not inline things that should not be inlined", function () {
strictEqual(
files["test2.html"].contents.toString(),
contents["test2.html"]
);
strictEqual(
files["test3.html"].contents.toString(),
contents["test3.html"]
);
});
});
});