Skip to content

Commit

Permalink
feat: add warnings disabled option, fix logging issues (#1136)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenbroekema authored Mar 26, 2024
1 parent 77ae35f commit 8b6fff3
Show file tree
Hide file tree
Showing 19 changed files with 259 additions and 106 deletions.
8 changes: 8 additions & 0 deletions .changeset/light-lions-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'style-dictionary': minor
---

Fixes some noisy warnings still being outputted even when verbosity is set to default.

We also added log.warning "disabled" option for turning off warnings altogether, meaning you only get success logs and fatal errors.
This option can be used from the CLI as well using the `--no-warn` flag.
2 changes: 1 addition & 1 deletion __integration__/__snapshots__/nameCollisions.test.snap.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ snapshots["integration name collisions should warn users of name collisions for
`⚠️ __integration__/build/variables.css
While building variables.css, token collisions were found; output may be unexpected. Ignore this warning if intentional.
Use --verbose or log.verbosity: 'verbose' option for more details`;
Use log.verbosity "verbose" or use CLI option --verbose for more details.`;
/* end snapshot integration name collisions should warn users of name collisions for flat files, brief version */

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ snapshots["integration output references should warn the user if filters out ref
While building filteredVariables.css, filtered out token references were found; output may be unexpected. Ignore this warning if intentional.
Here are the references that are used but not defined in the file:
Use --verbose or log.verbosity: 'verbose' option for more details`;
Use log.verbosity "verbose" or use CLI option --verbose for more details.`;
/* end snapshot integration output references should warn the user if filters out references briefly */

snapshots["integration output references should warn the user if filters out references with a detailed message when using verbose logging"] =
Expand Down
42 changes: 4 additions & 38 deletions __integration__/logging/__snapshots__/config.test.snap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,13 @@
export const snapshots = {};
snapshots["integration > logging > config > property value collisions should not throw, but notify users by default"] =
`
Property Value Collisions:
Collision detected at: size.padding.small! Original value: 0.5, New value: 0.5
Collision detected at: size.padding.small! Original value: dimension, New value: dimension
Collision detected at: size.padding.small! Original value: __integration__/tokens/size/padding.json, New value: __integration__/tokens/size/_padding.json
Collision detected at: size.padding.small! Original value: true, New value: true
Collision detected at: size.padding.medium! Original value: 1, New value: 1
Collision detected at: size.padding.medium! Original value: dimension, New value: dimension
Collision detected at: size.padding.medium! Original value: __integration__/tokens/size/padding.json, New value: __integration__/tokens/size/_padding.json
Collision detected at: size.padding.medium! Original value: true, New value: true
Collision detected at: size.padding.large! Original value: 1, New value: 1
Collision detected at: size.padding.large! Original value: dimension, New value: dimension
Collision detected at: size.padding.large! Original value: __integration__/tokens/size/padding.json, New value: __integration__/tokens/size/_padding.json
Collision detected at: size.padding.large! Original value: true, New value: true
Collision detected at: size.padding.xl! Original value: 1, New value: 1
Collision detected at: size.padding.xl! Original value: dimension, New value: dimension
Collision detected at: size.padding.xl! Original value: __integration__/tokens/size/padding.json, New value: __integration__/tokens/size/_padding.json
Collision detected at: size.padding.xl! Original value: true, New value: true
`;
Token collisions detected (16):
Use log.verbosity "verbose" or use CLI option --verbose for more details.`;
/* end snapshot integration > logging > config > property value collisions should not throw, but notify users by default */

snapshots["integration > logging > config > property value collisions should not show warnings if given higher log level"] =
`
Property Value Collisions:
Collision detected at: size.padding.small! Original value: 0.5, New value: 0.5
Collision detected at: size.padding.small! Original value: dimension, New value: dimension
Collision detected at: size.padding.small! Original value: __integration__/tokens/size/padding.json, New value: __integration__/tokens/size/_padding.json
Collision detected at: size.padding.small! Original value: true, New value: true
Collision detected at: size.padding.medium! Original value: 1, New value: 1
Collision detected at: size.padding.medium! Original value: dimension, New value: dimension
Collision detected at: size.padding.medium! Original value: __integration__/tokens/size/padding.json, New value: __integration__/tokens/size/_padding.json
Collision detected at: size.padding.medium! Original value: true, New value: true
Collision detected at: size.padding.large! Original value: 1, New value: 1
Collision detected at: size.padding.large! Original value: dimension, New value: dimension
Collision detected at: size.padding.large! Original value: __integration__/tokens/size/padding.json, New value: __integration__/tokens/size/_padding.json
Collision detected at: size.padding.large! Original value: true, New value: true
Collision detected at: size.padding.xl! Original value: 1, New value: 1
Collision detected at: size.padding.xl! Original value: dimension, New value: dimension
Collision detected at: size.padding.xl! Original value: __integration__/tokens/size/padding.json, New value: __integration__/tokens/size/_padding.json
Collision detected at: size.padding.xl! Original value: true, New value: true
`;
Token collisions detected (16):
Use log.verbosity "verbose" or use CLI option --verbose for more details.`;
/* end snapshot integration > logging > config > property value collisions should not show warnings if given higher log level */

12 changes: 6 additions & 6 deletions __integration__/logging/__snapshots__/file.test.snap.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ css
⚠️ __integration__/build/nameCollisions.css
While building nameCollisions.css, token collisions were found; output may be unexpected. Ignore this warning if intentional.
Use --verbose or log.verbosity: 'verbose' option for more details`;
Use log.verbosity "verbose" or use CLI option --verbose for more details.`;
/* end snapshot integration logging file name collisions should warn users briefly of name collisions by default */

snapshots["integration logging file name collisions should throw a brief error of name collisions with log level set to error"] =
`⚠️ __integration__/build/nameCollisions.css
While building nameCollisions.css, token collisions were found; output may be unexpected. Ignore this warning if intentional.
Use --verbose or log.verbosity: 'verbose' option for more details`;
Use log.verbosity "verbose" or use CLI option --verbose for more details.`;
/* end snapshot integration logging file name collisions should throw a brief error of name collisions with log level set to error */

snapshots["integration logging file name collisions should throw a brief error of name collisions with log level set to error on platform level"] =
`⚠️ __integration__/build/nameCollisions.css
While building nameCollisions.css, token collisions were found; output may be unexpected. Ignore this warning if intentional.
Use --verbose or log.verbosity: 'verbose' option for more details`;
Use log.verbosity "verbose" or use CLI option --verbose for more details.`;
/* end snapshot integration logging file name collisions should throw a brief error of name collisions with log level set to error on platform level */

snapshots["integration logging file name collisions should warn user of name collisions with a detailed message through \"verbose\" verbosity"] =
Expand Down Expand Up @@ -393,23 +393,23 @@ css
While building filteredReferences.css, filtered out token references were found; output may be unexpected. Ignore this warning if intentional.
Here are the references that are used but not defined in the file:
Use --verbose or log.verbosity: 'verbose' option for more details`;
Use log.verbosity "verbose" or use CLI option --verbose for more details.`;
/* end snapshot integration logging file filtered references should warn users briefly of filtered references by default */

snapshots["integration logging file filtered references should throw a brief error of filtered references with log level set to error"] =
`⚠️ __integration__/build/filteredReferences.css
While building filteredReferences.css, filtered out token references were found; output may be unexpected. Ignore this warning if intentional.
Here are the references that are used but not defined in the file:
Use --verbose or log.verbosity: 'verbose' option for more details`;
Use log.verbosity "verbose" or use CLI option --verbose for more details.`;
/* end snapshot integration logging file filtered references should throw a brief error of filtered references with log level set to error */

snapshots["integration logging file filtered references should throw a brief error of filtered references with log level set to error on platform level"] =
`⚠️ __integration__/build/filteredReferences.css
While building filteredReferences.css, filtered out token references were found; output may be unexpected. Ignore this warning if intentional.
Here are the references that are used but not defined in the file:
Use --verbose or log.verbosity: 'verbose' option for more details`;
Use log.verbosity "verbose" or use CLI option --verbose for more details.`;
/* end snapshot integration logging file filtered references should throw a brief error of filtered references with log level set to error on platform level */

snapshots["integration logging file filtered references should warn user of filtered references with a detailed message through \"verbose\" verbosity"] =
Expand Down
17 changes: 8 additions & 9 deletions __integration__/logging/__snapshots__/platform.test.snap.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,17 @@ Unknown transformGroup "foo" found in platform "css":
/* end snapshot integration logging platform should throw and notify users of unknown transformGroups */
snapshots["integration logging platform property reference errors should throw and notify users of unknown references"] =
`
Property Reference Errors:
color.danger.value tries to reference color.red.value, which is not defined.
Problems were found when trying to resolve property references`;
Reference Errors:
Some token references (1) could not be found.
Use log.verbosity "verbose" or use CLI option --verbose for more details.
`;
/* end snapshot integration logging platform property reference errors should throw and notify users of unknown references */

snapshots["integration logging platform property reference errors circular references should throw and notify users"] =
`
Property Reference Errors:
Circular definition cycle: color.foo.value, color.foo.value, color.foo.value
Circular definition cycle: color.teal.value, color.blue.value, color.green.value, color.teal.value
Problems were found when trying to resolve property references`;
Reference Errors:
Some token references (2) could not be found.
Use log.verbosity "verbose" or use CLI option --verbose for more details.
`;
/* end snapshot integration logging platform property reference errors circular references should throw and notify users */

16 changes: 16 additions & 0 deletions __integration__/logging/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ describe(`integration >`, () => {
await expect(stub.callCount).to.equal(0);
});

it(`should not log anything if the log warnings is set to disabled`, async () => {
const sd = new StyleDictionary({
log: {
warnings: 'disabled',
},
source: [
// including a specific file twice will throw value collision warnings
`__integration__/tokens/size/padding.json`,
`__integration__/tokens/size/_padding.json`,
],
platforms: {},
});
await sd.hasInitialized;
await expect(stub.callCount).to.equal(0);
});

it(`should not show warnings if given higher log level`, async () => {
const sd = new StyleDictionary(
{
Expand Down
75 changes: 75 additions & 0 deletions __integration__/logging/file.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,29 @@ describe(`integration`, () => {
expect(stub.callCount).to.equal(0);
});

it(`should not warn user about empty tokens with silent log verbosity`, async () => {
const sd = new StyleDictionary({
log: { warnings: 'disabled' },
source: [`__integration__/tokens/**/[!_]*.json?(c)`],
platforms: {
css: {
transformGroup: `css`,
files: [
{
destination: `empty.css`,
format: `css/variables`,
filter: (token) => token.type === `foo`,
},
],
},
},
});

await sd.buildAllPlatforms();
// 1 due to success log "css"
expect(stub.callCount).to.equal(1);
});

it(`should not warn user about empty tokens with log level set to error`, async () => {
const sd = new StyleDictionary({
log: { warnings: 'error' },
Expand Down Expand Up @@ -175,6 +198,30 @@ describe(`integration`, () => {
expect(stub.callCount).to.equal(0);
});

it(`should not warn user of name collisions with log verbosity silent`, async () => {
const sd = new StyleDictionary({
log: { warnings: 'disabled' },
source: [`__integration__/tokens/**/[!_]*.json?(c)`],
platforms: {
css: {
// no name transform means there will be name collisions
transforms: [`attribute/cti`],
buildPath,
files: [
{
destination: `nameCollisions.css`,
format: `css/variables`,
filter: (token) => token.type === `color`,
},
],
},
},
});
await sd.buildAllPlatforms();
// 1 due to success log "css"
expect(stub.callCount).to.equal(1);
});

it(`should throw a brief error of name collisions with log level set to error`, async () => {
const sd = new StyleDictionary({
log: { warnings: `error` },
Expand Down Expand Up @@ -350,6 +397,34 @@ describe(`integration`, () => {
expect(stub.callCount).to.equal(0);
});

it(`should not warn user of filtered references with log verbosity silent`, async () => {
const sd = new StyleDictionary({
log: { warnings: 'disabled' },
source: [`__integration__/tokens/**/[!_]*.json?(c)`],
platforms: {
css: {
transformGroup: `css`,
buildPath,
files: [
{
destination: `filteredReferences.css`,
format: `css/variables`,
options: {
outputReferences: true,
},
// background colors have references, only including them
// should warn the user
filter: (token) => token.attributes.type === `background`,
},
],
},
},
});
await sd.buildAllPlatforms();
// 1 due to success log "css"
expect(stub.callCount).to.equal(1);
});

it(`should throw a brief error of filtered references with log level set to error`, async () => {
const sd = new StyleDictionary({
log: { warnings: `error` },
Expand Down
10 changes: 9 additions & 1 deletion __node_tests__/cliBuild.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ describe('cliBuildWithJsConfig', () => {
expect(result.toString()).to.equal(``);
});

it('should only log success logs if --no-warn is used', () => {
const result = childProcess.execSync(
'node ./bin/style-dictionary build --config __tests__/__configs/test.js --no-warn',
);

expect(result.toString().match('Token collisions detected')).to.be.null;
});

it('should log briefly if neither --verbose nor --silent is used', () => {
//const logStub = stubMethod(console, 'log');
const result = childProcess.execSync(
Expand All @@ -54,7 +62,7 @@ css
⚠️ __tests__/__output/css/vars.css
While building vars.css, token collisions were found; output may be unexpected. Ignore this warning if intentional.
Use --verbose or log.verbosity: 'verbose' option for more details\n`);
Use log.verbosity "verbose" or use CLI option --verbose for more details.\n`);
});

it('should log verbosely if --verbose is used', () => {
Expand Down
17 changes: 17 additions & 0 deletions __tests__/StyleDictionary.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,23 @@ describe('StyleDictionary class + extend method', () => {
});

it('should throw an error if the collision is in source files and log is set to error', async () => {
const sd = new StyleDictionary(
{
source: ['__tests__/__tokens/paddings.json', '__tests__/__tokens/_paddings.json'],
log: { warnings: 'error', verbosity: 'verbose' },
},
{ init: false },
);
let error;
try {
await sd.init();
} catch (e) {
error = e;
}
await expect(error.message).to.matchSnapshot();
});

it('should throw a brief error if the collision is in source files and log is set to error and verbosity default', async () => {
const sd = new StyleDictionary(
{
source: ['__tests__/__tokens/paddings.json', '__tests__/__tokens/_paddings.json'],
Expand Down
9 changes: 8 additions & 1 deletion __tests__/__snapshots__/StyleDictionary.test.snap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
export const snapshots = {};
snapshots["StyleDictionary class + extend method should throw an error if the collision is in source files and log is set to error"] =
`
Property Value Collisions:
Token collisions detected (28):
Collision detected at: size.padding.zero! Original value: 0, New value: 0
Collision detected at: size.padding.zero! Original value: dimension, New value: dimension
Collision detected at: size.padding.zero! Original value: __tests__/__tokens/paddings.json, New value: __tests__/__tokens/_paddings.json
Expand Down Expand Up @@ -35,3 +36,9 @@ Collision detected at: size.padding.xxl! Original value: true, New value: true
`;
/* end snapshot StyleDictionary class + extend method should throw an error if the collision is in source files and log is set to error */

snapshots["StyleDictionary class + extend method should throw a brief error if the collision is in source files and log is set to error and verbosity default"] =
`
Token collisions detected (28):
Use log.verbosity "verbose" or use CLI option --verbose for more details.`;
/* end snapshot StyleDictionary class + extend method should throw a brief error if the collision is in source files and log is set to error and verbosity default */

10 changes: 6 additions & 4 deletions __tests__/exportPlatform.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,9 @@ describe('exportPlatform', () => {
});

describe('reference warnings', () => {
const errorMessage = `Problems were found when trying to resolve property references`;
const errorMessage = (amount = 1) => `Reference Errors:
Some token references (${amount}) could not be found.
Use log.verbosity "verbose" or use CLI option --verbose for more details.`;
const platforms = {
css: {
transformGroup: `css`,
Expand All @@ -403,7 +405,7 @@ describe('exportPlatform', () => {
platforms,
});

await expect(sd.exportPlatform('css')).to.eventually.be.rejectedWith(errorMessage);
await expect(sd.exportPlatform('css')).to.eventually.be.rejectedWith(errorMessage());
});

it('should throw if there are circular reference errors', async () => {
Expand All @@ -416,7 +418,7 @@ describe('exportPlatform', () => {
tokens,
platforms,
});
await expect(sd.exportPlatform('css')).to.eventually.be.rejectedWith(errorMessage);
await expect(sd.exportPlatform('css')).to.eventually.be.rejectedWith(errorMessage());
});

it('should throw if there are complex property reference errors', async () => {
Expand All @@ -436,7 +438,7 @@ describe('exportPlatform', () => {
tokens,
platforms,
});
await expect(sd.exportPlatform('css')).to.eventually.be.rejectedWith(errorMessage);
await expect(sd.exportPlatform('css')).to.eventually.be.rejectedWith(errorMessage(4));
});
});

Expand Down
Loading

0 comments on commit 8b6fff3

Please sign in to comment.