Some checks failed
CI / go (push) Waiting to run
CI / docker (push) Waiting to run
CI / lint-go (push) Waiting to run
CI / lint-docs (push) Waiting to run
CI / check-paperclip (push) Waiting to run
Deploy static site / Deploy to GitHub Pages (push) Has been cancelled
Deploy static site / Deploy via Docker to hatch.surf (push) Has been cancelled
Resolved conflicts by taking GitHub versions for: - .dockerignore, .gitignore, Dockerfile, README.md, docker-compose.yml Kept deploy.sh updated to: - Pull from GitHub (primary source) - Push to Gitea (push-mirror) - Build from site/ directory (GitHub structure) Co-Authored-By: Paperclip <noreply@paperclip.ing>
83 lines
2.6 KiB
JavaScript
83 lines
2.6 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
const _posttelemetrypayload = require("./post-telemetry-payload");
|
|
describe('postNextTelemetryPayload', ()=>{
|
|
let originalFetch;
|
|
beforeEach(()=>{
|
|
originalFetch = global.fetch;
|
|
});
|
|
afterEach(()=>{
|
|
global.fetch = originalFetch;
|
|
});
|
|
it('sends telemetry payload successfully', async ()=>{
|
|
const mockFetch = jest.fn().mockResolvedValue({
|
|
ok: true
|
|
});
|
|
global.fetch = mockFetch;
|
|
const payload = {
|
|
meta: {
|
|
version: '1.0'
|
|
},
|
|
context: {
|
|
anonymousId: 'test-id',
|
|
projectId: 'test-project',
|
|
sessionId: 'test-session'
|
|
},
|
|
events: [
|
|
{
|
|
eventName: 'test-event',
|
|
fields: {
|
|
foo: 'bar'
|
|
}
|
|
}
|
|
]
|
|
};
|
|
await (0, _posttelemetrypayload.postNextTelemetryPayload)(payload);
|
|
expect(mockFetch).toHaveBeenCalledWith('https://telemetry.nextjs.org/api/v1/record', {
|
|
method: 'POST',
|
|
body: JSON.stringify(payload),
|
|
headers: {
|
|
'content-type': 'application/json'
|
|
},
|
|
signal: expect.any(AbortSignal)
|
|
});
|
|
});
|
|
it('retries on failure', async ()=>{
|
|
const mockFetch = jest.fn().mockRejectedValueOnce(new Error('Network error')).mockResolvedValueOnce({
|
|
ok: true
|
|
});
|
|
global.fetch = mockFetch;
|
|
const payload = {
|
|
meta: {},
|
|
context: {
|
|
anonymousId: 'test-id',
|
|
projectId: 'test-project',
|
|
sessionId: 'test-session'
|
|
},
|
|
events: []
|
|
};
|
|
await (0, _posttelemetrypayload.postNextTelemetryPayload)(payload);
|
|
expect(mockFetch).toHaveBeenCalledTimes(2);
|
|
});
|
|
it('swallows errors after retries exhausted', async ()=>{
|
|
const mockFetch = jest.fn().mockRejectedValue(new Error('Network error'));
|
|
global.fetch = mockFetch;
|
|
const payload = {
|
|
meta: {},
|
|
context: {
|
|
anonymousId: 'test-id',
|
|
projectId: 'test-project',
|
|
sessionId: 'test-session'
|
|
},
|
|
events: []
|
|
};
|
|
// Should not throw
|
|
await (0, _posttelemetrypayload.postNextTelemetryPayload)(payload);
|
|
expect(mockFetch).toHaveBeenCalledTimes(2) // Initial try + 1 retry
|
|
;
|
|
});
|
|
});
|
|
|
|
//# sourceMappingURL=post-telemetry-payload.test.js.map
|