Skip to content

Commit

Permalink
Merge pull request #32 from curbengh/async
Browse files Browse the repository at this point in the history
refactor: async/await
  • Loading branch information
curbengh committed Sep 28, 2019
2 parents eedc754 + 8ef3b3b commit ed0dc29
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 21 deletions.
7 changes: 5 additions & 2 deletions .eslintrc
@@ -1,4 +1,7 @@
{
"extends": "hexo",
"root": true
}
"root": true,
"parserOptions": {
"ecmaVersion": 2017
}
}
5 changes: 2 additions & 3 deletions lib/filter.js
Expand Up @@ -4,7 +4,7 @@ var autoprefixer = require('autoprefixer');
var minimatch = require('minimatch');
var postcss = require('postcss');

module.exports = function(str, data) {
module.exports = async function(str, data) {
var options = this.config.autoprefixer;
var path = data.path;
var exclude = options.exclude;
Expand All @@ -16,7 +16,6 @@ module.exports = function(str, data) {
}
}

var result = postcss([autoprefixer(options)]).process(str, {from: path});

const result = await postcss([autoprefixer(options)]).process(str, {from: path});
return result.css;
};
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -37,6 +37,7 @@
},
"devDependencies": {
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"eslint": "^6.1.0",
"eslint-config-hexo": "^3.0.0",
"mocha": "^6.0.2",
Expand Down
22 changes: 6 additions & 16 deletions test/index.js
@@ -1,17 +1,10 @@
'use strict';

var should = require('chai').should(); // eslint-disable-line
require('chai').use(require('chai-as-promised')).should();
var prefixer = require('../lib/filter');

var nonStandards = ['-webkit-', '-moz-'];

function makeCSS(prefix) {
var isNS = nonStandards.indexOf(prefix) !== -1;

return ':%s%d div { color: white; }'
.replace('%s', prefix || '')
.replace('%d', isNS ? 'full-screen' : 'fullscreen');
}
const unprefixed = 'div { user-select: none; }';
const prefixed = 'div { -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; }';

describe('hexo-autoprefixer', function() {
it('should prefix fullscreen with no excludes', function() {
Expand All @@ -22,12 +15,11 @@ describe('hexo-autoprefixer', function() {
}
}
};
var unprefixed = makeCSS();
var newCSS = prefixer.call(ctx, unprefixed, {
path: '/usr/foo/bar/baz.css'
});

['-webkit-', '-moz-', '-ms-'].map(makeCSS).concat(unprefixed).join('\n').should.eql(newCSS);
newCSS.should.become(prefixed);
});

it('should prefix fullscreen with string exclude', function() {
Expand All @@ -38,12 +30,11 @@ describe('hexo-autoprefixer', function() {
}
}
};
var unprefixed = makeCSS();
var newCSS = prefixer.call(ctx, unprefixed, {
path: '/usr/foo/bar/baz.css'
});

['-webkit-', '-moz-', '-ms-'].map(makeCSS).concat(unprefixed).join('\n').should.eql(newCSS);
newCSS.should.become(prefixed);
});

it('should not prefix fullscreen with exclude match', function() {
Expand All @@ -54,11 +45,10 @@ describe('hexo-autoprefixer', function() {
}
}
};
var unprefixed = makeCSS();
var newCSS = prefixer.call(ctx, unprefixed, {
path: '/usr/baz.styl'
});

unprefixed.should.eql(newCSS);
newCSS.should.become(unprefixed);
});
});

0 comments on commit ed0dc29

Please sign in to comment.