Skip to content

Commit 1c623ce

Browse files
Merge pull request #102 from LambdaTest/stage
Release tunnel support in storybook static
2 parents b98d98e + a84dfb4 commit 1c623ce

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed

commands/storybook.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,17 @@ async function storybook(serve, options) {
157157
githubURL: process.env.GITHUB_URL || '',
158158
},
159159
buildName: buildName,
160+
tunnel: options.tunnel || {},
160161
}
161162

162163
// Call static render API
163164
await axios.post(new URL(constants[options.env].STATIC_RENDER_PATH, constants[options.env].BASE_URL).href, payload)
164165
.then(async function (response) {
166+
if (response.data && response.data.error) {
167+
console.log('[smartui] Error: ', response.data.error.message);
168+
process.exitCode = constants.ERROR_CATCHALL;
169+
return
170+
}
165171
console.log('[smartui] Build URL: ', response.data.data.buildURL);
166172
console.log('[smartui] Build in progress...');
167173
await shortPolling(response.data.data.buildId, 0, options);

commands/utils/validate.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,37 @@ function validateConfig(configFile) {
140140
// Sanity check waitForTimeout
141141
if (!Object.hasOwn(storybookConfig, 'waitForTimeout')) {
142142
storybookConfig.waitForTimeout = 0;
143-
} else if (storybookConfig.waitForTimeout <= 0 || storybookConfig.waitForTimeout > 30000) {
144-
console.log('[smartui] Warning: Invalid config, value of waitForTimeout must be > 0 and <= 30000');
143+
} else if (storybookConfig.waitForTimeout <= 0 || storybookConfig.waitForTimeout > 300000) {
144+
console.log('[smartui] Warning: Invalid config, value of waitForTimeout must be > 0 and <= 300000');
145145
console.log('[smartui] If you do not wish to include waitForTimeout parameter, remove it from the config file.');
146146
storybookConfig.waitForTimeout = 0;
147147
}
148148

149149
return storybookConfig
150150
}
151151

152+
function validateTunnel(configFile) {
153+
// Verify config file exists
154+
if (!fs.existsSync(configFile)) {
155+
console.log(`[smartui] Error: Config file ${configFile} not found.`);
156+
process.exit(constants.ERROR_CATCHALL);
157+
}
158+
159+
let tunnelConfig;
160+
try {
161+
let config = JSON.parse(fs.readFileSync(configFile));
162+
tunnelConfig = config.tunnel || {};
163+
if (tunnelConfig && tunnelConfig.type != "manual") {
164+
throw new ValidationError('Invalid tunnel type. Accepted type is `manual` only');
165+
}
166+
} catch (error) {
167+
console.log('[smartui] Error: ', error.message);
168+
process.exit(constants.ERROR_CATCHALL);
169+
}
170+
171+
return tunnelConfig
172+
}
173+
152174
function validateConfigBrowsers(browsers) {
153175
if (browsers.length == 0) {
154176
throw new ValidationError('empty browsers list.');
@@ -248,5 +270,6 @@ module.exports = {
248270
validateConfig,
249271
validateConfigBrowsers,
250272
validateConfigResolutions,
251-
validateCustomViewPorts
273+
validateCustomViewPorts,
274+
validateTunnel,
252275
};

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const { Command, Option } = require('commander');
44
const program = new Command();
55
const { storybook } = require('./commands/storybook');
6-
const { validateProjectToken, validateLatestBuild, validateConfig } = require('./commands/utils/validate');
6+
const { validateProjectToken, validateLatestBuild, validateConfig, validateTunnel } = require('./commands/utils/validate');
77
const { createConfig } = require('./commands/config');
88
const { version } = require('./package.json');
99
const { checkUpdate } = require('./commands/utils/package');
@@ -50,6 +50,9 @@ program.command('storybook')
5050
console.log(JSON.stringify(error, null, 2));
5151
process.exit(1);
5252
}
53+
if (options.config) {
54+
options.tunnel = validateTunnel(options.config);
55+
}
5356
if (options.config) {
5457
options.config = validateConfig(options.config);
5558
}

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.21",
3+
"version": "1.1.22",
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)