diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS deleted file mode 100644 index 9e31981..0000000 --- a/.github/CODEOWNERS +++ /dev/null @@ -1 +0,0 @@ -* @splitio/sdk diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md deleted file mode 100644 index 6e9fc04..0000000 --- a/.github/pull_request_template.md +++ /dev/null @@ -1,7 +0,0 @@ -# JavaScript Browser SDK - -## What did you accomplish? - -## How do we test the changes introduced in this PR? - -## Extra Notes diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml deleted file mode 100644 index 57b1865..0000000 --- a/.github/workflows/ci-cd.yml +++ /dev/null @@ -1,142 +0,0 @@ -name: ci-cd -on: - pull_request: - branches: - - main - - development - push: - branches: - - '*' - -env: - PUPPETEER_SKIP_DOWNLOAD: 'true' - -concurrency: - group: ${{ github.workflow }}-${{ github.event_name == 'push' && github.run_number || github.event.pull_request.number }} - cancel-in-progress: true - -permissions: - contents: read - id-token: write - -jobs: - build: - name: Build - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v5 - - - name: Setup Node.js - uses: actions/setup-node@v6 - with: - node-version: 'lts/*' - cache: 'npm' - - - name: npm ci - run: npm ci - - - name: Setup Chrome - uses: browser-actions/setup-chrome@19ae4b339ee18925ab85cf12c1041150ea4a44c8 # v1 - with: - chrome-version: '125' - - name: Set CHROME_BIN - run: echo "CHROME_BIN=$(which chrome)" >> $GITHUB_ENV - - - name: npm test-ts-decls - run: npm run test-ts-decls - - - name: npm check - run: npm run check - - - name: npm test - run: npm run test - - - name: npm build - run: BUILD_BRANCH=$(echo "${GITHUB_REF#refs/heads/}") npm run build - - - name: Store assets - if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/development' || github.ref == 'refs/heads/main') }} - uses: actions/upload-artifact@v5 - with: - name: assets - path: umd/ - retention-days: 1 - - upload-stage: - name: Upload assets - runs-on: ubuntu-latest - needs: build - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/development' }} - strategy: - matrix: - environment: - - stage - include: - - environment: stage - account_id: "079419646996" - bucket: split-public-stage - - steps: - - name: Download assets - uses: actions/download-artifact@v6 - with: - name: assets - path: umd - - - name: Display structure of assets - run: ls -R - working-directory: umd - - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v4 - with: - role-to-assume: arn:aws:iam::${{ matrix.account_id }}:role/gha-public-assets-role - aws-region: us-east-1 - - - name: Upload to S3 - run: aws s3 sync $SOURCE_DIR s3://$BUCKET/$DEST_DIR $ARGS - env: - BUCKET: ${{ matrix.bucket }} - SOURCE_DIR: ./umd - DEST_DIR: sdk - ARGS: --acl public-read --follow-symlinks --cache-control max-age=31536000,public - - upload-prod: - name: Upload assets - runs-on: ubuntu-latest - needs: build - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} - strategy: - matrix: - environment: - - prod - include: - - environment: prod - account_id: "825951051969" - bucket: split-public - - steps: - - name: Download assets - uses: actions/download-artifact@v6 - with: - name: assets - path: umd - - - name: Display structure of assets - run: ls -R - working-directory: umd - - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v4 - with: - role-to-assume: arn:aws:iam::${{ matrix.account_id }}:role/gha-public-assets-role - aws-region: us-east-1 - - - name: Upload to S3 - run: aws s3 sync $SOURCE_DIR s3://$BUCKET/$DEST_DIR $ARGS - env: - BUCKET: ${{ matrix.bucket }} - SOURCE_DIR: ./umd - DEST_DIR: sdk - ARGS: --acl public-read --follow-symlinks --cache-control max-age=31536000,public diff --git a/.github/workflows/sonar-scan.yml b/.github/workflows/sonar-scan.yml deleted file mode 100644 index a81b328..0000000 --- a/.github/workflows/sonar-scan.yml +++ /dev/null @@ -1,66 +0,0 @@ -name: sonar-scan -on: - pull_request: - branches: - - main - - development - push: - branches: - - main - - development - -jobs: - build: - name: Build - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v5 - with: - fetch-depth: 0 - - - name: Set up Node.js - uses: actions/setup-node@v6 - with: - node-version: 'lts/*' - cache: 'npm' - - - name: npm CI - run: npm ci - - - name: npm Check - run: npm run check - - - name: npm Build - run: BUILD_BRANCH=$(echo "${GITHUB_REF#refs/heads/}") npm run build - - - name: SonarQube Scan (Push) - if: github.event_name == 'push' - uses: SonarSource/sonarqube-scan-action@v6 - env: - SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }} - with: - projectBaseDir: . - args: > - -Dsonar.host.url=${{ secrets.SONARQUBE_HOST }} - -Dsonar.projectName=${{ github.event.repository.name }} - -Dsonar.projectKey=${{ github.event.repository.name }} - -Dsonar.links.ci="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/splitio/${{ github.event.repository.name }}/actions" - -Dsonar.links.scm="/splitio/${{ github.event.repository.name }}" - - - name: SonarQube Scan (Pull Request) - if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository - uses: SonarSource/sonarqube-scan-action@v6 - env: - SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }} - with: - projectBaseDir: . - args: > - -Dsonar.host.url=${{ secrets.SONARQUBE_HOST }} - -Dsonar.projectName=${{ github.event.repository.name }} - -Dsonar.projectKey=${{ github.event.repository.name }} - -Dsonar.links.ci="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/splitio/${{ github.event.repository.name }}/actions" - -Dsonar.links.scm="/splitio/${{ github.event.repository.name }}" - -Dsonar.pullrequest.key=${{ github.event.pull_request.number }} - -Dsonar.pullrequest.branch=${{ github.event.pull_request.head.ref }} - -Dsonar.pullrequest.base=${{ github.event.pull_request.base.ref }} diff --git a/.github/workflows/update-notice-year.yml b/.github/workflows/update-notice-year.yml deleted file mode 100644 index 440dacb..0000000 --- a/.github/workflows/update-notice-year.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: Update Notice Year - -on: - schedule: - - cron: "0 3 1 1 *" # 03:00 AM on January 1 - -permissions: - contents: write - pull-requests: write - -jobs: - test: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Set Current year - run: "echo CURRENT=$(date +%Y) >> $GITHUB_ENV" - - - name: Set Previous Year - run: "echo PREVIOUS=$(($CURRENT-1)) >> $GITHUB_ENV" - - - name: Update NOTICE - uses: jacobtomlinson/gha-find-replace@v3 - with: - find: ${{ env.PREVIOUS }} - replace: ${{ env.CURRENT }} - include: "NOTICE" - regex: false - - - name: Commit files - run: | - git config user.name 'github-actions[bot]' - git config user.email 'github-actions[bot]@users.noreply.github.com' - git commit -m "Updated Notice Year" -a - - - name: Create Pull Request - uses: peter-evans/create-pull-request@v5 - with: - token: ${{ secrets.GITHUB_TOKEN }} - title: Update Notice Year - branch: update-notice diff --git a/.harness/orgs/PROD/projects/Harness_Split/pipelines/javascript_browser_client_ci.yaml b/.harness/orgs/PROD/projects/Harness_Split/pipelines/javascript_browser_client_ci.yaml new file mode 100644 index 0000000..3bd06fb --- /dev/null +++ b/.harness/orgs/PROD/projects/Harness_Split/pipelines/javascript_browser_client_ci.yaml @@ -0,0 +1,127 @@ +pipeline: + name: javascript-browser-client-ci + identifier: javascript_browser_client_ci + projectIdentifier: Harness_Split + orgIdentifier: PROD + tags: {} + properties: + ci: + codebase: + connectorRef: fmegithubharnessgitops + repoName: javascript-browser-client + build: <+input> + stages: + - stage: + name: Check-Test-Build-Upload + identifier: Check_Test_Build_Upload + description: "" + type: CI + spec: + cloneCodebase: true + caching: + enabled: true + override: true + paths: [] + buildIntelligence: + enabled: false + execution: + steps: + - step: + type: Run + name: npm ci + identifier: npm_ci + spec: + connectorRef: dockerhub + image: node:lts + shell: Bash + command: npm ci + envVariables: + PUPPETEER_SKIP_DOWNLOAD: "true" + - step: + type: Run + name: npm run test-ts-decls + identifier: npm_run_test_ts_decls + spec: + connectorRef: dockerhub + image: node:lts + shell: Bash + command: npm run test-ts-decls + resources: + limits: + memory: 2Gi + cpu: "1" + - step: + type: Run + name: npm run check + identifier: npm_run_check + spec: + connectorRef: dockerhub + image: node:lts + shell: Bash + command: npm run check + - step: + type: Run + name: npm run test + identifier: npm_run_test + spec: + connectorRef: dockerhub + image: node:lts + shell: Bash + command: |- + apt-get update -qq && apt-get install -y -qq chromium + export CHROME_BIN=$(command -v chromium) + "$CHROME_BIN" --version + npm run test + resources: + limits: + memory: 8Gi + cpu: "4" + - step: + type: Run + name: npm run build + identifier: npm_run_build + spec: + connectorRef: dockerhub + image: node:lts + shell: Bash + command: BUILD_BRANCH=<+codebase.branch> npm run build + - parallel: + - step: + type: Run + name: upload dev assets to CDN + identifier: upload_dev_assets_to_CDN + spec: + connectorRef: dockerhub + image: amazon/aws-cli:2.31.5 + shell: Bash + command: aws s3 sync ./umd s3://split-public-stage/sdk --acl public-read --follow-symlinks --cache-control max-age=31536000,public + envVariables: + AWS_DEFAULT_REGION: us-east-1 + when: + stageStatus: Success + condition: <+trigger.event> == "PUSH" && <+trigger.branch> == "development" + - step: + type: Run + name: upload prod assets to CDN + identifier: upload_prod_assets_to_CDN + spec: + connectorRef: dockerhub + image: amazon/aws-cli:2.31.5 + shell: Bash + command: aws s3 sync ./umd s3://split-public/sdk --acl public-read --follow-symlinks --cache-control max-age=31536000,public + envVariables: + AWS_DEFAULT_REGION: us-east-1 + when: + stageStatus: Success + condition: <+trigger.event> == "PUSH" && <+trigger.branch> == "main" + infrastructure: + type: KubernetesDirect + spec: + connectorRef: "<+codebase.branch == \"main\" ? \"use1prod1cd\" : \"use1stage1cd\">" + namespace: harness-delegate + serviceAccountName: "<+codebase.branch == \"main\" ? \"use1-prod-1-public-assets\" : \"use1-stage-1-public-assets\">" + automountServiceAccountToken: false + nodeSelector: {} + os: Linux + delegateSelectors: + - "<+codebase.branch == \"main\" ? \"use1-prod-1-cd\" : \"use1-stage-1-cd\">" diff --git a/.harness/orgs/PROD/projects/Harness_Split/pipelines/javascript_browser_client_ci/input_sets/javascript_browser_client_ci_pr.yaml b/.harness/orgs/PROD/projects/Harness_Split/pipelines/javascript_browser_client_ci/input_sets/javascript_browser_client_ci_pr.yaml new file mode 100644 index 0000000..1b15ab7 --- /dev/null +++ b/.harness/orgs/PROD/projects/Harness_Split/pipelines/javascript_browser_client_ci/input_sets/javascript_browser_client_ci_pr.yaml @@ -0,0 +1,14 @@ +inputSet: + identifier: javascript_browser_client_ci_pr + name: javascript_browser_client_ci_pr + orgIdentifier: PROD + projectIdentifier: Harness_Split + pipeline: + identifier: javascript_browser_client_ci + properties: + ci: + codebase: + build: + type: PR + spec: + number: <+trigger.prNumber> diff --git a/.harness/orgs/PROD/projects/Harness_Split/pipelines/javascript_browser_client_ci/input_sets/javascript_browser_client_ci_push.yaml b/.harness/orgs/PROD/projects/Harness_Split/pipelines/javascript_browser_client_ci/input_sets/javascript_browser_client_ci_push.yaml new file mode 100644 index 0000000..aa02abe --- /dev/null +++ b/.harness/orgs/PROD/projects/Harness_Split/pipelines/javascript_browser_client_ci/input_sets/javascript_browser_client_ci_push.yaml @@ -0,0 +1,14 @@ +inputSet: + identifier: javascript_browser_client_ci_push + name: javascript_browser_client_ci_push + orgIdentifier: PROD + projectIdentifier: Harness_Split + pipeline: + identifier: javascript_browser_client_ci + properties: + ci: + codebase: + build: + type: branch + spec: + branch: <+trigger.branch> diff --git a/package-lock.json b/package-lock.json index 2802921..f1d93c4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@splitsoftware/splitio-browserjs", - "version": "1.7.1", + "version": "1.7.1-rc.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@splitsoftware/splitio-browserjs", - "version": "1.7.1", + "version": "1.7.1-rc.1", "license": "Apache-2.0", "dependencies": { "@splitsoftware/splitio-commons": "2.12.1", @@ -617,9 +617,9 @@ } }, "node_modules/@istanbuljs/load-nyc-config/node_modules/js-yaml": { - "version": "3.14.2", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.2.tgz", - "integrity": "sha512-PMSmkqxr106Xa156c2M265Z+FTrPl+oxd/rgOQy2tijQeK5TxQ43psO1ZCwhVOSdnn+RzkzlRz/eY4BgJBYVpg==", + "version": "3.15.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.15.1.tgz", + "integrity": "sha512-S99WuO3HlhO3XN41EtYUNl9zzXjoJx7QvmipxsJVxtCBT0YHEFy+iOJhjSvrmV12nYhWpZaM8lPHkJm0yUMbag==", "dev": true, "license": "MIT", "dependencies": { @@ -2186,9 +2186,9 @@ } }, "node_modules/brace-expansion": { - "version": "1.1.15", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.15.tgz", - "integrity": "sha512-EwOCDEex4quD37XhqM3omwtMoJjr//isUZz1JopUNWms+4Z2ViyM/k1YIRePpoVNnQhENnxtFjLaxNHrT7xIUg==", + "version": "1.1.18", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.18.tgz", + "integrity": "sha512-Edep/X9fGqVNmzKBVsDYIOtD+z1tuezV70LBjdCst9Tqu76lsnvRiZ6oTic1n+/BIwX6QDGAO94PN4N2SADvtw==", "dev": true, "license": "MIT", "dependencies": { @@ -3921,9 +3921,9 @@ "dev": true }, "node_modules/glob/node_modules/brace-expansion": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.1.1.tgz", - "integrity": "sha512-WR1cURNjuvBLMZBMbqM0UoE+WAfdUcEV1ccD8PVBVOI+Z3ND4+SZbN8RsfT2bMuG1qwz5RFvPukSZm5fF2D5eA==", + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.1.4.tgz", + "integrity": "sha512-hGfVzPxthbf3+2yjg/RBs60cB0FhqBS/zvdV/4wn4/BmN0bNMMHPc4V/BbFieqf1TKAGGAHnY4eSjajCl0f2Xg==", "dev": true, "license": "MIT", "dependencies": { @@ -5422,9 +5422,9 @@ "license": "MIT" }, "node_modules/js-yaml": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.2.0.tgz", - "integrity": "sha512-ePWsvanv0DWuDRsW8dnt+R4jQ31SCRCQ7hhNcPXZPsoBZiemuZNYGf7adZdqX2D86j6rvKp3RpCxVTSb8WQlOw==", + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.3.1.tgz", + "integrity": "sha512-CY6crGq313MX8GkwvB7tzgp99vjQxY1++5y10/BKN/GUfHqWaOGQMNZkBvqSzsZKWk/ijwHlWzzkLulsGHhjWQ==", "dev": true, "funding": [ { @@ -8930,9 +8930,9 @@ } }, "js-yaml": { - "version": "3.14.2", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.2.tgz", - "integrity": "sha512-PMSmkqxr106Xa156c2M265Z+FTrPl+oxd/rgOQy2tijQeK5TxQ43psO1ZCwhVOSdnn+RzkzlRz/eY4BgJBYVpg==", + "version": "3.15.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.15.1.tgz", + "integrity": "sha512-S99WuO3HlhO3XN41EtYUNl9zzXjoJx7QvmipxsJVxtCBT0YHEFy+iOJhjSvrmV12nYhWpZaM8lPHkJm0yUMbag==", "dev": true, "requires": { "argparse": "^1.0.7", @@ -10107,9 +10107,9 @@ } }, "brace-expansion": { - "version": "1.1.15", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.15.tgz", - "integrity": "sha512-EwOCDEex4quD37XhqM3omwtMoJjr//isUZz1JopUNWms+4Z2ViyM/k1YIRePpoVNnQhENnxtFjLaxNHrT7xIUg==", + "version": "1.1.18", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.18.tgz", + "integrity": "sha512-Edep/X9fGqVNmzKBVsDYIOtD+z1tuezV70LBjdCst9Tqu76lsnvRiZ6oTic1n+/BIwX6QDGAO94PN4N2SADvtw==", "dev": true, "requires": { "balanced-match": "^1.0.0", @@ -11364,9 +11364,9 @@ }, "dependencies": { "brace-expansion": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.1.1.tgz", - "integrity": "sha512-WR1cURNjuvBLMZBMbqM0UoE+WAfdUcEV1ccD8PVBVOI+Z3ND4+SZbN8RsfT2bMuG1qwz5RFvPukSZm5fF2D5eA==", + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.1.4.tgz", + "integrity": "sha512-hGfVzPxthbf3+2yjg/RBs60cB0FhqBS/zvdV/4wn4/BmN0bNMMHPc4V/BbFieqf1TKAGGAHnY4eSjajCl0f2Xg==", "dev": true, "requires": { "balanced-match": "^1.0.0" @@ -12481,9 +12481,9 @@ "dev": true }, "js-yaml": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.2.0.tgz", - "integrity": "sha512-ePWsvanv0DWuDRsW8dnt+R4jQ31SCRCQ7hhNcPXZPsoBZiemuZNYGf7adZdqX2D86j6rvKp3RpCxVTSb8WQlOw==", + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.3.1.tgz", + "integrity": "sha512-CY6crGq313MX8GkwvB7tzgp99vjQxY1++5y10/BKN/GUfHqWaOGQMNZkBvqSzsZKWk/ijwHlWzzkLulsGHhjWQ==", "dev": true, "requires": { "argparse": "^2.0.1" diff --git a/package.json b/package.json index c27ff75..3c7d291 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@splitsoftware/splitio-browserjs", - "version": "1.7.1", + "version": "1.7.1-rc.1", "description": "Split SDK for JavaScript on Browser", "main": "cjs/index.js", "module": "esm/index.js", diff --git a/src/__tests__/offline/browser.spec.js b/src/__tests__/offline/browser.spec.js index f0f6b3f..f9213ce 100644 --- a/src/__tests__/offline/browser.spec.js +++ b/src/__tests__/offline/browser.spec.js @@ -24,6 +24,19 @@ const replySpy = spy => { return 200; }; +// polls `condition` until it's true or `timeout` ms elapse, instead of a fixed wait, to avoid flakiness under CI load +const waitUntil = (condition, timeout = 10000, interval = 1000) => { + const start = Date.now(); + return new Promise((resolve, reject) => { + const check = () => { + if (condition()) return resolve(); + if (Date.now() - start >= timeout) return reject(new Error('waitUntil timed out')); + setTimeout(check, interval); + }; + check(); + }); +}; + const configMocks = () => { fetchMock.mock(new RegExp(`${url(settings, '/splitChanges/')}.*`), () => replySpy(spySplitChanges)); fetchMock.mock(new RegExp(`${url(settings, '/segmentChanges/')}.*`), () => replySpy(spySegmentChanges)); @@ -255,7 +268,7 @@ tape('Browser offline mode', function (assert) { setTimeout(() => { factory.settings.features = { testing_split: 'on', testing_split_with_config: { treatment: 'off', config: '{ "color": "blue" }' } }; }, 750); // once updated, test again. - client.once(client.Event.SDK_UPDATE, function (metadata) { + client.once(client.Event.SDK_UPDATE, async (metadata) => { assert.true((Date.now() - readyTimestamp) > 1000, 'Should only emit SDK_UPDATE after a real update.'); assert.true(metadata != null && typeof metadata.type === 'string' && ['FLAGS_UPDATE', 'SEGMENTS_UPDATE'].includes(metadata.type), 'SDK_UPDATE must receive SdkUpdateMetadata with type'); assert.true(Array.isArray(metadata.names), 'SDK_UPDATE must receive SdkUpdateMetadata with names array'); @@ -334,38 +347,42 @@ tape('Browser offline mode', function (assert) { testing_not_exist: { treatment: 'control', config: null } }); - // timeout to wait SDK_UPDATE on all factories - setTimeout(() => { - const destroyPromises = [ - sharedClient.destroy(), client.destroy(), - ...factories.map(f => f.client().destroy()) - ]; - - // When both promises have been resolved, we check for network activity - Promise.all(destroyPromises).then(() => { - // We test the breakdown instead of just the misc because it's faster to spot where the issue is - assert.notOk(spySplitChanges.called, 'On offline mode we should not call the splitChanges endpoint.'); - assert.notOk(spySegmentChanges.called, 'On offline mode we should not call the segmentChanges endpoint.'); - assert.notOk(spyMemberships.called, 'On offline mode we should not call the memberships endpoint.'); - assert.notOk(spyEventsBulk.called, 'On offline mode we should not call the events endpoint.'); - assert.notOk(spyTestImpressionsBulk.called, 'On offline mode we should not call the impressions endpoint.'); - assert.notOk(spyTestImpressionsCount.called, 'On offline mode we should not call the impressions count endpoint.'); - assert.notOk(spyMetricsTimes.called, 'On offline mode we should not call the metric times endpoint.'); - assert.notOk(spyMetricsCounters.called, 'On offline mode we should not call the metric counters endpoint.'); - assert.notOk(spyAny.called, 'On offline mode we should NOT call to ANY endpoint, we are completely isolated from BE.'); - - // SDK events on shared client - assert.equal(sharedReadyCount, 1, 'Shared client should have emitted SDK_READY event once'); - assert.equal(sharedUpdateCount, 1, 'Shared client should have emitted SDK_UPDATE event once'); - - // SDK events on other factory clients - assert.equal(readyCount, factories.length, 'Each factory client should have emitted SDK_READY event once'); - assert.equal(updateCount, factories.length - 1, 'Each factory client except one should have emitted SDK_UPDATE event once'); - assert.equal(readyFromCacheCount, 2, 'The main and shared client of the factory with LOCALSTORAGE should have emitted SDK_READY_FROM_CACHE event'); - - assert.end(); - }); - }); - }, 3500); + // wait for SDK_UPDATE on all factories + try { + await waitUntil(() => updateCount === factories.length - 1); + } catch (err) { + assert.fail(err.message); + assert.end(); + } + + const destroyPromises = [ + sharedClient.destroy(), client.destroy(), + ...factories.map(f => f.client().destroy()) + ]; + + // When both promises have been resolved, we check for network activity + await Promise.all(destroyPromises); + // We test the breakdown instead of just the misc because it's faster to spot where the issue is + assert.notOk(spySplitChanges.called, 'On offline mode we should not call the splitChanges endpoint.'); + assert.notOk(spySegmentChanges.called, 'On offline mode we should not call the segmentChanges endpoint.'); + assert.notOk(spyMemberships.called, 'On offline mode we should not call the memberships endpoint.'); + assert.notOk(spyEventsBulk.called, 'On offline mode we should not call the events endpoint.'); + assert.notOk(spyTestImpressionsBulk.called, 'On offline mode we should not call the impressions endpoint.'); + assert.notOk(spyTestImpressionsCount.called, 'On offline mode we should not call the impressions count endpoint.'); + assert.notOk(spyMetricsTimes.called, 'On offline mode we should not call the metric times endpoint.'); + assert.notOk(spyMetricsCounters.called, 'On offline mode we should not call the metric counters endpoint.'); + assert.notOk(spyAny.called, 'On offline mode we should NOT call to ANY endpoint, we are completely isolated from BE.'); + + // SDK events on shared client + assert.equal(sharedReadyCount, 1, 'Shared client should have emitted SDK_READY event once'); + assert.equal(sharedUpdateCount, 1, 'Shared client should have emitted SDK_UPDATE event once'); + + // SDK events on other factory clients + assert.equal(readyCount, factories.length, 'Each factory client should have emitted SDK_READY event once'); + assert.equal(updateCount, factories.length - 1, 'Each factory client except one should have emitted SDK_UPDATE event once'); + assert.equal(readyFromCacheCount, 2, 'The main and shared client of the factory with LOCALSTORAGE should have emitted SDK_READY_FROM_CACHE event'); + + assert.end(); + }); }); }); diff --git a/src/settings/defaults.ts b/src/settings/defaults.ts index d8ae1f1..eff20be 100644 --- a/src/settings/defaults.ts +++ b/src/settings/defaults.ts @@ -2,7 +2,7 @@ import type SplitIO from '@splitsoftware/splitio-commons/types/splitio'; import { LogLevels, isLogLevelString } from '@splitsoftware/splitio-commons/src/logger/index'; import { CONSENT_GRANTED } from '@splitsoftware/splitio-commons/src/utils/constants'; -const packageVersion = '1.7.1'; +const packageVersion = '1.7.1-rc.1'; /** * In browser, the default debug level, can be set via the `localStorage.splitio_debug` item.