-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
85 additions
and
51 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
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,28 @@ | ||
export interface DevtoolMessageRequest { | ||
method: string | ||
params: Record<string, any> | ||
} | ||
|
||
export interface DevtoolMessageResponse { | ||
id: string | ||
result: any | ||
method?: string | ||
} | ||
|
||
export type DevtoolMessage = DevtoolMessageRequest | DevtoolMessageResponse | ||
|
||
export class BaseDevtoolServer { | ||
public timestamp = 0 | ||
private startTime = Date.now() | ||
public getTimestamp() { | ||
this.updateTimestamp() | ||
return this.timestamp | ||
} | ||
public listeners: ((error: unknown | null, message?: any) => void)[] = [] | ||
public updateTimestamp() { | ||
this.timestamp = (Date.now() - this.startTime) / 1000 | ||
} | ||
public on(listener: (error: unknown | null, message?: any) => void) { | ||
this.listeners.push(listener) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { DevtoolMessage } from '../devtool' | ||
import { BaseDevtoolServer, IDevtoolServer, DevtoolServerInitOptions } from '../devtool/index' | ||
|
||
/** | ||
* 模拟 Devtool server,作为 core 上下文用于测试 | ||
*/ | ||
export class DevToolTester extends BaseDevtoolServer implements IDevtoolServer { | ||
private port: number | ||
constructor(props: DevtoolServerInitOptions) { | ||
super() | ||
const { port, autoOpenDevtool = true } = props | ||
|
||
this.port = port | ||
autoOpenDevtool && this.open() | ||
} | ||
async send(message: DevtoolMessage) { | ||
return message | ||
} | ||
async open() {} | ||
close() {} | ||
} |
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,6 @@ | ||
export class PluginTester { | ||
public plugins: any[] = [] | ||
public loadPlugins(plugins: any[]) { | ||
this.plugins = plugins | ||
} | ||
} |