Skip to content

Commit

Permalink
fix: dangerJS check now correctly detects missing design token changes (
Browse files Browse the repository at this point in the history
#3057)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
SiTaggart and kodiakhq[bot] committed Mar 1, 2023
1 parent b27a244 commit a790975
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
19 changes: 16 additions & 3 deletions .danger/__tests__/missing-changesets-check.spec.ts
Expand Up @@ -29,6 +29,12 @@ const mockPackList = [
private: true,
location: '/Users/simon/dev/twilio/design-systems/paste/packages/paste-core/primitives/box',
},
{
name: '@twilio-paste/design-tokens',
version: '0.0.0',
private: false,
location: '/Users/simon/dev/twilio/design-systems/paste/packages/paste-design-tokens',
},
];

describe('getMissingPackagesFromChangesets()', () => {
Expand All @@ -54,9 +60,15 @@ describe('getMissingPackagesFromChangesets()', () => {
'./.danger/__fixtures__/changeset/popular-cheetahs-punch.md',
'./.danger/__fixtures__/changeset/pretty-cameras-burn.md',
],
['@twilio-paste/avatar', '@twilio-paste/box', '@twilio-paste/icons', '@twilio-paste/core']
[
'@twilio-paste/avatar',
'@twilio-paste/box',
'@twilio-paste/icons',
'@twilio-paste/core',
'@twilio-paste/design-tokens',
]
)
).toEqual(['@twilio-paste/core']);
).toEqual(['@twilio-paste/core', '@twilio-paste/design-tokens']);

expect(
getMissingPackagesFromChangesets(
Expand Down Expand Up @@ -92,14 +104,15 @@ describe('missingChangesetCheck()', () => {
'packages/paste-icons/src/index.tsx',
'packages/paste-core/components/avatar/src/index.tsx',
'packages/paste-core/primitives/box/src/index.tsx',
'packages/paste-design-tokens/tokens/themes/evergreen/global/background-color.yml',
'yarn.lock',
'./.danger/__fixtures__/changeset/pretty-cameras-burn.md',
],
created_files: [],
},
};
missingChangesetCheck(mockPackList);
expect(global.fail).toHaveBeenCalledTimes(1);
expect(global.fail).toHaveBeenCalledTimes(2);
});

it('should fail twice for two packages that are not in a changeset', () => {
Expand Down
35 changes: 35 additions & 0 deletions .danger/__tests__/utils.spec.ts
Expand Up @@ -232,6 +232,41 @@ describe('danger utils', () => {
)
).toEqual(['@twilio-paste/style-props', '@twilio-paste/alert-dialog']);
});

it('should return the design-tokens package with even though no src files are updated', () => {
expect(
getUnpublishedPackageNames(
[
'package.json',
'packages/paste-style-props/src/index.ts',
'packages/paste-core/components/alert-dialog/stories/index.stories.tsx',
'packages/paste-design-tokens/tokens/themes/evergreen/global/background-color.yml',
'yarn.lock',
'.changeset/pretty-cameras-burn.md',
],
[
{
name: '@twilio-paste/alert-dialog',
version: '3.1.0',
private: false,
location: '/Users/simon/dev/twilio/design-systems/paste/packages/paste-core/components/alert-dialog',
},
{
name: '@twilio-paste/style-props',
version: '3.1.0',
private: false,
location: '/Users/simon/dev/twilio/design-systems/paste/packages/paste-style-props',
},
{
name: '@twilio-paste/design-tokens',
version: '3.1.0',
private: false,
location: '/Users/simon/dev/twilio/design-systems/paste/packages/paste-design-tokens',
},
]
)
).toEqual(['@twilio-paste/style-props', '@twilio-paste/design-tokens']);
});
});

describe('getChangesetsFromFiles', () => {
Expand Down
9 changes: 8 additions & 1 deletion .danger/utils.ts
Expand Up @@ -68,7 +68,14 @@ export const getUnpublishedPackageNames = (touchedFiles: string[], publicPackage
touchedFiles.forEach((filePath) => {
const packageName = getPackageNameFromPath(filePath, publicPackages);

if (filePath.includes('/src/')) {
// all packages are uniform, except for design tokens. Source files are in the src directory.
// any changes to tokens, formatters or types in design tokens also need to be released
if (
filePath.includes('/src/') ||
filePath.includes('/paste-design-tokens/tokens/') ||
filePath.includes('/paste-design-tokens/formatters/') ||
filePath.includes('/paste-design-tokens/types/')
) {
uniquePackages.add(packageName);
}
});
Expand Down

0 comments on commit a790975

Please sign in to comment.