From ac69507961d3496246708c10bba9fcc35df34212 Mon Sep 17 00:00:00 2001 From: Justin Dalrymple Date: Wed, 24 Jan 2024 12:51:07 -0500 Subject: [PATCH] CI script reorganization - Updating ci script to use latest shutdown logic - Removed unneeded tests - Split browser tests into ones that need a gl instance those that down - Removing the need to run the full e2e test unless its a release branch - Moved the most tested release tests (the exports) into a integration test since it doesnt require a full gitlab instance for testing --- .gitlab-ci.yml | 65 +++--- .prettierignore | 2 +- .../requester-utils/test/unit/BaseResource.ts | 9 +- packages/rest/package.json | 9 +- packages/rest/playwright.config.mjs | 36 ++- .../{e2e/browser => }/assets/test-import.html | 6 +- .../test/e2e/browser/{index.ts => General.ts} | 2 +- .../test/e2e/browser/resources/Projects.ts | 2 +- .../nodejs/resources/Issues.ts | 0 .../nodejs/resources/Lint.ts | 0 .../nodejs/resources/Projects.ts | 0 .../nodejs/resources/Repositories.ts | 0 .../rest/test/integration/browser/General.ts | 211 ++++++++++++++++++ .../rest/test/integration/nodejs/General.ts | 36 --- scripts/shutdown.sh | 8 - 15 files changed, 292 insertions(+), 94 deletions(-) rename packages/rest/test/{e2e/browser => }/assets/test-import.html (74%) rename packages/rest/test/e2e/browser/{index.ts => General.ts} (98%) rename packages/rest/test/{integration => e2e}/nodejs/resources/Issues.ts (100%) rename packages/rest/test/{integration => e2e}/nodejs/resources/Lint.ts (100%) rename packages/rest/test/{integration => e2e}/nodejs/resources/Projects.ts (100%) rename packages/rest/test/{integration => e2e}/nodejs/resources/Repositories.ts (100%) create mode 100644 packages/rest/test/integration/browser/General.ts delete mode 100644 packages/rest/test/integration/nodejs/General.ts delete mode 100644 scripts/shutdown.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e0af2e02d..b4cc00c1d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -169,8 +169,7 @@ format: - main - next needs: - - install - - test:live:setup + - build .test:e2e:base: extends: .test:integration:base @@ -264,9 +263,9 @@ test:live:setup: when: always - if: $CI_COMMIT_BRANCH == "next" || $CI_COMMIT_BRANCH =~ /^pr-[0-9]+$/ when: manual + allow_failure: true needs: - build - allow_failure: false variables: GITLAB_PERSONAL_ACCESS_TOKEN: gitbeaker CONTAINER_NAME: gitlab-${CI_PIPELINE_ID} @@ -287,8 +286,8 @@ test:live:setup: --container-arg="-c" \ --container-arg="printf '#!/usr/bin/env ruby \nu = User.first \nu.admin = true \nu.save! \nt = PersonalAccessToken.new({ user: u, name: \"gitbeaker\", scopes: [\"api\", \"read_user\"]}) \nt.expires_at = 365.days.from_now \nt.set_token(ENV[\"PERSONAL_ACCESS_TOKEN\"]) \nt.save! \nputs t.token\n' > /opt/gitlab/embedded/service/gitlab-rails/db/fixtures/production/40_access_token.rb && /assets/wrapper" \ --container-env ^~^GITLAB_ROOT_PASSWORD=${GITLAB_ROOT_PASSWORD}~PERSONAL_ACCESS_TOKEN=${GITLAB_PERSONAL_ACCESS_TOKEN}~GITLAB_OMNIBUS_CONFIG="gitlab_rails['monitoring_whitelist'] = ['0.0.0.0/0', '172.17.0.1'];" \ - --metadata SELF_DESTRUCT_INTERVAL_MINUTES=15 \ - --metadata-from-file startup-script=./scripts/shutdown.sh \ + --max-run-duration=25m + --instance-termination-action=DELETE --format='get(networkInterfaces[0].accessConfigs[0].natIP)'\ | head -2 | tail -1 ) @@ -309,10 +308,10 @@ test:live:teardown: stage: test image: gcr.io/google.com/cloudsdktool/cloud-sdk:alpine needs: - - test:integration:rest - test:e2e:core - test:e2e:cli - - test:e2e:rest + - test:e2e:rest:browser + - test:e2e:rest:nodejs when: always only: refs: @@ -327,22 +326,30 @@ test:live:teardown: - gcloud compute instances delete gitlab-${CI_PIPELINE_ID} --zone=northamerica-northeast1-b ## Integration Tests -test:integration:rest: - extends: .test:integration:base - script: yarn test:integration --projects=@gitbeaker/rest +test:integration:rest:browser: + extends: .test:e2e:base + image: mcr.microsoft.com/playwright:v1.40.0-focal + before_script: + # reinstall swc due to missing binding for ubuntu image + - yarn add @swc/core + script: yarn test:integration:browser --projects=@gitbeaker/rest ## End-to-End Tests test:e2e:core: extends: .test:e2e:base script: yarn test:e2e --projects=@gitbeaker/core -test:e2e:rest: +test:e2e:rest:browser: extends: .test:e2e:base image: mcr.microsoft.com/playwright:v1.40.0-focal before_script: # reinstall swc due to missing binding for ubuntu image - yarn add @swc/core - script: yarn test:e2e --projects=@gitbeaker/rest + script: yarn test:e2e:browser --projects=@gitbeaker/rest + +test:e2e:rest:nodejs: + extends: .test:e2e:base + script: yarn test:e2e:nodejs --projects=@gitbeaker/rest test:e2e:cli: extends: .test:e2e:base @@ -374,41 +381,43 @@ release:special: extends: .release:base needs: - build - - test:integration:rest - test:e2e:core - test:e2e:cli - - test:e2e:rest + - test:e2e:rest:browser + - test:e2e:rest:nodejs only: refs: - /^pr-[0-9]+$/ + script: - - echo "Checking for special release..." - - | - if [[ $CI_COMMIT_BRANCH =~ ^pr-[0-9]*$ ]]; then - pr_id="${CI_COMMIT_BRANCH//[!0-9]/}" + - echo 'release' + # - echo "Checking for special release..." + # - | + # if [[ $CI_COMMIT_BRANCH =~ ^pr-[0-9]*$ ]]; then + # pr_id="${CI_COMMIT_BRANCH//[!0-9]/}" - export CI_MERGE_REQUEST_ID=$pr_id - export CI_MERGE_REQUEST_SOURCE_BRANCH_NAME=$CI_COMMIT_BRANCH + # export CI_MERGE_REQUEST_ID=$pr_id + # export CI_MERGE_REQUEST_SOURCE_BRANCH_NAME=$CI_COMMIT_BRANCH - labels=$(yarn auto label --pr $pr_id) + # labels=$(yarn auto label --pr $pr_id) - if [[ "$labels" =~ "release:canary" ]]; then - yarn release:canary - fi - fi + # if [[ "$labels" =~ "release:canary" ]]; then + # yarn release:canary + # fi + # fi ## Production release: extends: .release:base needs: - build - - test:integration:rest - test:e2e:core - test:e2e:cli - - test:e2e:rest + - test:e2e:rest:browser + - test:e2e:rest:nodejs - test:unit:teardown only: refs: - main - next - script: yarn release + script: echo 'release' #yarn release diff --git a/.prettierignore b/.prettierignore index d4c44a089..b94445c33 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,4 +1,4 @@ -.turbo +reports coverage dist package.json diff --git a/packages/requester-utils/test/unit/BaseResource.ts b/packages/requester-utils/test/unit/BaseResource.ts index 29a3b2b94..9ea3e906b 100644 --- a/packages/requester-utils/test/unit/BaseResource.ts +++ b/packages/requester-utils/test/unit/BaseResource.ts @@ -35,10 +35,15 @@ describe('Creation of BaseResource instance', () => { await expect(service.authHeaders.authorization()).resolves.toBe('Bearer 1234'); }); - it('should accept a function oauthToken that returns a promise', async () => { + it('should accept a dynamic oauthToken that returns a promise', async () => { const service = new BaseResource({ requesterFn: jest.fn(), - oauthToken: () => Promise.resolve('1234'), + oauthToken: () => + new Promise((res) => { + setTimeout(() => { + res('1234'); + }, 1000); + }), }); expect(service.authHeaders.authorization).toBeFunction(); diff --git a/packages/rest/package.json b/packages/rest/package.json index b962a38b2..a0aa56c0c 100644 --- a/packages/rest/package.json +++ b/packages/rest/package.json @@ -43,10 +43,11 @@ "scripts": { "build": "tsup src/index.ts --format esm,cjs --dts --treeshake", "test:types": "tsc", - "test:e2e:browser": "playwright test", - "test:e2e": "yarn test:e2e:browser", - "test:integration:nodejs": "jest --maxWorkers=50% test/integration/nodejs/resources/Issues.ts", - "test:integration": "yarn test:integration:nodejs", + "test:e2e:browser": "playwright test --project=e2e", + "test:e2e:nodejs": "jest --maxWorkers=50% test/e2e/nodejs", + "test:e2e": "yarn test:e2e:browser && yarn test:e2e:nodejs", + "test:integration:browser": "playwright test --project=integration", + "test:integration": "test:integration:browser", "test:unit": "jest --maxWorkers=50% test/unit", "format:docs": "prettier '**/(*.json|.yml|.js|.md)' --ignore-path ../../.prettierignore", "format:docs:fix": "yarn format:docs --write", diff --git a/packages/rest/playwright.config.mjs b/packages/rest/playwright.config.mjs index a10b70e1d..ca9b30b28 100644 --- a/packages/rest/playwright.config.mjs +++ b/packages/rest/playwright.config.mjs @@ -1,19 +1,35 @@ import { defineConfig } from '@playwright/test'; +const launchOptions = { + args: [ + '--disable-web-security', + '--allow-file-access-from-files' + ], +} + export default defineConfig({ - use: { - browserName: 'chromium', - launchOptions: { - args: [ - '--disable-web-security', - '--allow-file-access-from-files' - ], - } - }, - testDir: './test/e2e/browser', + testMatch: /.*.ts/, testMatch: /.*.ts/, reporter: [ ['line'], ['junit', { outputFile: './reports/browser_junit.xml' }], ], + projects: [ + { + name: 'e2e', + use: { + browserName: 'chromium', + launchOptions + }, + testDir: './test/e2e/browser', + }, + { + name: 'integration', + use: { + browserName: 'chromium', + launchOptions + }, + testDir: './test/integration/browser', + } + ] }); diff --git a/packages/rest/test/e2e/browser/assets/test-import.html b/packages/rest/test/assets/test-import.html similarity index 74% rename from packages/rest/test/e2e/browser/assets/test-import.html rename to packages/rest/test/assets/test-import.html index d56666290..75b073721 100644 --- a/packages/rest/test/e2e/browser/assets/test-import.html +++ b/packages/rest/test/assets/test-import.html @@ -13,13 +13,13 @@ "xcase": "https://esm.sh/xcase?min", "rate-limiter-flexible": "https://esm.sh/rate-limiter-flexible?min", "picomatch-browser": "https://esm.sh/picomatch-browser?min", - "@gitbeaker/requester-utils": "../../../../../requester-utils/dist/index.mjs", - "@gitbeaker/core": "../../../../../core/dist/index.mjs" + "@gitbeaker/requester-utils": "../../../../requester-utils/dist/index.mjs", + "@gitbeaker/core": "../../../../core/dist/index.mjs" } }