Skip to content

Commit

Permalink
initial work on testS
Browse files Browse the repository at this point in the history
  • Loading branch information
jgallen23 committed Dec 28, 2017
1 parent ce55db9 commit e036cc1
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
.nyc_output/
test/out
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
language: node_js
node_js:
- "8"
- "6"
18 changes: 10 additions & 8 deletions css.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,17 @@ class CSSTask extends TaskKitTask {

// load mixins:
let globalMixins;
try {
globalMixins = require('require-all')({
dirname: path.join(config.globalMixins),
resolve: m => m(config, postcss)
});
} catch (e) {
this.log(e);
if (config.globalMixins) {
try {
globalMixins = require('require-all')({
dirname: path.join(config.globalMixins),
resolve: m => m(config, postcss)
});
} catch (e) {
this.log(e);
}
}
if (pathExists.sync(path.join(config.assetPath, 'mixins'))) {
if (config.assetPath && pathExists.sync(path.join(config.assetPath, 'mixins'))) {
const localMixins = require('require-all')({
dirname: path.join(config.assetPath, 'mixins'),
resolve: m => m(config, postcss)
Expand Down
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"version": "1.0.1",
"description": "Clientkit task that executes a PostCSS process on your .css files",
"main": "css.js",
"scripts": {
"test": "tap --cov test/*.test.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/firstandthird/clientkit-css.git"
Expand All @@ -14,9 +17,10 @@
},
"homepage": "https://github.com/firstandthird/clientkit-css#readme",
"devDependencies": {
"eslint": "^3.9.1",
"eslint-config-firstandthird": "^3.0.2",
"eslint-plugin-import": "^2.1.0"
"eslint": "^4.14.0",
"eslint-config-firstandthird": "^4.3.0",
"eslint-plugin-import": "^2.8.0",
"tap": "^11.0.1"
},
"dependencies": {
"async": "^2.1.4",
Expand Down
31 changes: 31 additions & 0 deletions test/colors.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const tap = require('tap');
const ClientKitCss = require('../');
const utils = require('./utils');

tap.test('color vars', (t) => {
const css = new ClientKitCss('css', {
color: {
test: '#336699'
}
});
t.deepEqual(css.cssVars, {
'color-test': '#336699'
});
t.end();
});

tap.test('color vars in css', (t) => {
const css = new ClientKitCss('css', {
files: {
'test/out/colors.css': 'test/fixtures/colors.css'
},
color: {
test: '#336699'
}
});
css.execute((err, results) => {
t.equal(err, null);
utils.checkOutput(t, 'colors.css');
t.end();
});
});
5 changes: 5 additions & 0 deletions test/expected/colors.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/fixtures/colors.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
background: var(--color-test);
}
6 changes: 6 additions & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const fs = require('fs');
exports.checkOutput = (t, file) => {
const out = fs.readFileSync(`${__dirname}/out/${file}`, 'utf8');
const expected = fs.readFileSync(`${__dirname}/expected/${file}`, 'utf8');
t.equal(out, expected);
};

0 comments on commit e036cc1

Please sign in to comment.