Skip to content

Commit

Permalink
Test partial support as well
Browse files Browse the repository at this point in the history
  • Loading branch information
ismay committed Feb 1, 2018
1 parent cb69f89 commit e62f917
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 108 deletions.
194 changes: 94 additions & 100 deletions lib/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,125 +1,119 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`stylelint-no-unsupported-browser-features ignore option should ignore a single property 1`] = `
Array [
Object {
"deprecations": Array [],
"invalidOptionWarnings": Array [],
"parseErrors": Array [],
"source": "<input css 5>",
"warnings": Array [],
},
]
Object {
"deprecations": Array [],
"invalidOptionWarnings": Array [],
"parseErrors": Array [],
"warnings": Array [],
}
`;

exports[`stylelint-no-unsupported-browser-features ignore option should ignore multiple properties 1`] = `
Array [
Object {
"deprecations": Array [],
"invalidOptionWarnings": Array [],
"parseErrors": Array [],
"source": "<input css 6>",
"warnings": Array [],
},
]
Object {
"deprecations": Array [],
"invalidOptionWarnings": Array [],
"parseErrors": Array [],
"warnings": Array [],
}
`;

exports[`stylelint-no-unsupported-browser-features multiple browsers should allow display:table for IE 8 and IE 9 1`] = `
Array [
Object {
"deprecations": Array [],
"invalidOptionWarnings": Array [],
"parseErrors": Array [],
"source": "<input css 3>",
"warnings": Array [],
},
]
Object {
"deprecations": Array [],
"invalidOptionWarnings": Array [],
"parseErrors": Array [],
"warnings": Array [],
}
`;

exports[`stylelint-no-unsupported-browser-features multiple browsers should disallow display:table for IE 6 and IE 7 1`] = `
Array [
Object {
"deprecations": Array [],
"errored": true,
"invalidOptionWarnings": Array [],
"parseErrors": Array [],
"source": "<input css 4>",
"warnings": Array [
Object {
"column": 7,
"line": 1,
"rule": "plugin/no-unsupported-browser-features",
"severity": "error",
"text": "Unexpected browser feature \\"css-table\\" is not supported by IE 6,7 (plugin/no-unsupported-browser-features)",
},
],
},
]
Object {
"deprecations": Array [],
"errored": true,
"invalidOptionWarnings": Array [],
"parseErrors": Array [],
"warnings": Array [
Object {
"column": 7,
"line": 1,
"rule": "plugin/no-unsupported-browser-features",
"severity": "error",
"text": "Unexpected browser feature \\"css-table\\" is not supported by IE 6,7 (plugin/no-unsupported-browser-features)",
},
],
}
`;

exports[`stylelint-no-unsupported-browser-features single browser should allow display:table for IE 8 1`] = `
Array [
Object {
"deprecations": Array [],
"invalidOptionWarnings": Array [],
"parseErrors": Array [],
"source": "<input css 1>",
"warnings": Array [],
},
]
Object {
"deprecations": Array [],
"invalidOptionWarnings": Array [],
"parseErrors": Array [],
"warnings": Array [],
}
`;

exports[`stylelint-no-unsupported-browser-features single browser should disallow display:table for IE 6 1`] = `
Array [
Object {
"deprecations": Array [],
"errored": true,
"invalidOptionWarnings": Array [],
"parseErrors": Array [],
"source": "<input css 2>",
"warnings": Array [
Object {
"column": 7,
"line": 1,
"rule": "plugin/no-unsupported-browser-features",
"severity": "error",
"text": "Unexpected browser feature \\"css-table\\" is not supported by IE 6 (plugin/no-unsupported-browser-features)",
},
],
},
]
Object {
"deprecations": Array [],
"errored": true,
"invalidOptionWarnings": Array [],
"parseErrors": Array [],
"warnings": Array [
Object {
"column": 7,
"line": 1,
"rule": "plugin/no-unsupported-browser-features",
"severity": "error",
"text": "Unexpected browser feature \\"css-table\\" is not supported by IE 6 (plugin/no-unsupported-browser-features)",
},
],
}
`;

exports[`stylelint-no-unsupported-browser-features single browser should disallow rems for IE 9 1`] = `
Object {
"deprecations": Array [],
"errored": true,
"invalidOptionWarnings": Array [],
"parseErrors": Array [],
"warnings": Array [
Object {
"column": 7,
"line": 1,
"rule": "plugin/no-unsupported-browser-features",
"severity": "error",
"text": "Unexpected browser feature \\"rem\\" is only partially supported by IE 9 (plugin/no-unsupported-browser-features)",
},
],
}
`;

exports[`stylelint-no-unsupported-browser-features validate options should validate the browsers option 1`] = `
Array [
Object {
"deprecations": Array [],
"errored": true,
"invalidOptionWarnings": Array [
Object {
"text": "Invalid value \\"1\\" for option \\"browsers\\" of rule \\"plugin/no-unsupported-browser-features\\"",
},
],
"parseErrors": Array [],
"source": "<input css 7>",
"warnings": Array [],
},
]
Object {
"deprecations": Array [],
"errored": true,
"invalidOptionWarnings": Array [
Object {
"text": "Invalid value \\"1\\" for option \\"browsers\\" of rule \\"plugin/no-unsupported-browser-features\\"",
},
],
"parseErrors": Array [],
"warnings": Array [],
}
`;

exports[`stylelint-no-unsupported-browser-features validate options should validate the ignore option 1`] = `
Array [
Object {
"deprecations": Array [],
"errored": true,
"invalidOptionWarnings": Array [
Object {
"text": "Invalid value \\"1\\" for option \\"ignore\\" of rule \\"plugin/no-unsupported-browser-features\\"",
},
],
"parseErrors": Array [],
"source": "<input css 8>",
"warnings": Array [],
},
]
Object {
"deprecations": Array [],
"errored": true,
"invalidOptionWarnings": Array [
Object {
"text": "Invalid value \\"1\\" for option \\"ignore\\" of rule \\"plugin/no-unsupported-browser-features\\"",
},
],
"parseErrors": Array [],
"warnings": Array [],
}
`;
51 changes: 43 additions & 8 deletions lib/index.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-env jest */

var stylelint = require('stylelint');
var deleteKeys = require('key-del');

function getOptions(code, rules) {
return {
Expand All @@ -13,6 +14,16 @@ function getOptions(code, rules) {
};
}

function parseResult(result) {
var parsedResult = JSON.parse(result);

if (parsedResult.length > 1) {
throw Error('More than one result received');
}

return deleteKeys(parsedResult[0], ['source']);
}

describe('stylelint-no-unsupported-browser-features', function() {
describe('single browser', function() {
it('should allow display:table for IE 8', function(done) {
Expand All @@ -31,7 +42,31 @@ describe('stylelint-no-unsupported-browser-features', function() {
.lint(options)
.then(function(result) {
expect(result.errored).toBe(false);
expect(JSON.parse(result.output)).toMatchSnapshot();
expect(parseResult(result.output)).toMatchSnapshot();
return done();
})
.catch(function(error) {
return done(error);
});
});

it('should disallow rems for IE 9', function(done) {
var code = 'div { width: 10rem; }';
var rules = {
'plugin/no-unsupported-browser-features': [
true,
{
browsers: ['IE 9']
}
]
};
var options = getOptions(code, rules);

return stylelint
.lint(options)
.then(function(result) {
expect(result.errored).toBe(true);
expect(parseResult(result.output)).toMatchSnapshot();
return done();
})
.catch(function(error) {
Expand All @@ -55,7 +90,7 @@ describe('stylelint-no-unsupported-browser-features', function() {
.lint(options)
.then(function(result) {
expect(result.errored).toBe(true);
expect(JSON.parse(result.output)).toMatchSnapshot();
expect(parseResult(result.output)).toMatchSnapshot();
return done();
})
.catch(function(error) {
Expand All @@ -81,7 +116,7 @@ describe('stylelint-no-unsupported-browser-features', function() {
.lint(options)
.then(function(result) {
expect(result.errored).toBe(false);
expect(JSON.parse(result.output)).toMatchSnapshot();
expect(parseResult(result.output)).toMatchSnapshot();
return done();
})
.catch(function(error) {
Expand All @@ -105,7 +140,7 @@ describe('stylelint-no-unsupported-browser-features', function() {
.lint(options)
.then(function(result) {
expect(result.errored).toBe(true);
expect(JSON.parse(result.output)).toMatchSnapshot();
expect(parseResult(result.output)).toMatchSnapshot();
return done();
})
.catch(function(error) {
Expand All @@ -132,7 +167,7 @@ describe('stylelint-no-unsupported-browser-features', function() {
.lint(options)
.then(function(result) {
expect(result.errored).toBe(false);
expect(JSON.parse(result.output)).toMatchSnapshot();
expect(parseResult(result.output)).toMatchSnapshot();
return done();
})
.catch(function(error) {
Expand All @@ -157,7 +192,7 @@ describe('stylelint-no-unsupported-browser-features', function() {
.lint(options)
.then(function(result) {
expect(result.errored).toBe(false);
expect(JSON.parse(result.output)).toMatchSnapshot();
expect(parseResult(result.output)).toMatchSnapshot();
return done();
})
.catch(function(error) {
Expand All @@ -183,7 +218,7 @@ describe('stylelint-no-unsupported-browser-features', function() {
.lint(options)
.then(function(result) {
expect(result.errored).toBe(true);
expect(JSON.parse(result.output)).toMatchSnapshot();
expect(parseResult(result.output)).toMatchSnapshot();
return done();
})
.catch(function(error) {
Expand All @@ -207,7 +242,7 @@ describe('stylelint-no-unsupported-browser-features', function() {
.lint(options)
.then(function(result) {
expect(result.errored).toBe(true);
expect(JSON.parse(result.output)).toMatchSnapshot();
expect(parseResult(result.output)).toMatchSnapshot();
return done();
})
.catch(function(error) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"eslint-plugin-import": "^2.7.0",
"husky": "^0.14.3",
"jest": "^22.1.4",
"key-del": "^1.3.0",
"lint-staged": "^6.1.0",
"prettier": "^1.10.2",
"stylelint": "^8.4.0"
Expand Down

0 comments on commit e62f917

Please sign in to comment.