From af56de285b8f60b45b5b08267a940843109e1e6b Mon Sep 17 00:00:00 2001 From: Deepjyoti Date: Thu, 5 Dec 2024 02:31:51 +0530 Subject: [PATCH] feat: Add changes to run tests using circle ci for partial reruns (#965) * Add changes to run tests using circle ci for partial reruns * Update config continue to store results for backend sdk and other tests * Update config_continue template to fix some syntax issues * Undo placeholder change to keep things same * Undo change for removing workflow version based on circleci linter * Add a print context job to debug circle ci issues * Remove print context step * Add some improvements for proper partial re-run support in circle CI * Update test run commands to make them run without issues * Remove use of test.mocha.env in tests that don't use it * Remove use of mocha multi in test runs * Add some fixes to run tests more accurately in different setups * Add fixes for exporting env variables properly * Add fixes to properly store the test results through junit * Fix mocha tests with free core * Add some fixes to properly set multi variable * Install mocha multi-junit-reporter package for tests * Add changes to not use absolute path for junit results * Update mocha file environment variable to match other paths * Use a simple report name for junit result reports * Add mocha junit file name fixes * Fix multi variable not being visible to runner * Add debug steps for checking the junit file * Add support for printing test-results directory for debugging * Add fix for the path for test-results * Add support for proper paths for all tests * Remove unused parameters from unit-test job --- .circleci/config_continue.yml | 10 +++++++--- .circleci/setupAndTestBackendSDKWithFreeCore.sh | 17 ++++++++++++----- .circleci/setupAndTestWithAuthReact.sh | 8 +++++++- .circleci/setupAndTestWithFreeCore.sh | 16 +++++++++++----- .circleci/setupAndTestWithFrontend.sh | 16 +++++++++++----- 5 files changed, 48 insertions(+), 19 deletions(-) diff --git a/.circleci/config_continue.yml b/.circleci/config_continue.yml index 67589d228..2fc5e3baa 100644 --- a/.circleci/config_continue.yml +++ b/.circleci/config_continue.yml @@ -56,6 +56,8 @@ jobs: - run: update-alternatives --install "/usr/bin/java" "java" "/usr/java/jdk-15.0.1/bin/java" 2 - run: update-alternatives --install "/usr/bin/javac" "javac" "/usr/java/jdk-15.0.1/bin/javac" 2 - run: (cd .circleci/ && ./doUnitTests.sh << parameters.cdi-version >>) + - store_test_results: + path: ~/test_report/free-core-junit.xml - slack/status test-backend-sdk-testing: docker: @@ -75,6 +77,8 @@ jobs: - run: update-alternatives --install "/usr/bin/java" "java" "/usr/java/jdk-15.0.1/bin/java" 2 - run: update-alternatives --install "/usr/bin/javac" "javac" "/usr/java/jdk-15.0.1/bin/javac" 2 - run: (cd .circleci/ && ./doBackendSDKTests.sh << parameters.cdi-version >> << parameters.fdi-version >>) + - store_test_results: + path: ~/backend-sdk-testing/test-results/junit.xml - slack/status test-website: docker: @@ -94,6 +98,8 @@ jobs: - run: update-alternatives --install "/usr/bin/java" "java" "/usr/java/jdk-15.0.1/bin/java" 2 - run: update-alternatives --install "/usr/bin/javac" "javac" "/usr/java/jdk-15.0.1/bin/javac" 2 - run: (cd .circleci/ && ./website.sh << parameters.fdi-version >>) + - store_test_results: + path: ~/test_report/website-junit.xml - slack/status test-authreact: docker: @@ -103,8 +109,6 @@ jobs: parameters: fdi-version: type: string - environment: - MOCHA_FILE: ~/test_report/report_node-<< parameters.fdi-version >>.xml parallelism: 4 steps: - checkout @@ -125,7 +129,7 @@ jobs: path: ~/test_report/react-logs destination: react-logs - store_test_results: - path: ~/test_report/report_node-<< parameters.fdi-version >>.xml + path: ~/test_report/auth-react-junit.xml - slack/status test-success: docker: diff --git a/.circleci/setupAndTestBackendSDKWithFreeCore.sh b/.circleci/setupAndTestBackendSDKWithFreeCore.sh index 0870c659a..04f6dcc97 100755 --- a/.circleci/setupAndTestBackendSDKWithFreeCore.sh +++ b/.circleci/setupAndTestBackendSDKWithFreeCore.sh @@ -105,13 +105,20 @@ git clone git@github.com:supertokens/backend-sdk-testing.git cd backend-sdk-testing git checkout $frontendDriverVersion npm install +npm i mocha-multi mocha-junit-reporter npm run build -if ! [[ -z "${CIRCLE_NODE_TOTAL}" ]]; then - API_PORT=$API_PORT TEST_MODE=testing SUPERTOKENS_CORE_TAG=$coreTag NODE_PORT=8081 INSTALL_PATH=../supertokens-root npx mocha --node-option no-experimental-fetch -r test/fetch-polyfill.mjs --no-config --timeout 500000 $(npx mocha-split-tests -r ./runtime.log -t $CIRCLE_NODE_TOTAL -g $CIRCLE_NODE_INDEX -f 'test/**/*.test.js') -else - API_PORT=$API_PORT TEST_MODE=testing SUPERTOKENS_CORE_TAG=$coreTag NODE_PORT=8081 INSTALL_PATH=../supertokens-root npm test -fi +export API_PORT=$API_PORT +export TEST_MODE=testing +export SUPERTOKENS_CORE_TAG=$coreTag +export NODE_PORT=8081 +export INSTALL_PATH=../supertokens-root +export MOCHA_FILE=test-results/junit.xml +export multi="spec=- mocha-junit-reporter=$MOCHA_FILE" + +mkdir -p test-results +TEST_FILES=$(circleci tests glob "test/**/*.test.js") +echo "$TEST_FILES" | circleci tests run --command="xargs npx mocha mocha --reporter mocha-multi --node-option no-experimental-fetch -r test/fetch-polyfill.mjs --timeout 500000 --no-config" --verbose --split-by=timings # kill test-server kill $(lsof -t -i:$API_PORT) diff --git a/.circleci/setupAndTestWithAuthReact.sh b/.circleci/setupAndTestWithAuthReact.sh index 2514c8aee..08ef188d5 100755 --- a/.circleci/setupAndTestWithAuthReact.sh +++ b/.circleci/setupAndTestWithAuthReact.sh @@ -159,8 +159,14 @@ done sleep 2 # Because the server is responding does not mean the app is ready. Let's wait another 2secs to make sure the app is up. echo "Start mocha testing" +export MOCHA_FILE=~/test_report/auth-react-junit.xml +export multi="spec=- mocha-junit-reporter=$MOCHA_FILE" +export TEST_MODE=testing +export APP_SERVER=$apiPort +export SCREENSHOT_ROOT=~/test_report/screenshots + export SPEC_FILES=$(circleci tests glob 'test/end-to-end/**/*.test.js' 'test/unit/**/*.test.js') -echo $SPEC_FILES | SCREENSHOT_ROOT=~/test_report/screenshots APP_SERVER=$apiPort TEST_MODE=testing multi="spec=- mocha-junit-reporter=/dev/null" circleci tests run --command="xargs npx mocha mocha --reporter mocha-multi --require @babel/register --require test/test.mocha.env --timeout 40000 --no-config" --verbose --split-by=timings +echo $SPEC_FILES | circleci tests run --command="xargs npx mocha mocha --reporter mocha-multi --require @babel/register --require test/test.mocha.env --timeout 40000 --no-config" --verbose --split-by=timings testPassed=$?; cp ../supertokens-root/logs/error.log ~/test_report/logs/core_error.log diff --git a/.circleci/setupAndTestWithFreeCore.sh b/.circleci/setupAndTestWithFreeCore.sh index 100d4ae92..92e11b009 100755 --- a/.circleci/setupAndTestWithFreeCore.sh +++ b/.circleci/setupAndTestWithFreeCore.sh @@ -60,6 +60,7 @@ then fi echo "Testing with FREE core: $coreVersion, plugin-interface: $pluginInterfaceVersion" +mkdir -p ~/test_report cd ../../ git clone git@github.com:supertokens/supertokens-root.git cd supertokens-root @@ -84,12 +85,17 @@ cd ../ echo $SUPERTOKENS_API_KEY > apiPassword ./utils/setupTestEnvLocal cd ../project/ +npm i mocha-multi mocha-junit-reporter # Set the script to exit on error set -e -if ! [[ -z "${CIRCLE_NODE_TOTAL}" ]]; then - TEST_MODE=testing SUPERTOKENS_CORE_TAG=$coreTag NODE_PORT=8081 INSTALL_PATH=../supertokens-root npx mocha --node-option no-experimental-fetch -r test/fetch-polyfill.mjs --no-config --timeout 500000 $(npx mocha-split-tests -r ./runtime.log -t $CIRCLE_NODE_TOTAL -g $CIRCLE_NODE_INDEX -f 'test/**/*.test.js') -else - TEST_MODE=testing SUPERTOKENS_CORE_TAG=$coreTag NODE_PORT=8081 INSTALL_PATH=../supertokens-root npm test -fi +export TEST_MODE=testing +export SUPERTOKENS_CORE_TAG=$coreTag +export NODE_PORT=8081 +export INSTALL_PATH=../supertokens-root +export MOCHA_FILE=~/test_report/free-core-junit.xml +export multi="spec=- mocha-junit-reporter=$MOCHA_FILE" + +TEST_FILES=$(circleci tests glob "test/**/*.test.js") +echo "$TEST_FILES" | circleci tests run --command="xargs npx mocha mocha --reporter mocha-multi --node-option no-experimental-fetch --timeout 40000 --no-config" --verbose --split-by=timings diff --git a/.circleci/setupAndTestWithFrontend.sh b/.circleci/setupAndTestWithFrontend.sh index 937faf787..358138785 100755 --- a/.circleci/setupAndTestWithFrontend.sh +++ b/.circleci/setupAndTestWithFrontend.sh @@ -61,6 +61,8 @@ fi echo "Testing with frontend website: $2, FREE core: $coreVersion, plugin-interface: $pluginInterfaceVersion" +mkdir -p ~/test_report + cd ../../ git clone git@github.com:supertokens/supertokens-root.git cd supertokens-root @@ -96,11 +98,15 @@ npm i cd ../../ npm i -d -if ! [[ -z "${CIRCLE_NODE_TOTAL}" ]]; then - TEST_MODE=testing SUPERTOKENS_CORE_TAG=$coreTag NODE_PORT=8081 INSTALL_PATH=../supertokens-root npx mocha --exit --no-config --require isomorphic-fetch --timeout 500000 $(npx mocha-split-tests -r ./runtime.log -t $CIRCLE_NODE_TOTAL -g $CIRCLE_NODE_INDEX -f 'test/*.test.js') -else - TEST_MODE=testing SUPERTOKENS_CORE_TAG=$coreTag NODE_PORT=8081 INSTALL_PATH=../supertokens-root npm test -fi +export TEST_MODE=testing +export SUPERTOKENS_CORE_TAG=$coreTag +export NODE_PORT=8081 +export INSTALL_PATH=../supertokens-root +export MOCHA_FILE=~/test_report/website-junit.xml +export multi="spec=- mocha-junit-reporter=$MOCHA_FILE" + +TEST_FILES=$(circleci tests glob "test/*.test.js") +echo "$TEST_FILES" | circleci tests run --command="xargs npx mocha npx mocha --exit --reporter mocha-multi --no-config --require isomorphic-fetch --timeout 500000" --verbose --split-by=timings if [[ $? -ne 0 ]] then