From b9a75a26abc7242e41ea8aa623da814ecb4677e5 Mon Sep 17 00:00:00 2001 From: Ben Teichman Date: Tue, 12 Nov 2024 11:23:52 -0500 Subject: [PATCH] feat: add playwright job (QLT-83) (#308) --- src/executors/node/playwright-executor.yml | 6 ++ src/jobs/e2e/collect-e2e-logs.yml | 24 ++++--- src/jobs/smoke/run-playwright-smoke-tests.yml | 71 +++++++++++++++++++ src/jobs/smoke/run-smoke-tests.yml | 2 +- 4 files changed, 93 insertions(+), 10 deletions(-) create mode 100644 src/executors/node/playwright-executor.yml create mode 100644 src/jobs/smoke/run-playwright-smoke-tests.yml diff --git a/src/executors/node/playwright-executor.yml b/src/executors/node/playwright-executor.yml new file mode 100644 index 00000000..bba723f6 --- /dev/null +++ b/src/executors/node/playwright-executor.yml @@ -0,0 +1,6 @@ +parameters: + playwright-version: + type: string +docker: # run the steps with Docker. + - image: mcr.microsoft.com/playwright:v<< parameters.playwright-version >>-noble +resource_class: xlarge diff --git a/src/jobs/e2e/collect-e2e-logs.yml b/src/jobs/e2e/collect-e2e-logs.yml index d941e160..43cf0ce4 100644 --- a/src/jobs/e2e/collect-e2e-logs.yml +++ b/src/jobs/e2e/collect-e2e-logs.yml @@ -13,9 +13,13 @@ parameters: description: Path to the env_name file default: "/home/circleci/voiceflow/env_name.txt" executor: - description: Executor to run the command on - type: executor - default: default-executor + description: Executor to run the command on + type: executor + default: default-executor + smoke-test-jobs: + description: Comma separated list of smoke test jobs + type: string + default: "vfcommon/run-smoke-tests" executor: << parameters.executor >> steps: - install-vfcli: @@ -78,12 +82,14 @@ steps: capture_logs - run: - name: Wait for smoke-tests job to complete - command: | - # The waiter job keeps looping through to check if the smoke-tests job has been completed - while [[ $(curl --location --request GET "https://circleci.com/api/v2/workflow/$CIRCLE_WORKFLOW_ID/job" --header "Circle-Token: $CIRCLE_TOKEN"| jq -r '.items[]|select(.name == "vfcommon/run-smoke-tests")|.status' | grep -c "running") -gt 0 ]] - do - sleep 5 + name: Wait for smoke test jobs to complete + command: | + # Loop through to check if each of the jobs have been completed + for job in $(echo "<< parameters.smoke-test-jobs >>" | tr "," "\n"); do + while [[ $(curl --location --request GET "https://circleci.com/api/v2/workflow/$CIRCLE_WORKFLOW_ID/job" --header "Circle-Token: $CIRCLE_TOKEN"| jq -r ".items[]|select(.name == \"$job\")|.status" | grep -c "running") -gt 0 ]] + do + sleep 5 + done done - run: echo "All required jobs have now completed" - run: diff --git a/src/jobs/smoke/run-playwright-smoke-tests.yml b/src/jobs/smoke/run-playwright-smoke-tests.yml new file mode 100644 index 00000000..46886e45 --- /dev/null +++ b/src/jobs/smoke/run-playwright-smoke-tests.yml @@ -0,0 +1,71 @@ +executor: + name: playwright-executor + playwright-version: << parameters.playwright-version >> +parallelism: << parameters.parallelism >> + +parameters: + playwright-version: + type: string + default: "1.48.2" + e2e-env-name: + type: string + default: "" + parallelism: + type: integer + default: 1 + target-url: + type: string + default: "" + description: "use this to override the e2e-env-name and set the full creator-app URL" + branch-or-commit: + type: string + default: "master" + description: "the branch or commit of the automated-testing repo to checkout" + smoke-command: + type: string + default: "test:smoke:playwright" + env-name-path: + type: string + description: Path to the env_name file + default: "/home/circleci/voiceflow/env_name.txt" +steps: + - clone_repo: + github_repo_name: automated-testing + github_commit: << parameters.branch-or-commit >> + path_to_clone: ~/project + - install_node_modules: + avoid_post_install_scripts: false + cache_prefix: playwright-smoke-test + - restore_cache: + key: env_name_cache-{{ .Environment.CIRCLE_PROJECT_REPONAME }}-{{ .Environment.CIRCLE_WORKFLOW_ID }} + - run: + name: "Set Environment Variables" + command: | + # env_name.txt is used to store the e2e env name and passed to the smoke tests + # uses e2e-env-name if env_name.txt is 'null' + if [ ! -z "<< parameters.target-url >>" ]; then + echo 'export CREATOR_APP_URL=<< parameters.target-url >>' >> $BASH_ENV + elif [ -f << parameters.env-name-path >> ] && [ "$(cat << parameters.env-name-path >>)" != "null" ]; then + echo 'export CREATOR_APP_URL=https://creator-$(cat << parameters.env-name-path >>).br-2.development.voiceflow.com' >> $BASH_ENV + else + echo 'export CREATOR_APP_URL=https://creator-<< parameters.e2e-env-name >>.br-2.development.voiceflow.com' >> $BASH_ENV + fi + shell: /bin/bash + - run: + name: "Reference commit SHA" + command: git rev-parse HEAD >> commit.txt + - restore_cache: + # use the commit of the smoke-test-runner repo as the cache key + key: playwright-smoke-test-build-cache-{{ checksum "commit.txt" }} + - run: + name: Run Smoke Tests + command: yarn << parameters.smoke-command >> + - save_cache: + key: playwright-smoke-test-build-cache-{{ checksum "commit.txt" }} + paths: + - node_modules/.cache/turbo + - store_test_results: + path: tests/smoke-playwright/e2e.report.xml + - store_artifacts: + path: tests/smoke-playwright/test-results + diff --git a/src/jobs/smoke/run-smoke-tests.yml b/src/jobs/smoke/run-smoke-tests.yml index d2d2bd5d..ee774a35 100644 --- a/src/jobs/smoke/run-smoke-tests.yml +++ b/src/jobs/smoke/run-smoke-tests.yml @@ -33,7 +33,7 @@ steps: path_to_clone: ~/project - install_node_modules: avoid_post_install_scripts: false - cache_prefix: smoke-test + cache_prefix: cypress-smoke-test - restore_cache: key: env_name_cache-{{ .Environment.CIRCLE_PROJECT_REPONAME }}-{{ .Environment.CIRCLE_WORKFLOW_ID }} - run: