Skip to content

Refactor: tests to ts #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__tests__/files
6 changes: 2 additions & 4 deletions __tests__/generateMapping.js → __tests__/generateMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ import rcs from '../lib';
let testCwd;
const fixturesCwd = path.join(process.cwd(), '/__tests__/files/fixtures');

beforeEach((done) => {
beforeEach(async () => {
testCwd = tmp.dirSync();

reset();

rcs.process.css('**/style*.css', {
await rcs.process.css('**/style*.css', {
newPath: testCwd.name,
cwd: fixturesCwd,
}, () => {
done();
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ import rcs from '../lib';
let testCwd;
const fixturesCwd = path.join(process.cwd(), '/__tests__/files/fixtures');

beforeEach((done) => {
beforeEach(async () => {
testCwd = tmp.dirSync();

reset();

rcs.process.css('**/style*.css', {
await rcs.process.css('**/style*.css', {
newPath: testCwd.name,
cwd: fixturesCwd,
}, () => {
done();
});
});

Expand Down
2 changes: 1 addition & 1 deletion __tests__/helpers/reset.js → __tests__/helpers/reset.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import rcsCore from 'rcs-core';

const reset = () => {
const reset = (): void => {
rcsCore.keyframesLibrary.setAlphabet('#abcdefghijklmnopqrstuvwxyz');
rcsCore.cssVariablesLibrary.setAlphabet('#abcdefghijklmnopqrstuvwxyz');
rcsCore.selectorsLibrary.setAlphabet('#abcdefghijklmnopqrstuvwxyz');
Expand Down
File renamed without changes.
107 changes: 0 additions & 107 deletions __tests__/integration.js

This file was deleted.

96 changes: 96 additions & 0 deletions __tests__/integration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import tmp from 'tmp';
import path from 'path';
import fs from 'fs-extra';
import { minify } from 'html-minifier';

import rcs from '../lib';
import reset from './helpers/reset';

let testCwd;
const testFiles = '__tests__/files';
const fixturesCwd = path.join(testFiles, 'fixtures');

beforeEach(() => {
testCwd = tmp.dirSync();

reset();
});

afterEach(() => {
testCwd.removeCallback();
});

test('issue #19 | detect one file as array', async () => {
await rcs.process.css('**/style.css', {
newPath: testCwd.name,
cwd: fixturesCwd,
});

await rcs.process.html(['html/index.html'], {
newPath: testCwd.name,
cwd: fixturesCwd,
});

expect(fs.existsSync(path.join(testCwd.name, '/html/index.html'))).toBe(true);
expect(fs.existsSync(path.join(testCwd.name, '/css/style.css'))).toBe(true);
expect(fs.existsSync(path.join(testCwd.name, '/css/subdirectory/style.css'))).toBe(true);
});

test('issue #19 | detect one file', async () => {
await rcs.process.css('**/style.css', {
newPath: testCwd.name,
cwd: fixturesCwd,
});

await rcs.process.html('html/index.html', {
newPath: testCwd.name,
cwd: fixturesCwd,
});

expect(fs.existsSync(path.join(testCwd.name, '/html/index.html'))).toBe(true);
expect(fs.existsSync(path.join(testCwd.name, '/css/style.css'))).toBe(true);
expect(fs.existsSync(path.join(testCwd.name, '/css/subdirectory/style.css'))).toBe(true);
});

test('issue #21 | with auto', async () => {
const issueFixture = path.join(testFiles, 'issue21/fixtures');
const issueResults = path.join(testFiles, 'issue21/results');

await rcs.process.auto(['style.css', 'index.html'], {
newPath: testCwd.name,
cwd: issueFixture,
});

const newCss = fs.readFileSync(path.join(testCwd.name, '/style.css'), 'utf8');
const newHtml = fs.readFileSync(path.join(testCwd.name, '/index.html'), 'utf8');
const expectedCss = fs.readFileSync(path.join(issueResults, '/style.css'), 'utf8');
const expectedHtml = fs.readFileSync(path.join(issueResults, '/index.html'), 'utf8');

expect(newCss).toBe(expectedCss);
expect(minify(newHtml, { collapseWhitespace: true }))
.toBe(minify(expectedHtml, { collapseWhitespace: true }));
});

test('issue #21 | with seperated process functions', async () => {
const issueFixture = path.join(testFiles, 'issue21/fixtures');
const issueResults = path.join(testFiles, 'issue21/results');

await rcs.process.css('style.css', {
newPath: testCwd.name,
cwd: issueFixture,
});

await rcs.process.html('index.html', {
newPath: testCwd.name,
cwd: issueFixture,
});

const newCss = fs.readFileSync(path.join(testCwd.name, '/style.css'), 'utf8');
const newHtml = fs.readFileSync(path.join(testCwd.name, '/index.html'), 'utf8');
const expectedCss = fs.readFileSync(path.join(issueResults, '/style.css'), 'utf8');
const expectedHtml = fs.readFileSync(path.join(issueResults, '/index.html'), 'utf8');

expect(newCss).toBe(expectedCss);
expect(minify(newHtml, { collapseWhitespace: true }))
.toBe(minify(expectedHtml, { collapseWhitespace: true }));
});
116 changes: 0 additions & 116 deletions __tests__/integration_mapping.js

This file was deleted.

Loading