Repository: postcss/autoprefixer
Pull request #928 (2017-10-20 13:54:03)

Add code coverage, tests of initializing and remove not used code
Code coverage
===

Before:
--
> 97.12% Statements 2093/2155
> 92.69% Branches 1192/1286
> 97.45% Functions 382/392
> 97.23% Lines 2069/2128

After:
--
> 97.67% Statements 2099/2149
> 93.23% Branches 1199/1286
> 97.95% Functions 382/390
> 97.79% Lines 2075/2122

ai: I don’t like many changes in the code. We had bad story in Browserslist when coverage fixes broke release.

What do you think of not changing origin code and only add new tests?
Semigradsky: Ok, I will change PR. I will ping when it be done.
Semigradsky: @ai ping! :point_left: 
Semigradsky: Added `plugin.browsers`

Patch:
diff --git a/.gitignore b/.gitignore
index 2a5c483..cefa9ad 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@
 node_modules/
 
 build/
+coverage/
diff --git a/.npmignore b/.npmignore
index 6be5d99..af8d0d2 100644
--- a/.npmignore
+++ b/.npmignore
@@ -4,6 +4,7 @@
 node_modules
 yarn.lock
 build
+coverage
 autoprefixer.js
 
 test
diff --git a/lib/autoprefixer.js b/lib/autoprefixer.js
index 45518c4..35b034f 100644
--- a/lib/autoprefixer.js
+++ b/lib/autoprefixer.js
@@ -92,6 +92,8 @@ module.exports = postcss.plugin('autoprefixer', (...reqs) => {
 
     plugin.options = options;
 
+    plugin.browsers = reqs;
+
     plugin.info = function (opts) {
         opts = opts || {};
         opts.from = opts.from || process.cwd();
diff --git a/lib/browsers.js b/lib/browsers.js
index e3ec76a..e597a9e 100644
--- a/lib/browsers.js
+++ b/lib/browsers.js
@@ -55,21 +55,6 @@ class Browsers {
         });
     }
 
-    /**
-     * Select major browsers versions by criteria
-     */
-    browsers(criteria) {
-        let selected = [];
-        for (const browser in this.data) {
-            const data = this.data[browser];
-            const versions = criteria(data).map(
-                version => `${browser} ${version}`
-            );
-            selected = selected.concat(versions);
-        }
-        return selected;
-    }
-
     /**
      * Return prefix for selected browser
      */
diff --git a/package.json b/package.json
index 64133d5..881dd9e 100644
--- a/package.json
+++ b/package.json
@@ -45,7 +45,7 @@
   "scripts": {
     "lint-staged": "lint-staged",
     "lint": "eslint *.js lib/*.js data/*.js test/*.js",
-    "test": "jest && npm run lint && gulp && size-limit"
+    "test": "jest --coverage && npm run lint && gulp && size-limit"
   },
   "lint-staged": {
     "*.js": "eslint"
@@ -70,6 +70,13 @@
       "jest": true
     }
   },
+  "jest": {
+    "coverageThreshold": {
+      "global": {
+        "statements": 97
+      }
+    }
+  },
   "babel": {
     "presets": [
       [


Test patch:
diff --git a/test/autoprefixer.test.js b/test/autoprefixer.test.js
index 536400a..3ed1b32 100644
--- a/test/autoprefixer.test.js
+++ b/test/autoprefixer.test.js
@@ -145,9 +145,31 @@ it('throws on wrong options', () => {
     }).toThrowError(/browsers/);
 });
 
-it('sets options', () => {
-    const opts = { browsers: ['chrome 25', 'opera 12'], cascade: false };
-    expect(autoprefixer(opts).options).toEqual(opts);
+const options = {
+    cascade: false,
+    grid: false
+};
+
+const browsers = ['chrome 25', 'opera 12'];
+
+it('sets options via options object', () => {
+    const allOptions = Object.assign(options, { browsers });
+
+    const instance = autoprefixer(allOptions);
+    expect(instance.options).toEqual(allOptions);
+    expect(instance.browsers).toEqual(browsers);
+});
+
+it('sets options via array of browsers as first argument and object', () => {
+    const instance = autoprefixer(browsers, options);
+    expect(instance.options).toEqual(options);
+    expect(instance.browsers).toEqual(browsers);
+});
+
+it('sets options via browsers as arguments and options object', () => {
+    const instance = autoprefixer(...browsers, options);
+    expect(instance.options).toEqual(options);
+    expect(instance.browsers).toEqual(browsers);
 });
 
 it('has default browsers', () => {