Skip to content

Commit

Permalink
Adding Unit Tests to run along with github workflow (#12)
Browse files Browse the repository at this point in the history
* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Create AreaChartUnitTest.test.tsx

* Update testCoverage.yml

* Update AreaChartUnitTest.test.tsx

* Create VerticalBarChartUT.test.tsx

* Rename AreaChartUnitTest.test.tsx to AreaChartUT.test.tsx

* Create UnitTests

* Delete tools/UnitTestApp/UnitTests

* Create UnitTests\

* Update and rename tools/UnitTestApp/UnitTests\ to tools/UnitTestApp/UnitTests/LineChartUT.test.tsx

* Rename tools/UnitTestApp/AreaChartUT.test.tsx to tools/UnitTestApp/UnitTests/AreaChartUT.test.tsx

* Rename tools/UnitTestApp/VerticalBarChartUT.test.tsx to tools/UnitTestApp/UnitTests/VerticalBarChartUT.test.tsx

* Update testCoverage.yml

* Update VerticalBarChartUT.test.tsx

* Update VerticalBarChartUT.test.tsx

* Update VerticalBarChartUT.test.tsx

* Update VerticalBarChartUT.test.tsx

* Update VerticalBarChartUT.test.tsx

* Update AreaChartUT.test.tsx

* Update LineChartUT.test.tsx

* Update VerticalBarChartUT.test.tsx

* Update LineChartUT.test.tsx

* Update VerticalBarChartUT.test.tsx

* Update LineChartUT.test.tsx

* Create TestEnvSetupScript.ts

* Update TestEnvSetupScript.ts

* Update AreaChartUT.test.tsx

* Update VerticalBarChartUT.test.tsx

* Update LineChartUT.test.tsx

* Update VerticalBarChartUT.test.tsx

* Update LineChartUT.test.tsx

* Update AreaChartUT.test.tsx

* Update AreaChartUT.test.tsx

* Update VerticalBarChartUT.test.tsx

* Update LineChartUT.test.tsx

* Update LineChartUT.test.tsx

* Update LineChartUT.test.tsx

* Update LineChartUT.test.tsx

* Update LineChartUT.test.tsx

* Update LineChartUT.test.tsx

* Update AreaChartUT.test.tsx

* Update VerticalBarChartUT.test.tsx

* Update TestEnvSetupScript.ts

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Rename tools/UnitTestApp/TestEnvSetupScript.ts to tools/UnitTestApp/UnitTests/TestEnvSetupScript.ts

* Update TestEnvSetupScript.ts

* Update AreaChartUT.test.tsx

* Update VerticalBarChartUT.test.tsx

* Update LineChartUT.test.tsx

* Update testCoverage.yml

* Update testCoverage.yml

* Create package.json

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Delete tools/UnitTestApp/UnitTests/package.json

* Updating testCoverage.yml

* Updating import

* Adding action for changing function visibility

* Updating test coverage workflow

* Updating test coverage workflow

* Updating test coverage workflow

* Updating test coverage workflow

* Updating the src dir

* Update testCoverage.yml

* Update testCoverage.yml

* Update testCoverage.yml

* Update index.js

* Updating workflow

* Updating home root

* Updating pwd

* Updating pwd dir

* Updating import for exec

* Update index.js

* Updating execSync

* Updating pwd

* Updating pwd

* Updating execSync

* Updating function to change function visibility

* Update index.js

* Update TestEnvSetupScript.js

* Building the action script
  • Loading branch information
srmukher authored Dec 8, 2023
1 parent a2f695c commit 85454d6
Show file tree
Hide file tree
Showing 7 changed files with 1,657 additions and 9 deletions.
34 changes: 25 additions & 9 deletions .github/workflows/testCoverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,32 @@ on:
jobs:
test_env_setup_job:
runs-on: ubuntu-latest
name: A job to setup test environment
name: Test coverage
steps:
- name: Checkout [master]
uses: actions/checkout@v4

steps:
- name: Checkout [react-charting]
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: "microsoft/fluentui"

- name: Run coverage report
working-directory: microsoft/fluentui
run: echo "$(<./packages/react-charting/src/index.ts)"
# run: yarn jest --coverage --collectCoverageFrom='./src/*'

path: repo1

- name: Show current directory
run: echo "$PWD"

- name: Change function visibility from private to public
id: setup
uses: ./tools/UnitTestApp/ChangeFunctionVisibility

- name: Install packages
run: yarn --cwd ./tools/UnitTestApp && yarn --cwd ./repo1 && yarn --cwd ./repo1/packages/react-charting

- name: Build
run: yarn --cwd ./repo1 buildto @fluentui/react-charting

- name: Test Environment Setup
run: cp -r ./tools/UnitTestApp/UnitTests ./repo1/packages/react-charting/src/components/

- name: Run the tests
run: cd ./repo1/packages/react-charting && yarn update-snapshots && yarn test --coverage --verbose
6 changes: 6 additions & 0 deletions tools/UnitTestApp/ChangeFunctionVisibility/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: 'Change function visibility'
description: 'Change function visibility from private to public'

runs:
using: 'node20'
main: '../dist/ChangeFunctionVisibility/index.js'
52 changes: 52 additions & 0 deletions tools/UnitTestApp/TestEnvSetupScript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const fs = require('fs');
const path = require('path');
const { exec } = require('child_process');

function getPWD(callback) {
exec('echo $PWD', (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
// Remove the trailing newline character
const pwd = stdout.trim();
// Call the callback function with the result
callback(pwd);
});
}

async function makePrivateFunctionsPublic(filePath) {
let data = await fs.readFileSync(filePath, 'utf8');
// Replace the words
data = data.replace(/\bprivate\b/g, "public");
// Write the file back
if (data != null && data != '' && data != undefined) {
await fs.writeFileSync(filePath, data);
}
};

async function readDirectory(dirPath) {
const items = await fs.readdirSync(dirPath);

items.forEach(item => {
const fullPath = path.join(dirPath, item);
if (fullPath.includes('.base.')) {
const stat = fs.statSync(fullPath);

if (stat.isDirectory()) {
readDirectory(fullPath);
} else {
makePrivateFunctionsPublic(fullPath);
}
}
});
}

const changeFunctionVisibility = async () => {
getPWD((pwd) => {
console.log(`The pwd is: ${pwd}`);
readDirectory(`${pwd}/repo1/packages/react-charting/src/components/`);
});
}

changeFunctionVisibility();
Loading

0 comments on commit 85454d6

Please sign in to comment.