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 + } +} diff --git a/lib/filter.js b/lib/filter.js index f8e09d8..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,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; }; 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", 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); }); });