Skip to content

New generate test changes apeksha #5

New generate test changes apeksha

New generate test changes apeksha #5

Workflow file for this run

name: Generate Jest Tests - Improved
on:
# This line enables manual triggering of this workflow.
workflow_dispatch:
defaults:
run:
#working-directory: app/client
shell: bash
jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: "Start of workflow"
run: |
echo "Starting the workflow"
- name: "Checkout code"
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Get changed files in the client folder
id: changed-files-specific
uses: tj-actions/changed-files@v41
with:
files: "app/client/**"
base_sha: "release"
- name: Run step if any file(s) in the client folder change
if: steps.changed-files-specific.outputs.any_changed == 'true'
env:
ALL_CHANGED_FILES: ${{ steps.changed-files-specific.outputs.all_changed_files }}
run: |
for file in ${ALL_CHANGED_FILES}; do
echo "$file was changed"
done
- name: Install jest-gen-test
run: yarn add jest-test-gen
- name: Generate Tests
if: steps.changed-files-specific.outputs.any_changed == 'true'
env:
ALL_CHANGED_FILES: ${{ steps.changed-files-specific.outputs.all_changed_files }}
run: |
for file in ${ALL_CHANGED_FILES}; do
testfile=`echo $file|sed 's/.ts/.generated.test.ts/g'`
yarn run jest-test-gen $file
echo $testfile >> generated_test_files.txt
done
# git ignore yarn.lock
# Step 1: Run Unit Tests on Generated Files
- name: Run unit tests on generated files
id: run_tests
run: |
while IFS= read -r testfile; do
yarn test "$testfile" --json --outputFile=jest_results.json || echo "$testfile" >> failed_tests.txt
done < generated_test_files.txt
continue-on-error: true # Continue even if tests fail to capture results
- name: Debug: Check jest_results.json existence

Check failure on line 64 in .github/workflows/GenerateTests.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/GenerateTests.yml

Invalid workflow file

You have an error in your yaml syntax on line 64
id: check_results_existence
run: |
if [ -f jest_results.json ]; then
echo "jest_results.json file exists."
echo "::set-output name=results_exist::true"
else
echo "jest_results.json file does NOT exist."
echo "::set-output name=results_exist::false"
continue-on-error: true
- name: Check if jest_results.json exists
run: |
if steps.check_results_existence.outputs.results_exist == 'false'; then
echo "jest_results.json file does NOT exist."
exit 1
fi
# Step 2: Get Failed Tests
- name: Capture failed test cases
id: failed_tests
run: |
if [ -f failed_tests.txt ]; then
failed_tests=$(cat failed_tests.txt | jq -R -s -c 'split("\n")[:-1]')
echo "::set-output name=failed_tests::$failed_tests"
else
echo "::set-output name=failed_tests::[]"
fi
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install OpenAI package
run: pip install openai
- name: Add OpenAI API Key
run: echo "OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}" >> $GITHUB_ENV
- name: Fix failing tests
run: |
cp /home/runner/work/appsmith/appsmith/.github/workflows/scripts/fix_failing_tests.py ./
python fix_failing_tests.py
- name: Run fixed tests
run: npm test -- --json --outputFile=jest_results_fixed.json || true
- name: Check if tests passed
run: |
if grep -q '"status":"failed"' jest_results_fixed.json; then
exit 1
fi
# Commit newly generated test files
- name: Commit generated test files
if: steps.changed-files-specific.outputs.any_changed == 'true'
run: |
git config --global user.email "[email protected]"
git config --global user.name "github-actions[bot]"
git add .
git reset -- package.json
git reset -- yarn.lock
git commit -m "chore:generate tests for changed files"
git push