Skip to content

Commit d69039d

Browse files
author
Shane Osbourne
committed
fix: pass all data in .request()
1 parent 64dcb06 commit d69039d

File tree

7 files changed

+102
-8
lines changed

7 files changed

+102
-8
lines changed

packages/messaging/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export class Messaging {
9898
context: this.messagingContext.context,
9999
featureName: this.messagingContext.featureName,
100100
method: name,
101-
params: { data: '' },
101+
params: data,
102102
id
103103
})
104104
return this.transport.request(message)
@@ -127,6 +127,7 @@ export class MessagingTransport {
127127
* @param {NotificationMessage} msg
128128
* @returns {void}
129129
*/
130+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
130131
notify (msg) {
131132
throw new Error("must implement 'notify'")
132133
}
@@ -136,6 +137,7 @@ export class MessagingTransport {
136137
* @param {{signal?: AbortSignal}} [options]
137138
* @return {Promise<any>}
138139
*/
140+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
139141
request (msg, options = {}) {
140142
throw new Error('must implement')
141143
}
@@ -145,6 +147,7 @@ export class MessagingTransport {
145147
* @param {(value: unknown) => void} callback
146148
* @return {() => void}
147149
*/
150+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
148151
subscribe (msg, callback) {
149152
throw new Error('must implement')
150153
}
@@ -185,7 +188,7 @@ export class TestTransport {
185188
return this.config.impl.notify(msg)
186189
}
187190

188-
request (msg, options) {
191+
request (msg) {
189192
return this.config.impl.request(msg)
190193
}
191194

packages/messaging/lib/examples/payloads.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-unused-vars */
12
import { NotificationMessage, RequestMessage, MessageResponse, SubscriptionEvent } from '../../index.js'
23

34
/**

packages/messaging/lib/messaging.types.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ interface UnstableWebkit {
99

1010
interface UnstableMockCall {
1111
payload: import('../index.js').RequestMessage;
12-
response?: Record<string, any>;
12+
response?: Record<string, unknown>;
1313
}
1414

1515
interface Window {
@@ -23,6 +23,6 @@ interface Window {
2323
}
2424
}
2525

26-
declare let windowsInteropPostMessage: any
27-
declare let windowsInteropAddEventListener: any
28-
declare let windowsInteropRemoveEventListener: any
26+
declare let windowsInteropPostMessage: unknown
27+
declare let windowsInteropAddEventListener: unknown
28+
declare let windowsInteropRemoveEventListener: unknown

packages/messaging/lib/windows.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* [[include:packages/messaging/lib/examples/windows.example.js]]```
1212
*
1313
*/
14+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1415
import { MessagingTransport, NotificationMessage, RequestMessage } from '../index.js'
1516

1617
/**

packages/special-pages/pages/duckplayer/src/js/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ const MouseMove = {
686686
/**
687687
* Watch for inactivity and toggle toolbar accordingly
688688
*/
689-
handleFadeState: (e) => {
689+
handleFadeState: () => {
690690
if (MouseMove.timer) {
691691
clearTimeout(MouseMove.timer)
692692
}

packages/special-pages/tests/duckplayer.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ test.describe('duckplayer toolbar', () => {
5454
await page.mouse.move(1, 1)
5555
await duckplayer.infoTooltipIsHidden()
5656
})
57-
test('clicking on cog icon opens settings', async ({ page, context }, workerInfo) => {
57+
test('clicking on cog icon opens settings', async ({ page }, workerInfo) => {
5858
const duckplayer = DuckPlayerPage.create(page, workerInfo)
5959
await duckplayer.openWithVideoID()
6060
await duckplayer.hasLoadedIframe()

unit-test/messaging.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import {
2+
Messaging,
3+
MessagingContext,
4+
TestTransportConfig,
5+
RequestMessage, NotificationMessage, Subscription
6+
} from '@duckduckgo/messaging'
7+
8+
describe('Messaging Transports', () => {
9+
it('calls transport with a RequestMessage', () => {
10+
const { messaging, transport } = createMessaging()
11+
12+
const spy = spyOn(transport, 'request')
13+
14+
messaging.request('helloWorld', { foo: 'bar' })
15+
16+
expect(spy).toHaveBeenCalledWith(new RequestMessage({
17+
context: 'contentScopeScripts',
18+
featureName: 'hello-world',
19+
id: 'helloWorld.response',
20+
method: 'helloWorld',
21+
params: { foo: 'bar' }
22+
}))
23+
})
24+
it('calls transport with a NotificationMessage', () => {
25+
const { messaging, transport } = createMessaging()
26+
27+
const spy = spyOn(transport, 'notify')
28+
29+
messaging.notify('helloWorld', { foo: 'bar' })
30+
31+
expect(spy).toHaveBeenCalledWith(new NotificationMessage({
32+
context: 'contentScopeScripts',
33+
featureName: 'hello-world',
34+
method: 'helloWorld',
35+
params: { foo: 'bar' }
36+
}))
37+
})
38+
it('calls transport with a Subscription', () => {
39+
const { messaging, transport } = createMessaging()
40+
41+
const spy = spyOn(transport, 'subscribe')
42+
const callback = jasmine.createSpy()
43+
44+
messaging.subscribe('helloWorld', callback)
45+
46+
expect(spy).toHaveBeenCalledWith(new Subscription({
47+
context: 'contentScopeScripts',
48+
featureName: 'hello-world',
49+
subscriptionName: 'helloWorld'
50+
}), callback)
51+
})
52+
})
53+
54+
/**
55+
* Creates a test transport and Messaging instance for testing
56+
*/
57+
function createMessaging () {
58+
/** @type {import("@duckduckgo/messaging").MessagingTransport} */
59+
const transport = {
60+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
61+
notify (msg) {
62+
// test
63+
},
64+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
65+
request: (_msg) => {
66+
// test
67+
return Promise.resolve(null)
68+
},
69+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
70+
subscribe (_msg) {
71+
// test
72+
return () => {
73+
// test teardown
74+
}
75+
}
76+
}
77+
78+
const testTransportConfig = new TestTransportConfig(transport)
79+
80+
const messagingContext = new MessagingContext({
81+
context: 'contentScopeScripts',
82+
featureName: 'hello-world',
83+
env: 'development'
84+
})
85+
86+
const messaging = new Messaging(messagingContext, testTransportConfig)
87+
88+
return { transport, messaging }
89+
}

0 commit comments

Comments
 (0)