From 3b1b9cdae98bbd0725a1a650c4e536f189aa1873 Mon Sep 17 00:00:00 2001 From: kirrg001 Date: Mon, 13 May 2024 13:02:28 +0200 Subject: [PATCH] chore: added github action workflow for test stats --- .github/workflows/schedule-test-stats.yaml | 16 +++++++ bin/gather-test-stats.js | 52 ++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 .github/workflows/schedule-test-stats.yaml create mode 100644 bin/gather-test-stats.js diff --git a/.github/workflows/schedule-test-stats.yaml b/.github/workflows/schedule-test-stats.yaml new file mode 100644 index 0000000000..854cc18687 --- /dev/null +++ b/.github/workflows/schedule-test-stats.yaml @@ -0,0 +1,16 @@ +name: Schedule Test Stats + +on: + schedule: + - cron: '0 0 * * 1' # Every Monday at 06:00 AM UTC + +jobs: + run-script: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + + - name: Execute stats + run: node bin/gather-test-stats.js diff --git a/bin/gather-test-stats.js b/bin/gather-test-stats.js new file mode 100644 index 0000000000..5a47debffe --- /dev/null +++ b/bin/gather-test-stats.js @@ -0,0 +1,52 @@ +/* + * (c) Copyright IBM Corp. 2024 + */ + +'use strict'; + +const fs = require('fs'); +const path = require('path'); + +const packagesFolder = path.join(__dirname, '..', 'packages'); +let noOfTestFiles = 0; +let noOfTestCases = 0; + +function walkSync(dir, list = []) { + const files = fs.readdirSync(dir); + + files.forEach(file => { + const currentPath = path.join(dir, file); + + if (fs.statSync(currentPath).isDirectory()) { + if (file === 'node_modules') { + return; + } + + list = walkSync(currentPath, list); + } else if (currentPath.endsWith('test.js')) { + list.push(currentPath); + } + }); + + return list; +} + +const packages = fs.readdirSync(packagesFolder); +packages.forEach(pkg => { + const packageTestFolder = path.join(packagesFolder, pkg, 'test'); + const files = walkSync(packageTestFolder); + + noOfTestFiles += files.length; + + files.forEach(file => { + const content = fs.readFileSync(file, 'utf8'); + const match = content.match(/it\('/g); + + if (match) { + noOfTestCases += match.length; + } + }); +}); + +console.log(`TOTAL NUMBER OF TEST FILES: ${noOfTestFiles}`); +console.log(`TOTAL NUMBER OF TEST CASES: ${noOfTestCases}`);