Skip to content

Commit 5e1b3f6

Browse files
authored
Merge pull request #53 from LambdaTest/stage
Release v1.1.11
2 parents da8fa18 + 2d85650 commit 5e1b3f6

File tree

9 files changed

+39
-25
lines changed

9 files changed

+39
-25
lines changed

commands/config.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
const path = require('path');
22
const fs = require('fs');
3-
const { defaultSmartUIConfig } = require('./utils/config')
3+
const { defaultSmartUIConfig } = require('./utils/config');
4+
var { constants } = require('./utils/constants');
45

56
function createConfig(filepath) {
67
// default filepath
78
filepath = filepath || '.smartui.json';
89
let filetype = path.extname(filepath);
910
if (filetype != '.json') {
1011
console.log(`[smartui] Error: Config file must have .json extension`);
11-
process.exit(1);
12+
process.exitCode = constants.ERROR_CATCHALL;
13+
return
1214
}
1315

1416
// verify the file does not already exist
1517
if (fs.existsSync(filepath)) {
1618
console.log(`[smartui] Error: LambdaTest SmartUI config already exists: ${filepath}`);
17-
process.exit(1);
19+
process.exitCode = constants.ERROR_CATCHALL;
20+
return
1821
}
1922

2023
// write stringified default config options to the filepath

commands/storybook.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@ async function storybook(serve, options) {
4141

4242
if (Object.keys(stories).length === 0) {
4343
console.log('[smartui] Error: No stories found');
44-
process.exit(0);
44+
process.exit(constants.ERROR_CATCHALL);
4545
}
4646
console.log('[smartui] Stories found: ', Object.keys(stories).length);
4747

4848
// Capture DoM of every story and send it to renderer API
4949
await sendDoM(url, stories, storybookConfig, options);
5050
})
5151
.catch(function (error) {
52+
process.exitCode = constants.ERROR_CATCHALL;
5253
if (error.response) {
5354
console.log('[smartui] Cannot fetch stories. Error: ', error.message);
5455
} else if (error.request) {
@@ -76,7 +77,7 @@ async function storybook(serve, options) {
7677
})
7778
.catch(function (err) {
7879
console.log(`[smartui] Cannot compress ${dirPath}. Error: ${err.message}`);
79-
process.exit(0);
80+
process.exit(constants.ERROR_CATCHALL);
8081
});
8182

8283
// Upload to S3
@@ -94,7 +95,7 @@ async function storybook(serve, options) {
9495
.catch(function (error) {
9596
console.log(`[smartui] Cannot upload ${dirPath}. Error: ${error.message}`);
9697
fs.rmSync('storybook-static.zip');
97-
process.exit(0);
98+
process.exit(constants.ERROR_CATCHALL);
9899
});
99100

100101
// Prepare payload data
@@ -139,6 +140,7 @@ async function storybook(serve, options) {
139140
} else {
140141
console.log('[smartui] Build failed: Error: ', error.message);
141142
}
143+
process.exitCode = constants.ERROR_CATCHALL;
142144
});
143145
})
144146
.catch(function (error) {
@@ -147,7 +149,7 @@ async function storybook(serve, options) {
147149
} else {
148150
console.log('[smartui] Error: ', error.message);
149151
}
150-
process.exit(0);
152+
process.exitCode = constants.ERROR_CATCHALL;
151153
});
152154

153155
}

commands/utils/constants.js

+5
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,9 @@ constants.prod = {
2222
};
2323
constants.VALID_BROWSERS = ['chrome', 'safari', 'firefox', 'edge'];
2424

25+
// Error codes
26+
constants.ERROR_CATCHALL = 1
27+
constants.ERROR_BUILD_ALREADY_EXISTS = 3
28+
constants.ERROR_CHANGES_FOUND_OR_REJECTED = 4
29+
2530
module.exports = { constants };

commands/utils/dom.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ async function sendDoM(storybookUrl, stories, storybookConfig, options) {
1515
fs.mkdir('doms', (err) => {
1616
if (err) {
1717
console.error(err);
18-
process.exit(1);
18+
process.exit(constants.ERROR_CATCHALL);
1919
}
2020
});
2121
}
@@ -106,7 +106,7 @@ function getBase64(url) {
106106
.then(response => response.data)
107107
.catch(function (error) {
108108
console.log('[smartui] Error: ', error.message);
109-
process.exit(0);
109+
process.exit(constants.ERROR_CATCHALL);
110110
});
111111
}
112112

commands/utils/polling.js

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ async function shortPolling(buildId, retries = 0, options) {
3939
])
4040
});
4141
console.log(table.toString());
42+
43+
if (response.data.buildResults.changesFound != 0 || response.data.buildResults.rejected != 0) {
44+
process.exitCode = constants.ERROR_CHANGES_FOUND_OR_REJECTED;
45+
}
4246
})
4347
} else {
4448
if (response.data.baseline) {

commands/utils/static.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function filterStories(dirPath, storybookConfig) {
6464
}
6565
if (storyIds.length === 0) {
6666
console.log('[smartui] Error: No stories found');
67-
process.exit(0);
67+
process.exit(constants.ERROR_CATCHALL);
6868
}
6969
console.log('[smartui] Stories found: ', storyIds.length);
7070

commands/utils/validate.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ function validateProjectToken(options) {
3333
} else {
3434
console.log('[smartui] Project Token not validated. Error: ', error.message);
3535
}
36-
process.exit(0);
36+
process.exit(constants.ERROR_CATCHALL);
3737
});
3838
}
3939
else {
4040
console.log('[smartui] Error: No PROJECT_TOKEN set');
41-
process.exit(0);
41+
process.exit(constants.ERROR_CATCHALL);
4242
}
4343
};
4444

@@ -48,7 +48,7 @@ function validateStorybookUrl(url) {
4848
aboutUrl = new URL('?path=/settings/about', url).href;
4949
} catch (error) {
5050
console.log('[smartui] Error: ', error.message)
51-
process.exit(0);
51+
process.exit(constants.ERROR_CATCHALL);
5252
}
5353
return axios.get(aboutUrl)
5454
.then(function (response) {
@@ -62,24 +62,24 @@ function validateStorybookUrl(url) {
6262
} else {
6363
console.log('[smartui] Connection to storybook not established. Error: ', error.message);
6464
}
65-
process.exit(0);
65+
process.exit(constants.ERROR_CATCHALL);
6666
});
6767
};
6868

6969
async function validateStorybookDir(dir) {
7070
// verify the directory exists
7171
if (!fs.existsSync(dir)) {
7272
console.log(`[smartui] Error: No directory found: ${dir}`);
73-
process.exit(1);
73+
process.exit(constants.ERROR_CATCHALL);
7474
}
7575
// Verify project.json and stories.json exist to confirm it's a storybook-static dir
7676
if (!fs.existsSync(dir + '/index.html')) {
7777
console.log(`[smartui] Given directory is not a storybook static directory. Error: No index.html found`);
78-
process.exit(1);
78+
process.exit(constants.ERROR_CATCHALL);
7979
}
8080
if (!fs.existsSync(dir + '/stories.json')) {
8181
console.log(`[smartui] Given directory is not a storybook static directory. Error: No stories.json found`);
82-
process.exit(1);
82+
process.exit(constants.ERROR_CATCHALL);
8383
}
8484
};
8585

@@ -97,21 +97,21 @@ async function validateLatestBuild(options) {
9797
if (response.data.status === 'Failure') {
9898
console.log(`[smartui] Build with commit '${commit.shortHash}' on branch '${commit.branch}' already exists.`);
9999
console.log('[smartui] Use option --force-rebuild to forcefully push a new build.');
100-
process.exit(0);
100+
process.exit(constants.ERROR_BUILD_ALREADY_EXISTS);
101101
}
102102
})
103103
.catch(function (error) {
104104
// TODO: Add retries
105105
console.log('[smartui] Cannot fetch latest build of the project. Error: ', error.message);
106-
process.exit(1);
106+
process.exit(constants.ERROR_CATCHALL);
107107
});
108108
}
109109

110110
function validateConfig(configFile) {
111111
// Verify config file exists
112112
if (!fs.existsSync(configFile)) {
113113
console.log(`[smartui] Error: Config file ${configFile} not found.`);
114-
process.exit(1);
114+
process.exit(constants.ERROR_CATCHALL);
115115
}
116116

117117
// Parse JSON
@@ -120,15 +120,15 @@ function validateConfig(configFile) {
120120
storybookConfig = JSON.parse(fs.readFileSync(configFile)).storybook;
121121
} catch (error) {
122122
console.log('[smartui] Error: ', error.message);
123-
process.exit(1);
123+
process.exit(constants.ERROR_CATCHALL);
124124
}
125125

126126
try {
127127
validateConfigBrowsers(storybookConfig.browsers);
128128
storybookConfig.resolutions = validateConfigResolutions(storybookConfig.resolutions);
129129
} catch (error) {
130130
console.log(`[smartui] Error: Invalid config, ${error.message}`);
131-
process.exit(0);
131+
process.exit(constants.ERROR_CATCHALL);
132132
}
133133

134134
// Sanity check waitForTimeout

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lambdatest/smartui-storybook",
3-
"version": "1.1.10",
3+
"version": "1.1.11",
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)