From 4a9635c9446e4511567404ab062c7cd3c2ca4326 Mon Sep 17 00:00:00 2001
From: JPeer264
Date: Sun, 26 Aug 2018 14:54:32 +0200
Subject: [PATCH] Test: add tests for html (closes #21)
---
test/files/issue21/fixtures/index.html | 15 +++++++
test/files/issue21/fixtures/style.css | 7 +++
test/files/issue21/results/index.html | 15 +++++++
test/files/issue21/results/style.css | 7 +++
test/integration.js | 59 +++++++++++++++++++++++++-
5 files changed, 101 insertions(+), 2 deletions(-)
create mode 100644 test/files/issue21/fixtures/index.html
create mode 100644 test/files/issue21/fixtures/style.css
create mode 100644 test/files/issue21/results/index.html
create mode 100644 test/files/issue21/results/style.css
diff --git a/test/files/issue21/fixtures/index.html b/test/files/issue21/fixtures/index.html
new file mode 100644
index 0000000..a80eb8e
--- /dev/null
+++ b/test/files/issue21/fixtures/index.html
@@ -0,0 +1,15 @@
+
+
+
+
+
+ '
+
+
+
+
+ '
+
+
+
+
diff --git a/test/files/issue21/fixtures/style.css b/test/files/issue21/fixtures/style.css
new file mode 100644
index 0000000..3e9f853
--- /dev/null
+++ b/test/files/issue21/fixtures/style.css
@@ -0,0 +1,7 @@
+.wf-active {
+ color: red;
+}
+
+.in {
+ font-weight: bold;
+}
diff --git a/test/files/issue21/results/index.html b/test/files/issue21/results/index.html
new file mode 100644
index 0000000..cb8eefb
--- /dev/null
+++ b/test/files/issue21/results/index.html
@@ -0,0 +1,15 @@
+
+
+
+
+
+ '
+
+
+
+
+ '
+
+
+
+
diff --git a/test/files/issue21/results/style.css b/test/files/issue21/results/style.css
new file mode 100644
index 0000000..5167650
--- /dev/null
+++ b/test/files/issue21/results/style.css
@@ -0,0 +1,7 @@
+.a {
+ color: red;
+}
+
+.b {
+ font-weight: bold;
+}
diff --git a/test/integration.js b/test/integration.js
index 59a1628..ab67354 100644
--- a/test/integration.js
+++ b/test/integration.js
@@ -2,11 +2,13 @@ import test from 'ava';
import path from 'path';
import fs from 'fs-extra';
import rcsCore from 'rcs-core';
+import { minify } from 'html-minifier';
import rcs from '../';
-const testCwd = 'test/files/testCache';
-const fixturesCwd = 'test/files/fixtures';
+const testFiles = 'test/files';
+const testCwd = path.join(testFiles, 'testCache');
+const fixturesCwd = path.join(testFiles, 'fixtures');
test.beforeEach(() => {
rcsCore.nameGenerator.setAlphabet('#abcdefghijklmnopqrstuvwxyz');
@@ -54,3 +56,56 @@ test.cb('issue #19 | detect one file', (t) => {
});
});
});
+
+test.cb('issue #21 | with auto', (t) => {
+ const issueFixture = path.join(testFiles, 'issue21/fixtures');
+ const issueResults = path.join(testFiles, 'issue21/results');
+
+ rcs.process.auto(['style.css', 'index.html'], {
+ newPath: testCwd,
+ cwd: issueFixture,
+ }, (err) => {
+ t.falsy(err);
+
+ const newCss = fs.readFileSync(path.join(testCwd, '/style.css'), 'utf8');
+ const newHtml = fs.readFileSync(path.join(testCwd, '/index.html'), 'utf8');
+ const expectedCss = fs.readFileSync(path.join(issueResults, '/style.css'), 'utf8');
+ const expectedHtml = fs.readFileSync(path.join(issueResults, '/index.html'), 'utf8');
+
+ t.is(newCss, expectedCss);
+ t.is(
+ minify(newHtml, { collapseWhitespace: true }),
+ minify(expectedHtml, { collapseWhitespace: true }),
+ );
+
+ t.end();
+ });
+});
+
+test.cb('issue #21 | with seperated process functions', (t) => {
+ const issueFixture = path.join(testFiles, 'issue21/fixtures');
+ const issueResults = path.join(testFiles, 'issue21/results');
+
+ rcs.process.css('style.css', {
+ newPath: testCwd,
+ cwd: issueFixture,
+ }, () => {
+ rcs.process.html('index.html', {
+ newPath: testCwd,
+ cwd: issueFixture,
+ }, () => {
+ const newCss = fs.readFileSync(path.join(testCwd, '/style.css'), 'utf8');
+ const newHtml = fs.readFileSync(path.join(testCwd, '/index.html'), 'utf8');
+ const expectedCss = fs.readFileSync(path.join(issueResults, '/style.css'), 'utf8');
+ const expectedHtml = fs.readFileSync(path.join(issueResults, '/index.html'), 'utf8');
+
+ t.is(newCss, expectedCss);
+ t.is(
+ minify(newHtml, { collapseWhitespace: true }),
+ minify(expectedHtml, { collapseWhitespace: true }),
+ );
+
+ t.end();
+ });
+ });
+});