Skip to content

Commit aa5dee0

Browse files
authored
Refactor: tests to ts (#61)
* Refactor: reset to ts * Refactor: generateMapping to ts * Refactor: all tests to ts * Chore: update eslint paths * Fix: correct typings for glob
1 parent 07e3461 commit aa5dee0

29 files changed

+590
-663
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__tests__/files

__tests__/generateMapping.js renamed to __tests__/generateMapping.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@ import rcs from '../lib';
1010
let testCwd;
1111
const fixturesCwd = path.join(process.cwd(), '/__tests__/files/fixtures');
1212

13-
beforeEach((done) => {
13+
beforeEach(async () => {
1414
testCwd = tmp.dirSync();
1515

1616
reset();
1717

18-
rcs.process.css('**/style*.css', {
18+
await rcs.process.css('**/style*.css', {
1919
newPath: testCwd.name,
2020
cwd: fixturesCwd,
21-
}, () => {
22-
done();
2321
});
2422
});
2523

__tests__/generateMappingSync.js renamed to __tests__/generateMappingSync.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@ import rcs from '../lib';
1010
let testCwd;
1111
const fixturesCwd = path.join(process.cwd(), '/__tests__/files/fixtures');
1212

13-
beforeEach((done) => {
13+
beforeEach(async () => {
1414
testCwd = tmp.dirSync();
1515

1616
reset();
1717

18-
rcs.process.css('**/style*.css', {
18+
await rcs.process.css('**/style*.css', {
1919
newPath: testCwd.name,
2020
cwd: fixturesCwd,
21-
}, () => {
22-
done();
2321
});
2422
});
2523

__tests__/helpers/reset.js renamed to __tests__/helpers/reset.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import rcsCore from 'rcs-core';
22

3-
const reset = () => {
3+
const reset = (): void => {
44
rcsCore.keyframesLibrary.setAlphabet('#abcdefghijklmnopqrstuvwxyz');
55
rcsCore.cssVariablesLibrary.setAlphabet('#abcdefghijklmnopqrstuvwxyz');
66
rcsCore.selectorsLibrary.setAlphabet('#abcdefghijklmnopqrstuvwxyz');
File renamed without changes.

__tests__/integration.js

-107
This file was deleted.

__tests__/integration.ts

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import tmp from 'tmp';
2+
import path from 'path';
3+
import fs from 'fs-extra';
4+
import { minify } from 'html-minifier';
5+
6+
import rcs from '../lib';
7+
import reset from './helpers/reset';
8+
9+
let testCwd;
10+
const testFiles = '__tests__/files';
11+
const fixturesCwd = path.join(testFiles, 'fixtures');
12+
13+
beforeEach(() => {
14+
testCwd = tmp.dirSync();
15+
16+
reset();
17+
});
18+
19+
afterEach(() => {
20+
testCwd.removeCallback();
21+
});
22+
23+
test('issue #19 | detect one file as array', async () => {
24+
await rcs.process.css('**/style.css', {
25+
newPath: testCwd.name,
26+
cwd: fixturesCwd,
27+
});
28+
29+
await rcs.process.html(['html/index.html'], {
30+
newPath: testCwd.name,
31+
cwd: fixturesCwd,
32+
});
33+
34+
expect(fs.existsSync(path.join(testCwd.name, '/html/index.html'))).toBe(true);
35+
expect(fs.existsSync(path.join(testCwd.name, '/css/style.css'))).toBe(true);
36+
expect(fs.existsSync(path.join(testCwd.name, '/css/subdirectory/style.css'))).toBe(true);
37+
});
38+
39+
test('issue #19 | detect one file', async () => {
40+
await rcs.process.css('**/style.css', {
41+
newPath: testCwd.name,
42+
cwd: fixturesCwd,
43+
});
44+
45+
await rcs.process.html('html/index.html', {
46+
newPath: testCwd.name,
47+
cwd: fixturesCwd,
48+
});
49+
50+
expect(fs.existsSync(path.join(testCwd.name, '/html/index.html'))).toBe(true);
51+
expect(fs.existsSync(path.join(testCwd.name, '/css/style.css'))).toBe(true);
52+
expect(fs.existsSync(path.join(testCwd.name, '/css/subdirectory/style.css'))).toBe(true);
53+
});
54+
55+
test('issue #21 | with auto', async () => {
56+
const issueFixture = path.join(testFiles, 'issue21/fixtures');
57+
const issueResults = path.join(testFiles, 'issue21/results');
58+
59+
await rcs.process.auto(['style.css', 'index.html'], {
60+
newPath: testCwd.name,
61+
cwd: issueFixture,
62+
});
63+
64+
const newCss = fs.readFileSync(path.join(testCwd.name, '/style.css'), 'utf8');
65+
const newHtml = fs.readFileSync(path.join(testCwd.name, '/index.html'), 'utf8');
66+
const expectedCss = fs.readFileSync(path.join(issueResults, '/style.css'), 'utf8');
67+
const expectedHtml = fs.readFileSync(path.join(issueResults, '/index.html'), 'utf8');
68+
69+
expect(newCss).toBe(expectedCss);
70+
expect(minify(newHtml, { collapseWhitespace: true }))
71+
.toBe(minify(expectedHtml, { collapseWhitespace: true }));
72+
});
73+
74+
test('issue #21 | with seperated process functions', async () => {
75+
const issueFixture = path.join(testFiles, 'issue21/fixtures');
76+
const issueResults = path.join(testFiles, 'issue21/results');
77+
78+
await rcs.process.css('style.css', {
79+
newPath: testCwd.name,
80+
cwd: issueFixture,
81+
});
82+
83+
await rcs.process.html('index.html', {
84+
newPath: testCwd.name,
85+
cwd: issueFixture,
86+
});
87+
88+
const newCss = fs.readFileSync(path.join(testCwd.name, '/style.css'), 'utf8');
89+
const newHtml = fs.readFileSync(path.join(testCwd.name, '/index.html'), 'utf8');
90+
const expectedCss = fs.readFileSync(path.join(issueResults, '/style.css'), 'utf8');
91+
const expectedHtml = fs.readFileSync(path.join(issueResults, '/index.html'), 'utf8');
92+
93+
expect(newCss).toBe(expectedCss);
94+
expect(minify(newHtml, { collapseWhitespace: true }))
95+
.toBe(minify(expectedHtml, { collapseWhitespace: true }));
96+
});

__tests__/integration_mapping.js

-116
This file was deleted.

0 commit comments

Comments
 (0)