Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new test cases to increase code coverage #31

Merged
merged 5 commits into from
Oct 2, 2020
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
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@
"contributions": [
"design"
]
},
{
"login": "ratnamal",
"name": "Ratnamala Korlepara",
"avatar_url": "https://avatars0.githubusercontent.com/u/36140652?v=4",
"profile": "https://github.com/ratnamal",
"contributions": [
"test"
]
}
],
"contributorsPerLine": 7
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</br>
PostCSS plugin for adding multiple themes to CSS files.
</p>
<div>
<div>
<a href="https://circleci.com/gh/intuit/postcss-themed"><img src="https://circleci.com/gh/intuit/postcss-themed.svg?style=svg"></a>
<a href="https://www.npmjs.com/package/postcss-themed"><img src="https://img.shields.io/npm/v/postcss-themed.svg?style=flat-square&logo=npm" alt="npm" /></a>
<a href="https://github.com/prettier/prettier"><img src="https://img.shields.io/badge/styled_with-prettier-ff69b4.svg" alt="styled with prettier" /></a>
Expand Down Expand Up @@ -390,6 +390,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center"><a href="https://christyjacob4.github.io"><img src="https://avatars1.githubusercontent.com/u/20852629?v=4" width="100px;" alt="Christy Jacob"/><br /><sub><b>Christy Jacob</b></sub></a><br /><a href="https://github.com/intuit/postcss-themed/commits?author=christyjacob4" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/Sharps"><img src="https://avatars2.githubusercontent.com/u/8174841?v=4" width="100px;" alt="Sharps"/><br /><sub><b>Sharps</b></sub></a><br /><a href="#design-Sharps" title="Design">🎨</a></td>
<td align="center"><a href="https://www.behance.net/amandayoshiizumi"><img src="https://avatars0.githubusercontent.com/u/30158643?v=4" width="100px;" alt="Amanda Yoshiizumi"/><br /><sub><b>Amanda Yoshiizumi</b></sub></a><br /><a href="#design-mandyellow" title="Design">🎨</a></td>
<td align="center"><a href="https://github.com/ratnamal"><img src="https://avatars0.githubusercontent.com/u/36140652?v=4" width="100px;" alt="Ratnamala Korlepara"/><br /><sub><b>Ratnamala Korlepara</b></sub></a><br /><a href="https://github.com/intuit/postcss-themed/commits?author=ratnamal" title="Tests">⚠️</a></td>
</tr>
</table>

Expand Down
52 changes: 39 additions & 13 deletions __tests__/legacy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ it('multiple themes + theme-root', () => {
.light.expanded {
width: 10px;
}
.dark.expanded {
.dark.expanded {
width: 100px;
}
`,
Expand Down Expand Up @@ -517,7 +517,7 @@ it('multiple themes + fallback', () => {
.light.expanded {
border: 1px solid white;
}
.dark.expanded {
.dark.expanded {
border: 1px solid black;
}
`,
Expand Down Expand Up @@ -641,7 +641,7 @@ it('multiple selectors - theme root', () => {
background: @theme color;
width: @theme width;
}
}
}
`,
`
.item {
Expand Down Expand Up @@ -689,7 +689,7 @@ it('dark themes', () => {
`
.item {
color: @theme color;
}
}
`,
`
.item {
Expand Down Expand Up @@ -732,7 +732,7 @@ it('overrides themes to single theme', () => {
}
`;

return postcss([plugin({ config, defaultTheme: 'quickBooks', forceSingleTheme: true })])
return postcss([plugin({ config, defaultTheme: 'quickBooks', forceSingleTheme: 'true' })])
.process(input, { from: undefined })
.catch(e => {
expect(e.message).toContain(
Expand Down Expand Up @@ -773,7 +773,7 @@ it('when theme = light , forceSingleTheme = true, single selector is generated',
{
config,
defaultTheme: 'light',
forceSingleTheme: true,
forceSingleTheme: 'true',
}
);
});
Expand Down Expand Up @@ -806,19 +806,45 @@ it('when theme = light , forceSingleTheme = false, multiple selectors are genera
width: 10px;
color: white;
}
.default .expanded,.default .foo {
width: 1px;
`,
{
config,
defaultTheme: 'light',
forceSingleTheme: 'false',
}
);
});

it('Adding empty selectors to final output. Part of legacy code', () => {
const config = {
default: {
color: 'purple'
},
light: {
color: 'white'
}
};

return run(
`
.test {
color: @theme color;
}
`,
`
.test {
color: purple;
}
.dark .expanded,.dark .foo {
width: 20px;
color: black;
.light .test {
color: white;
}
.default {}
.light {}
.dark {}
`,
{
config,
defaultTheme: 'light',
forceSingleTheme: false,
forceEmptyThemeSelectors: true
}
);
});
29 changes: 29 additions & 0 deletions __tests__/modern.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,32 @@ it('scoped variable names with custom function', () => {
}
);
});

it('Wrong key mentioned in theme configuration', () => {
const config = {
default: {
color: 'purple'
},
light: {
color: 'white'
}
};

return run(
`
.test {
background-color: @theme background-color;
}
`,
`
.test {
}
`,
{
config,
forceSingleTheme: 'mint',
optimizeSingleTheme: true
}
);
});