Skip to content

Commit 7895fda

Browse files
committed
add tunnel support in storybook static
1 parent b98d98e commit 7895fda

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

commands/storybook.js

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

163+
console.log('[smartui] Payload: ', JSON.stringify(payload, null, 2));
164+
console.log('URL : ', new URL(constants[options.env].STATIC_RENDER_PATH, constants[options.env].BASE_URL).href);
162165
// Call static render API
163166
await axios.post(new URL(constants[options.env].STATIC_RENDER_PATH, constants[options.env].BASE_URL).href, payload)
164167
.then(async function (response) {

commands/utils/validate.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,25 @@ function validateConfig(configFile) {
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+
} catch (error) {
164+
console.log('[smartui] Error: ', error.message);
165+
process.exit(constants.ERROR_CATCHALL);
166+
}
167+
168+
return tunnelConfig
169+
}
170+
152171
function validateConfigBrowsers(browsers) {
153172
if (browsers.length == 0) {
154173
throw new ValidationError('empty browsers list.');
@@ -248,5 +267,6 @@ module.exports = {
248267
validateConfig,
249268
validateConfigBrowsers,
250269
validateConfigResolutions,
251-
validateCustomViewPorts
270+
validateCustomViewPorts,
271+
validateTunnel,
252272
};

index.js

Lines changed: 7 additions & 3 deletions
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');
@@ -12,7 +12,7 @@ program
1212
.name('smartui')
1313
.description('CLI to help you run your SmartUI tests on LambdaTest platform')
1414
.version('v' + version)
15-
.addOption(new Option('--env <prod|stage>', 'Runtime environment option').choices(['prod', 'stage']));
15+
.addOption(new Option('--env <prod|stage>', 'Runtime environment option').choices(['prod', 'stage', 'dev']));
1616

1717
const configCommand = program.command('config')
1818
.description('Manage LambdaTest SmartUI config')
@@ -50,10 +50,14 @@ 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+
console.log(`[smartui] Tunnel Config : ${JSON.stringify(options.tunnel, null, 2)}`);
56+
}
5357
if (options.config) {
5458
options.config = validateConfig(options.config);
5559
}
56-
60+
5761
await validateProjectToken(options);
5862
if (!options.forceRebuild) await validateLatestBuild(options);
5963
storybook(serve, options);

0 commit comments

Comments
 (0)