Skip to content

Commit

Permalink
fix: non-set tokens should have names
Browse files Browse the repository at this point in the history
  • Loading branch information
GarthDB committed Apr 19, 2022
1 parent 13d331d commit d8ca3c8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/css-sets-formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const valueFormatter = (token, dictionary) => {
const formatter = ({ dictionary, platform, file, options }) => {
const resultAr = [];
dictionary.allTokens.forEach((token) => {
let name = [];
let name = token.path;
if (isASet(options)) {
const setsIndex = token.path.indexOf("sets");
name = token.path.filter((element, index) => {
Expand Down
22 changes: 21 additions & 1 deletion tests/css-formatter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ beforeEach(() => {
});

afterEach(() => {
helpers.clearOutput();
// helpers.clearOutput();
});

test("basic data with sets keyword in path should provide basic css", () => {
Expand Down Expand Up @@ -84,3 +84,23 @@ test("should handle multi nested reference css", () => {
});
expect(result).toEqual(expected);
});

test("tokens without sets should still have names", () => {
const filename = "multi-ref";
const config = generateConfig(filename);
config.platforms.CSS.files[0].filter = (token) => {
return !("sets" in token.attributes);
};
const sd = StyleDictionary.extend(config);
sd.buildAllPlatforms();
const result = fs.readFileSync(
path.join(helpers.outputDir, `${filename}.css`),
{
encoding: "utf8",
}
);
const expected = fs.readFileSync(`./tests/expected/${filename}.css`, {
encoding: "utf8",
});
expect(result).toEqual(expected);
});
5 changes: 5 additions & 0 deletions tests/expected/multi-ref.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
:root {
--background-color: var(--color-gray-100);
--light-gray: #EEEEEE;
--dark-gray: #111111;
}

0 comments on commit d8ca3c8

Please sign in to comment.