Skip to content
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
66 changes: 61 additions & 5 deletions src/build/tasks/__tests__/theme-json-schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('validateJson', () => {
},
}),
).toThrowError(
'Tokens validation error: instance.tokens.border-radius-one.$value does not match pattern "\\\\d+(px|rem|%)"',
'Tokens validation error: instance.tokens.border-radius-one.$value does not match pattern "^\\\\d+(\\\\.\\\\d+)?(px|rem|%)$"',
);
});

Expand Down Expand Up @@ -158,7 +158,7 @@ describe('validateJson', () => {
},
}),
).toBe(true);
['100 px', '20ps', '100 %'].forEach((invalidValue) => {
['100 px', '20ps', '100 %', '100px a'].forEach((invalidValue) => {
expect(() =>
validateTokens({
'space-button': {
Expand All @@ -169,7 +169,7 @@ describe('validateJson', () => {
},
}),
).toThrowError(
'Tokens validation error: instance.tokens.space-button.$value.comfortable does not match pattern "\\\\d+(px|rem|%)"',
'Tokens validation error: instance.tokens.space-button.$value.comfortable does not match pattern "^\\\\d+(\\\\.\\\\d+)?(px|rem|%)$"',
);
});
});
Expand Down Expand Up @@ -269,6 +269,62 @@ describe('validateJson', () => {
});
});

describe('font-size', () => {
test('accepts certain formats', () => {
['14px', '2rem', '1em', '1.5rem'].forEach((validValue) => {
expect(
validateTokens({
'font-size-body': {
$value: validValue,
},
}),
).toBe(true);
});
});

test('rejects invalid formats', () => {
['14', '14 px', '14ps', '1em a'].forEach((invalidValue) => {
expect(() =>
validateTokens({
'font-size-body': {
$value: invalidValue,
},
}),
).toThrowError(
'Tokens validation error: instance.tokens.font-size-body.$value does not match pattern "^\\\\d+(\\\\.\\\\d+)?(px|rem|em)$"',
);
});
});
});

describe('line-height', () => {
test('accepts certain formats', () => {
['20px', '1.5rem', '1em'].forEach((validValue) => {
expect(
validateTokens({
'line-height-body': {
$value: validValue,
},
}),
).toBe(true);
});
});

test('rejects invalid formats', () => {
['20', '20 px', '20ps', '1em a'].forEach((invalidValue) => {
expect(() =>
validateTokens({
'line-height-body': {
$value: invalidValue,
},
}),
).toThrowError(
'Tokens validation error: instance.tokens.line-height-body.$value does not match pattern "^\\\\d+(\\\\.\\\\d+)?(px|rem|em)$"',
);
});
});
});

describe('letter spacing', () => {
test('accepts positive, negative, and zero values with valid units', () => {
['1px', '-0.5rem', '0em', '0.25px', '-1.5em', '.5px', '-.5rem'].forEach((validValue) => {
Expand All @@ -295,15 +351,15 @@ describe('validateJson', () => {
});

test('rejects invalid formats', () => {
['100', '-1', '1.5', '100 px', '20ps', '.px', '-.rem'].forEach((invalidValue) => {
['100', '-1', '1.5', '100 px', '20ps', '.px', '-.rem', 'revert-', '1px test'].forEach((invalidValue) => {
expect(() =>
validateTokens({
'letter-spacing-button': {
$value: invalidValue,
},
}),
).toThrowError(
'Tokens validation error: instance.tokens.letter-spacing-button.$value does not match pattern "normal|inherit|initial|revert|revert-layer|unset|-?\\\\d*\\\\.?\\\\d+(px|rem|em)"',
'Tokens validation error: instance.tokens.letter-spacing-button.$value does not match pattern "^(normal|inherit|initial|revert|revert-layer|unset|-?\\\\d*\\\\.?\\\\d+(px|rem|em))$"',
);
});
});
Expand Down
8 changes: 4 additions & 4 deletions src/build/tasks/theme-json-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@ const colorValueSchema: GenericSchema = {
};
const spaceValueSchema: GenericSchema = {
type: 'string',
pattern: '\\d+(px|rem|%)',
pattern: '^\\d+(\\.\\d+)?(px|rem|%)$',
};
const borderWidthValueSchema: GenericSchema = {
type: 'string',
pattern: '\\d+(px|rem|em)',
pattern: '^\\d+(\\.\\d+)?(px|rem|em)$',
};
const textSizeValueSchema: GenericSchema = {
type: 'string',
pattern: '\\d+(px|rem|em)',
pattern: '^\\d+(\\.\\d+)?(px|rem|em)$',
};
const textWeightValueSchema: GenericSchema = {
type: 'string',
pattern: '300|400|700|900|normal|bold|light|heavy',
};
const letterSpacingValueSchema: GenericSchema = {
type: 'string',
pattern: 'normal|inherit|initial|revert|revert-layer|unset|-?\\d*\\.?\\d+(px|rem|em)',
pattern: '^(normal|inherit|initial|revert|revert-layer|unset|-?\\d*\\.?\\d+(px|rem|em))$',
};
const durationValueSchema: GenericSchema = { type: 'string', pattern: '\\d+m?s' };

Expand Down
Loading