Skip to content
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

refactor: async/await #32

Merged
merged 5 commits into from
Sep 28, 2019
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
7 changes: 5 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"extends": "hexo",
"root": true
}
"root": true,
"parserOptions": {
"ecmaVersion": 2017
}
}
5 changes: 2 additions & 3 deletions lib/filter.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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);
});
});