Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
.vscode/
coverage/
src/
circle.yml
tsconfig.json
tslint.json
70 changes: 46 additions & 24 deletions src/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,69 +5,91 @@ const pseudoElements = require('pseudo-elements');

import * as plugin from './plugin';

test('unwraps a nested property', scenario(
test(
'unwraps a nested property',
macro,
'a{b:{c:d}}',
'a{b-c:d}'
));
);

test('unwraps a deeply nested property', scenario(
test(
'unwraps a deeply nested property',
macro,
'a{b:{c:{d:{e:{f:g}}}}}',
'a{b-c-d-e-f:g}'
));
);

test('unwraps two nested properties in the same rule', scenario(
test(
'unwraps two nested properties in the same rule',
macro,
'a{b:{c:{d:e}}f:{g:{h:i}}}',
'a{b-c-d:e;f-g-h:i}'
));
);

test('unwraps a property namespace paired with a value', scenario(
test(
'unwraps a property namespace paired with a value',
macro,
'a{b:c{d:e}}',
'a{b:c;b-d:e}'
));
);

test('preserves nested rules w/o a colon in the selector', scenario(
test(
'preserves nested rules w/o a colon in the selector',
macro,
'a{b{c{d:e}}}',
'a{b{c{d:e}}}'
));
);

test('preserves a rule with a :global pseudo-selector', scenario(
test(
'preserves a rule with a :global pseudo-selector',
macro,
`:global .a{b:c;d:e;}`,
`:global .a{b:c;d:e;}`
));
);

test('preserves a rule with a :local pseudo-selector', scenario(
test(
'preserves a rule with a :local pseudo-selector',
macro,
`:local .a{b:c;d:e;}`,
`:local .a{b:c;d:e;}`
));
);

pseudoClasses().forEach((pseudoClass: string) => {
test(`preserves the :${pseudoClass}() pseudo-class`, scenario(
test(
`preserves the :${pseudoClass}() pseudo-class`,
macro,
`a{b:${pseudoClass}(c){d:e}}`,
`a{b:${pseudoClass}(c){d:e}}`
));
);
});

pseudoElements().forEach((pseudoElement: string) => {
test(`preserves the ::${pseudoElement} pseudo-element`, scenario(
test(
`preserves the ::${pseudoElement} pseudo-element`,
macro,
`a{b::${pseudoElement}{c:d}}`,
`a{b::${pseudoElement}{c:d}}`
));
);
});

[
'-ms-clear',
'-webkit-progress-bar',
'-moz-focus-outer'
].forEach(vendorPseudoElement => {
test(`preserves the ::${vendorPseudoElement} pseudo-element`, scenario(
test(
`preserves the ::${vendorPseudoElement} pseudo-element`,
macro,
`a{b::${vendorPseudoElement}{c:d}}`,
`a{b::${vendorPseudoElement}{c:d}}`
));
);
});

function scenario(input: string, expectedOutput: string) {
function macro(
t: ContextualTestContext,
input: string,
expected?: string | RegExp
) {
const processor = postcss([plugin()]);
return (t: ContextualTestContext) => {
t.is(processor.process(input).css, expectedOutput);
};
t.is(processor.process(input).css, expected);
}