Skip to content

Commit 6c5eb44

Browse files
authored
Test: add tests for html (closes #21) (#28)
1 parent ec8f026 commit 6c5eb44

File tree

5 files changed

+101
-2
lines changed

5 files changed

+101
-2
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<title>'</title>
7+
<link rel="stylesheet" href="style.css" type="text/css">
8+
</head>
9+
10+
<body class="in wf-active">
11+
<p>'</p>
12+
<script src="script.js"></script>
13+
</body>
14+
15+
</html>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.wf-active {
2+
color: red;
3+
}
4+
5+
.in {
6+
font-weight: bold;
7+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<title>'</title>
7+
<link rel="stylesheet" href="style.css" type="text/css">
8+
</head>
9+
10+
<body class="b a">
11+
<p>'</p>
12+
<script src="script.js"></script>
13+
</body>
14+
15+
</html>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.a {
2+
color: red;
3+
}
4+
5+
.b {
6+
font-weight: bold;
7+
}

test/integration.js

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import test from 'ava';
22
import path from 'path';
33
import fs from 'fs-extra';
44
import rcsCore from 'rcs-core';
5+
import { minify } from 'html-minifier';
56

67
import rcs from '../';
78

8-
const testCwd = 'test/files/testCache';
9-
const fixturesCwd = 'test/files/fixtures';
9+
const testFiles = 'test/files';
10+
const testCwd = path.join(testFiles, 'testCache');
11+
const fixturesCwd = path.join(testFiles, 'fixtures');
1012

1113
test.beforeEach(() => {
1214
rcsCore.nameGenerator.setAlphabet('#abcdefghijklmnopqrstuvwxyz');
@@ -54,3 +56,56 @@ test.cb('issue #19 | detect one file', (t) => {
5456
});
5557
});
5658
});
59+
60+
test.cb('issue #21 | with auto', (t) => {
61+
const issueFixture = path.join(testFiles, 'issue21/fixtures');
62+
const issueResults = path.join(testFiles, 'issue21/results');
63+
64+
rcs.process.auto(['style.css', 'index.html'], {
65+
newPath: testCwd,
66+
cwd: issueFixture,
67+
}, (err) => {
68+
t.falsy(err);
69+
70+
const newCss = fs.readFileSync(path.join(testCwd, '/style.css'), 'utf8');
71+
const newHtml = fs.readFileSync(path.join(testCwd, '/index.html'), 'utf8');
72+
const expectedCss = fs.readFileSync(path.join(issueResults, '/style.css'), 'utf8');
73+
const expectedHtml = fs.readFileSync(path.join(issueResults, '/index.html'), 'utf8');
74+
75+
t.is(newCss, expectedCss);
76+
t.is(
77+
minify(newHtml, { collapseWhitespace: true }),
78+
minify(expectedHtml, { collapseWhitespace: true }),
79+
);
80+
81+
t.end();
82+
});
83+
});
84+
85+
test.cb('issue #21 | with seperated process functions', (t) => {
86+
const issueFixture = path.join(testFiles, 'issue21/fixtures');
87+
const issueResults = path.join(testFiles, 'issue21/results');
88+
89+
rcs.process.css('style.css', {
90+
newPath: testCwd,
91+
cwd: issueFixture,
92+
}, () => {
93+
rcs.process.html('index.html', {
94+
newPath: testCwd,
95+
cwd: issueFixture,
96+
}, () => {
97+
const newCss = fs.readFileSync(path.join(testCwd, '/style.css'), 'utf8');
98+
const newHtml = fs.readFileSync(path.join(testCwd, '/index.html'), 'utf8');
99+
const expectedCss = fs.readFileSync(path.join(issueResults, '/style.css'), 'utf8');
100+
const expectedHtml = fs.readFileSync(path.join(issueResults, '/index.html'), 'utf8');
101+
102+
t.is(newCss, expectedCss);
103+
t.is(
104+
minify(newHtml, { collapseWhitespace: true }),
105+
minify(expectedHtml, { collapseWhitespace: true }),
106+
);
107+
108+
t.end();
109+
});
110+
});
111+
});

0 commit comments

Comments
 (0)