Skip to content

Commit 3723f96

Browse files
authored
Merge pull request #109 from parthlambdatest/Dot-6103
[Dot-6103] feat: add support for `exclude` in custom viewport
2 parents c28d190 + 283b07b commit 3723f96

File tree

5 files changed

+21
-10
lines changed

5 files changed

+21
-10
lines changed

commands/storybook.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ async function storybook(serve, options) {
4545
process.exit(constants.ERROR_CATCHALL);
4646
}
4747
console.log('[smartui] Stories found: ', Object.keys(stories).length);
48+
console.log('[smartui] Number of stories rendered may differ based on the config file.');
4849

4950
// Capture DoM of every story and send it to renderer API
5051
await sendDoM(url, stories, storybookConfig, options);

commands/utils/static.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ function filterStories(dirPath, storybookConfig) {
7272
process.exit(constants.ERROR_CATCHALL);
7373
}
7474
console.log('[smartui] Stories found: ', storyIds.length);
75+
console.log('[smartui] Number of stories rendered may differ based on the config file.');
7576

7677
return storyIds
7778
}

commands/utils/validate.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,19 @@ function validateConfig(configFile) {
128128

129129
try {
130130
validateConfigBrowsers(storybookConfig.browsers);
131-
resolutions = storybookConfig.resolutions || storybookConfig.viewports
132-
storybookConfig.resolutions = validateConfigResolutions(resolutions);
131+
let resolutions = storybookConfig.resolutions || storybookConfig.viewports
132+
if (resolutions) {
133+
storybookConfig.resolutions = validateConfigResolutions(resolutions);
134+
}
133135
storybookConfig.viewports = storybookConfig.resolutions;
134-
validateCustomViewPorts(storybookConfig.customViewports)
136+
let customViewports = storybookConfig.customViewports;
137+
if (customViewports && customViewports.length > 0) {
138+
validateCustomViewPorts(storybookConfig.customViewports)
139+
}
140+
if (!resolutions && (!customViewports || customViewports.length === 0)) {
141+
console.log('[smartui] Error: No resolutions or customViewports found in config file');
142+
process.exit(constants.ERROR_CATCHALL);
143+
}
135144
} catch (error) {
136145
console.log(`[smartui] Error: Invalid config, ${error.message}`);
137146
process.exit(constants.ERROR_CATCHALL);
@@ -210,7 +219,7 @@ function validateConfigResolutions(resolutions) {
210219
if (width && width < MIN_RESOLUTION_WIDTH || width > MAX_RESOLUTION_WIDTH) {
211220
throw new ValidationError(`width must be > ${MIN_RESOLUTION_WIDTH}, < ${MAX_RESOLUTION_WIDTH}`);
212221
}
213-
if (height & (height < MIN_RESOLUTION_WIDTH || height > MAX_RESOLUTION_WIDTH)) {
222+
if (height && (height < MIN_RESOLUTION_HEIGHT|| height > MAX_RESOLUTION_HEIGHT)) {
214223
throw new ValidationError(`height must be > ${MIN_RESOLUTION_HEIGHT}, < ${MAX_RESOLUTION_HEIGHT}`);
215224
}
216225
res.push([width, height || 0]);
@@ -228,8 +237,8 @@ function validateCustomViewPorts(customViewports) {
228237
return
229238
}
230239
customViewports.forEach(element => {
231-
if (!Array.isArray(element.stories) || element.stories == 0) {
232-
throw new ValidationError('Missing `stories` in customViewports config. please check the config file');
240+
if (element.stories && element.stories.length !== 0 && element.exclude && element.exclude.length !== 0) {
241+
throw new ValidationError('Cannot specify both stories and excludeStories in customViewports');
233242
}
234243
if (element.styles) {
235244
if (!element.styles?.width) {
@@ -246,7 +255,7 @@ function validateCustomViewPorts(customViewports) {
246255
if (width && width < MIN_RESOLUTION_WIDTH || width > MAX_RESOLUTION_WIDTH) {
247256
throw new ValidationError(`customViewports.styles width must be > ${MIN_RESOLUTION_WIDTH}, < ${MAX_RESOLUTION_WIDTH}`);
248257
}
249-
if (height & (height < MIN_RESOLUTION_WIDTH || height > MAX_RESOLUTION_WIDTH)) {
258+
if (height && (height < MIN_RESOLUTION_HEIGHT || height > MAX_RESOLUTION_HEIGHT)) {
250259
throw new ValidationError(`customViewports.styles height must be > ${MIN_RESOLUTION_HEIGHT}, < ${MAX_RESOLUTION_HEIGHT}`);
251260
}
252261
element.styles.width = width;

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lambdatest/smartui-storybook",
3-
"version": "1.1.24",
3+
"version": "1.1.25",
44
"description": "LambdaTest's command-line interface (CLI) aimed to help you run your SmartUI tests on LambdaTest platform",
55
"main": "index.js",
66
"repository": {

0 commit comments

Comments
 (0)