Skip to content

Commit aa2e1cd

Browse files
committed
🎨 added instrumentation for node_modules package
1 parent b01a8db commit aa2e1cd

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

bin/commands/runs.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,13 @@ module.exports = function run(args, rawArgs) {
159159
// Archive the spec files
160160
logger.debug("Started archiving test suite");
161161
markBlockStart('zip.archive');
162-
return archiver.archive(bsConfig.run_settings, config.fileName, args.exclude, md5data).then(function (data) {
162+
return archiver.archive(bsConfig.run_settings, config.fileName, args.exclude, md5data).then(async function (data) {
163163
logger.debug("Completed archiving test suite");
164164
markBlockEnd('zip.archive');
165165

166166
let test_zip_size = utils.fetchZipSize(path.join(process.cwd(), config.fileName));
167167
let npm_zip_size = utils.fetchZipSize(path.join(process.cwd(), config.packageFileName));
168+
let node_modules_size = await utils.fetchFolderSize(path.join(process.cwd(), "node_modules"))
168169

169170
//Package diff
170171
let isPackageDiff = false;
@@ -275,6 +276,7 @@ module.exports = function run(args, rawArgs) {
275276
build_id: data.build_id,
276277
test_zip_size: test_zip_size,
277278
npm_zip_size: npm_zip_size,
279+
node_modules_size: node_modules_size,
278280
test_suite_zip_upload: md5data.zipUrlPresent ? 0 : 1,
279281
package_zip_upload: md5data.packageUrlPresent ? 0 : 1
280282
};

bin/helpers/utils.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ const { v4: uuidv4 } = require('uuid');
88
const browserstack = require('browserstack-local');
99
const crypto = require('crypto');
1010
const util = require('util');
11+
const { promisify } = require('util');
12+
const readdir = promisify(fs.readdir);
13+
const stat = promisify(fs.stat);
1114

1215
const usageReporting = require("./usageReporting"),
1316
logger = require("./logger").winstonLogger,
@@ -1278,6 +1281,34 @@ exports.fetchZipSize = (fileName) => {
12781281
}
12791282
}
12801283

1284+
const getDirectorySize = async function(dir) {
1285+
try{
1286+
const subdirs = (await readdir(dir));
1287+
const files = await Promise.all(subdirs.map(async (subdir) => {
1288+
const res = path.resolve(dir, subdir);
1289+
const s = (await stat(res));
1290+
return s.isDirectory() ? getDirectorySize(res) : (s.size);
1291+
}));
1292+
return files.reduce((a, f) => a+f, 0);
1293+
}catch(e){
1294+
console.log(`Error ${e}`)
1295+
logger.debug('Failed to get file or directory.');
1296+
return 0;
1297+
}
1298+
};
1299+
1300+
exports.fetchFolderSize = async (dir) => {
1301+
try {
1302+
if(fs.existsSync(dir)){
1303+
return (await getDirectorySize(dir) / 1024 / 1024);
1304+
}
1305+
return 0;
1306+
} catch (error) {
1307+
logger.debug(`Failed to get directory size.`);
1308+
return 0;
1309+
}
1310+
}
1311+
12811312
exports.getVideoConfig = (cypressConfig) => {
12821313
let conf = {
12831314
video: true,

0 commit comments

Comments
 (0)