Skip to content

Commit

Permalink
add test case for exclude opt
Browse files Browse the repository at this point in the history
  • Loading branch information
JackyTianer committed Nov 19, 2018
1 parent 0579625 commit ebef846
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default postcss.plugin('postcss-plugin-px2rem', options => {
css.walkDecls((decl, i) => {
const _decl = decl;
// 1st check exclude
if (opts.exclude && css.source.input.file.match(opts.exclude) !== null) return;
if (opts.exclude && css.source.input.file && css.source.input.file.match(opts.exclude) !== null) return;
// 2st check 'px'
if (_decl.value.indexOf('px') === -1) return;
// 3nd check property black list
Expand Down
26 changes: 25 additions & 1 deletion test/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ describe('minPixelValue', () => {
});
});

describe('rpx support', function() {
describe('rpx support', function () {
it('should work on the readme example', () => {
const input = 'h1 { margin: 0 0 20rpx 20rpx; font-size: 32px; line-height: 1.2; letter-spacing: 1rpx; }';
const output = 'h1 { margin: 0 0 0.2rem 0.2rem; font-size: 0.64rem; line-height: 1.2; letter-spacing: 0.01rem; }';
Expand Down Expand Up @@ -262,3 +262,27 @@ describe('rpx support', function() {
expect(processed).toBe(output);
});
});

describe('exclude support', () => {
it('should work on the readme example', () => {
const input = 'h1 { margin: 0 0 20px 20px; font-size: 32px; line-height: 1.2; letter-spacing: 1px; }';
const output = 'h1 { margin: 0 0 20px 20px; font-size: 32px; line-height: 1.2; letter-spacing: 1px; }';
const processed = postcss(pxtorem({
exclude: /(node_modules)/,
})).process(input, {
from: 'node_modules/third.css',
}).css;
expect(processed).toBe(output);
});

it('should work when exclude option range doesn\'t cover', () => {
const input = 'h1 { margin: 0 0 20px 20px; font-size: 32px; line-height: 1.2; letter-spacing: 1px; }';
const output = 'h1 { margin: 0 0 0.2rem 0.2rem; font-size: 0.32rem; line-height: 1.2; letter-spacing: 0.01rem; }';
const processed = postcss(pxtorem({
exclude: /(node_modules)/,
})).process(input, {
from: 'lib/own.css',
}).css;
expect(processed).toBe(output);
});
});

0 comments on commit ebef846

Please sign in to comment.