From 9108dd71419c827f68de0595ee87d59891d86e74 Mon Sep 17 00:00:00 2001 From: curbengh <43627182+curbengh@users.noreply.github.com> Date: Mon, 26 Aug 2019 00:46:19 +0930 Subject: [PATCH 1/5] refactor: promise-fy --- lib/filter.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/filter.js b/lib/filter.js index f8e09d8..aa90d3a 100644 --- a/lib/filter.js +++ b/lib/filter.js @@ -16,7 +16,11 @@ module.exports = function(str, data) { } } - var result = postcss([autoprefixer(options)]).process(str, {from: path}); + const result = postcss([autoprefixer(options)]) + .process(str, {from: path}) + .then(output => { + return output.css; + }); - return result.css; + return result; }; From 21e5435bf878125e3171acd7972391792defc5a2 Mon Sep 17 00:00:00 2001 From: curbengh <43627182+curbengh@users.noreply.github.com> Date: Tue, 24 Sep 2019 17:59:01 +0100 Subject: [PATCH 2/5] refactor: async/await --- lib/filter.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/filter.js b/lib/filter.js index aa90d3a..572370e 100644 --- a/lib/filter.js +++ b/lib/filter.js @@ -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; @@ -16,11 +16,6 @@ module.exports = function(str, data) { } } - const result = postcss([autoprefixer(options)]) - .process(str, {from: path}) - .then(output => { - return output.css; - }); - - return result; + const result = await postcss([autoprefixer(options)]).process(str, {from: path}); + return result.css; }; From e912f1e1292f4d1d766dc20e8f46dc9f0d303f5e Mon Sep 17 00:00:00 2001 From: curbengh <43627182+curbengh@users.noreply.github.com> Date: Tue, 24 Sep 2019 18:00:01 +0100 Subject: [PATCH 3/5] chore(deps-dev): requires chai-as-promised --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index bf44ea8..843313d 100644 --- a/package.json +++ b/package.json @@ -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", From df12281f0b5646c41ac889fef21c8a1f7daa1ec2 Mon Sep 17 00:00:00 2001 From: curbengh <43627182+curbengh@users.noreply.github.com> Date: Tue, 24 Sep 2019 18:01:16 +0100 Subject: [PATCH 4/5] test(eslint): specify ecmaVersion 2017 to support async/await --- .eslintrc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.eslintrc b/.eslintrc index 91288aa..eab7721 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,4 +1,7 @@ { "extends": "hexo", - "root": true -} \ No newline at end of file + "root": true, + "parserOptions": { + "ecmaVersion": 2017 + } +} From 8ef3b3b6cf335f930d4bb6a6c0c4790ae9143097 Mon Sep 17 00:00:00 2001 From: curbengh <43627182+curbengh@users.noreply.github.com> Date: Tue, 24 Sep 2019 18:08:39 +0100 Subject: [PATCH 5/5] test: use chai-as-promised --- test/index.js | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/test/index.js b/test/index.js index 382d743..5078fb8 100644 --- a/test/index.js +++ b/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() { @@ -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() { @@ -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() { @@ -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); }); });