diff --git a/lib/sse.js b/lib/sse.js index b992b4f..c855f2b 100644 --- a/lib/sse.js +++ b/lib/sse.js @@ -1,6 +1,21 @@ /** + * sse.js - A flexible EventSource polyfill/replacement. + * https://github.com/mpetazzoni/sse.js + * * Copyright (C) 2016-2024 Maxime Petazzoni . * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/lib/sse.test.js b/lib/sse.test.js index 5d382e5..7479175 100644 --- a/lib/sse.test.js +++ b/lib/sse.test.js @@ -1,3 +1,23 @@ +/** + * sse.js - A flexible EventSource polyfill/replacement. + * https://github.com/mpetazzoni/sse.js + * + * Copyright (C) 2016-2024 Maxime Petazzoni . + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import { SSE } from 'sse.js'; // Setup Mocking for XMLHttpRequest @@ -32,7 +52,7 @@ beforeEach(() => { describe('SSE Initialization', () => { - + it('should initialize with default options', () => { const sse = new SSE('http://example.com'); expect(sse.method).toBe('GET'); @@ -164,7 +184,7 @@ describe('SSE Event handling and Listeners', () => { expect(listener.mock.calls[0][0].event).toBe(undefined); expect(listener.mock.calls[0][0].id).toBe('1'); expect(listener.mock.calls[0][0].lastEventId).toBe('1'); - }) + }) it('should handle multiple data events', () => { sse.xhr.responseText = 'id: id1\ndata: First message\n\n'; @@ -237,7 +257,7 @@ describe('SSE Event handling and Listeners', () => { expect(listener.mock.calls[0][0].data).toBe('Test message\nmore message'); expect(listener.mock.calls[0][0].event).toBe(undefined); expect(listener.mock.calls[0][0].id).toBe(null); - }) + }) it('should handle an event with a custom event type', () => { sse.xhr.responseText = 'event: customEvent\ndata: Custom event data\n\n'; @@ -250,7 +270,7 @@ describe('SSE Event handling and Listeners', () => { expect(customListener.mock.calls[0][0].type).toBe('customEvent'); expect(customListener.mock.calls[0][0].id).toBe(null); }); - + it('should handle events different field orders', () => { sse.xhr.responseText = 'data: Custom event data\nevent: customEvent\nid: 1\n\n'; sse.xhr.trigger('progress', {});