Skip to content

Commit

Permalink
Add tests for :global and :local shorthand selectors.
Browse files Browse the repository at this point in the history
  • Loading branch information
fxb authored and madyankin committed Feb 23, 2022
1 parent 3c8ba0c commit a400e14
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
38 changes: 38 additions & 0 deletions test/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,22 @@ p {
"
`;

exports[`only calls plugins once when it processes :global shorthand selector: plugins once - processes :global shorthand selector - CSS 1`] = `
"/* validator-2-start (globalShorthand.css) *//* validator-1-start (globalShorthand.css) */
.title {
color: red;
}/* validator-1-end (globalShorthand.css) *//* validator-2-end (globalShorthand.css) */
"
`;

exports[`only calls plugins once when it processes :local shorthand selector: plugins once - processes :local shorthand selector - CSS 1`] = `
"/* validator-2-start (localShorthand.css) *//* validator-1-start (localShorthand.css) */
._localShorthand_title {
color: red;
}/* validator-1-end (localShorthand.css) *//* validator-2-end (localShorthand.css) */
"
`;

exports[`only calls plugins once when it processes classes: plugins once - processes classes - CSS 1`] = `
"/* validator-2-start (classes.css) */
Expand Down Expand Up @@ -268,6 +284,28 @@ p {

exports[`preserves comments: preserves comments - JSON 1`] = `Object {}`;

exports[`processes :global shorthand selector: processes :global shorthand selector - CSS 1`] = `
".title {
color: red;
}
"
`;

exports[`processes :global shorthand selector: processes :global shorthand selector - JSON 1`] = `Object {}`;

exports[`processes :local shorthand selector: processes :local shorthand selector - CSS 1`] = `
"._localShorthand_title {
color: red;
}
"
`;

exports[`processes :local shorthand selector: processes :local shorthand selector - JSON 1`] = `
Object {
"title": "_localShorthand_title",
}
`;

exports[`processes classes: processes classes - CSS 1`] = `
".page {
padding: 20px;
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/in/globalShorthand.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:global .title {
color: red;
}
3 changes: 3 additions & 0 deletions test/fixtures/in/localShorthand.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:local .title {
color: red;
}
6 changes: 5 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const cases = {
values: "processes values",
interpolated: "generates scoped name with interpolated string",
global: "allows to make CSS global",
localShorthand: "processes :local shorthand selector",
globalShorthand: "processes :global shorthand selector",
};

function generateScopedName(name, filename) {
Expand All @@ -40,7 +42,9 @@ Object.keys(cases).forEach((name) => {
: generateScopedName;

const scopeBehaviour =
name === behaviours.GLOBAL ? behaviours.GLOBAL : behaviours.LOCAL;
name === behaviours.GLOBAL || name === "globalShorthand"
? behaviours.GLOBAL
: behaviours.LOCAL;

it(description, async () => {
const sourceFile = path.join(fixturesPath, "in", `${name}.css`);
Expand Down

0 comments on commit a400e14

Please sign in to comment.