-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
XHR Network signals URL normalization (#1152)
- Loading branch information
Showing
7 changed files
with
166 additions
and
10 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
'@segment/analytics-signals': minor | ||
--- | ||
- normalize XHR URL, http methods, etc |
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 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
63 changes: 63 additions & 0 deletions
63
packages/signals/signals/src/types/__tests__/create-network-signal.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,63 @@ | ||
import { | ||
createNetworkSignal, | ||
NetworkData, | ||
NetworkSignalMetadata, | ||
} from '../signals' | ||
import { normalizeUrl } from '../../lib/normalize-url' | ||
|
||
jest.mock('../../lib/normalize-url', () => ({ | ||
normalizeUrl: jest.fn((url) => url), | ||
})) | ||
|
||
describe(createNetworkSignal, () => { | ||
const metadata: NetworkSignalMetadata = { | ||
filters: { | ||
allowed: ['allowed1', 'allowed2'], | ||
disallowed: ['disallowed1', 'disallowed2'], | ||
}, | ||
} | ||
|
||
it('should create a network signal for a request', () => { | ||
const data: NetworkData = { | ||
action: 'request', | ||
url: 'http://example.com', | ||
method: 'post', | ||
data: { key: 'value' }, | ||
} | ||
|
||
const signal = createNetworkSignal(data, metadata) | ||
|
||
expect(signal).toEqual({ | ||
type: 'network', | ||
data: { | ||
action: 'request', | ||
url: 'http://example.com', | ||
method: 'POST', | ||
data: { key: 'value' }, | ||
}, | ||
metadata, | ||
}) | ||
expect(normalizeUrl).toHaveBeenCalledWith('http://example.com') | ||
}) | ||
|
||
it('should create a network signal for a response', () => { | ||
const data: NetworkData = { | ||
action: 'response', | ||
url: 'http://example.com', | ||
data: { key: 'value' }, | ||
} | ||
|
||
const signal = createNetworkSignal(data, metadata) | ||
|
||
expect(signal).toEqual({ | ||
type: 'network', | ||
data: { | ||
action: 'response', | ||
url: 'http://example.com', | ||
data: { key: 'value' }, | ||
}, | ||
metadata, | ||
}) | ||
expect(normalizeUrl).toHaveBeenCalledWith('http://example.com') | ||
}) | ||
}) |
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