forked from segmentio/analytics-next
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into test-branch
- Loading branch information
Showing
279 changed files
with
10,226 additions
and
3,642 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,8 @@ steps: | |
- PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 HUSKY=0 yarn install --immutable | ||
- echo "+++ Run tests" | ||
- yarn constraints | ||
- yarn run test:scripts | ||
- yarn scripts test | ||
- yarn scripts lint | ||
- yarn run test:check-dts | ||
plugins: | ||
- ssh://[email protected]/segmentio/cache-buildkite-plugin#v2.0.0: | ||
|
@@ -98,6 +99,21 @@ steps: | |
key: "v1.1-cache-dev-{{ checksum 'yarn.lock' }}" | ||
paths: ['.yarn/cache/'] | ||
|
||
- label: '[Generic Utils] Lint + Test' | ||
agents: | ||
queue: v1 | ||
commands: | ||
- npm config set "//registry.npmjs.org/:_authToken" $${NPM_TOKEN} | ||
- echo "--- Install dependencies" | ||
- PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 HUSKY=0 yarn install --immutable | ||
- echo "+++ Run QA" | ||
- yarn turbo run --filter=analytics-generic-utils lint | ||
- yarn turbo run --filter=analytics-generic-utils test | ||
plugins: | ||
- ssh://[email protected]/segmentio/cache-buildkite-plugin#v2.0.0: | ||
key: "v1.1-cache-dev-{{ checksum 'yarn.lock' }}" | ||
paths: ['.yarn/cache/'] | ||
|
||
- label: '[Consent] Lint + Test' | ||
agents: | ||
queue: v1 | ||
|
@@ -148,18 +164,18 @@ steps: | |
key: "v1.1-cache-dev-{{ checksum 'yarn.lock' }}" | ||
paths: ['.yarn/cache/'] | ||
|
||
- label: '[Examples] Lint + Test :hammer:' | ||
key: examples | ||
- label: '[Playgrounds] Lint + Test :hammer:' | ||
key: playgrounds | ||
agents: | ||
queue: v1 | ||
commands: | ||
- npm config set "//registry.npmjs.org/:_authToken" $${NPM_TOKEN} | ||
- echo "--- Install dependencies" | ||
- PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 HUSKY=0 yarn install --immutable | ||
- echo "--- Build bundles" | ||
- yarn turbo run --filter='./examples/*' build | ||
- yarn turbo run --filter='./playgrounds/*' build | ||
- echo "+++ Run tests" | ||
- yarn turbo run --filter='./examples/*' lint | ||
- yarn turbo run --filter='./playgrounds/*' lint | ||
plugins: | ||
- ssh://[email protected]/segmentio/cache-buildkite-plugin#v2.0.0: | ||
key: "v1.1-cache-dev-{{ checksum 'yarn.lock' }}" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json", | ||
"ignore": ["@example/*"], | ||
"ignore": ["@playground/*"], | ||
"changelog": [ | ||
"@changesets/changelog-github", | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,4 @@ jobs: | |
run: | | ||
git config --global user.name "Segment Github" | ||
git config --global user.email "[email protected]" | ||
yarn ts-node-script --files scripts/create-release-from-tags/run.ts | ||
yarn scripts create-release-from-tags |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,22 +3,22 @@ | |
"private": true, | ||
"version": "0.0.0", | ||
"workspaces": [ | ||
"examples/*", | ||
"playgrounds/*", | ||
"packages/*", | ||
"packages/consent/*" | ||
"packages/consent/*", | ||
"scripts" | ||
], | ||
"engines": { | ||
"node": "^16.16.0" | ||
}, | ||
"scripts": { | ||
"test": "jest", | ||
"test:scripts": "jest --config scripts/jest.config.js", | ||
"test:check-dts": "yarn build && yarn ts-node meta-tests/check-dts.ts", | ||
"test:node-int": "turbo run --filter=node-integration-tests test", | ||
"lint": "yarn constraints && turbo run lint --continue", | ||
"build": "turbo run build --filter='./packages/**'", | ||
"watch": "turbo run watch --filter='./packages/**'", | ||
"dev": "yarn workspace @example/with-next-js run dev", | ||
"dev": "yarn workspace @playground/next-playground run dev", | ||
"postinstall": "husky install", | ||
"changeset": "changeset", | ||
"update-versions-and-changelogs": "changeset version && yarn version-run-all && bash scripts/update-lockfile.sh", | ||
|
@@ -27,16 +27,17 @@ | |
"core": "yarn workspace @segment/analytics-core", | ||
"browser": "yarn workspace @segment/analytics-next", | ||
"node": "yarn workspace @segment/analytics-node", | ||
"scripts": "yarn workspace @internal/scripts", | ||
"clean": "bash scripts/clean.sh", | ||
"turbo": "turbo" | ||
}, | ||
"packageManager": "[email protected]", | ||
"devDependencies": { | ||
"@changesets/changelog-github": "^0.4.5", | ||
"@changesets/cli": "^2.23.2", | ||
"@npmcli/promise-spawn": "^3.0.0", | ||
"@npmcli/promise-spawn": "^7.0.0", | ||
"@types/express": "4", | ||
"@types/jest": "^28.1.1", | ||
"@types/jest": "^29.5.11", | ||
"@types/lodash": "^4", | ||
"@types/node-fetch": "^2.6.2", | ||
"@typescript-eslint/eslint-plugin": "^5.21.0", | ||
|
@@ -50,15 +51,15 @@ | |
"express": "^4.18.2", | ||
"get-monorepo-packages": "^1.2.0", | ||
"husky": "^8.0.0", | ||
"jest": "^28.1.0", | ||
"jest": "^29.7.0", | ||
"lint-staged": "^13.0.0", | ||
"lodash": "^4.17.21", | ||
"nock": "^13.3.0", | ||
"node-gyp": "^9.0.0", | ||
"prettier": "^2.6.2", | ||
"ts-jest": "^28.0.4", | ||
"ts-jest": "^29.1.1", | ||
"ts-node": "^10.8.0", | ||
"turbo": "^1.3.1", | ||
"turbo": "^1.10.14", | ||
"typescript": "^4.7.0", | ||
"webpack": "^5.76.0", | ||
"webpack-dev-server": "^4.15.1" | ||
|
54 changes: 54 additions & 0 deletions
54
packages/browser-integration-tests/src/custom-global-key.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { test, expect } from '@playwright/test' | ||
import { standaloneMock } from './helpers/standalone-mock' | ||
import { extractWriteKeyFromUrl } from './helpers/extract-writekey' | ||
import { CDNSettingsBuilder } from '@internal/test-helpers' | ||
|
||
test.describe('Segment with custom global key', () => { | ||
test.beforeEach(standaloneMock) | ||
test.beforeEach(async ({ context }) => { | ||
await context.route( | ||
'https://cdn.segment.com/v1/projects/*/settings', | ||
(route, request) => { | ||
if (request.method().toLowerCase() !== 'get') { | ||
return route.continue() | ||
} | ||
|
||
const writeKey = extractWriteKeyFromUrl(request.url()) || 'writeKey' | ||
return route.fulfill({ | ||
status: 200, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(new CDNSettingsBuilder({ writeKey }).build()), | ||
}) | ||
} | ||
) | ||
}) | ||
|
||
test('supports using a custom global key', async ({ page }) => { | ||
// Load analytics.js | ||
await page.goto('/standalone-custom-key.html') | ||
await page.evaluate(() => { | ||
;(window as any).segment_analytics.track('track before load') | ||
;(window as any).segment_analytics.load('fake-key') | ||
}) | ||
|
||
const req = await page.waitForRequest('https://api.segment.io/v1/t') | ||
|
||
// confirm that any events triggered before load have been sent | ||
expect(req.postDataJSON().event).toBe('track before load') | ||
|
||
const contextObj = await page.evaluate(() => | ||
(window as any).segment_analytics.track('track after load') | ||
) | ||
|
||
// confirm that any events triggered after load return a regular context object | ||
expect(contextObj).toMatchObject( | ||
expect.objectContaining({ | ||
attempts: expect.anything(), | ||
event: expect.objectContaining({ event: 'track after load' }), | ||
stats: expect.objectContaining({ metrics: expect.anything() }), | ||
}) | ||
) | ||
}) | ||
}) |
Oops, something went wrong.