Best JavaScript code snippet using wpt
outputServices.ts
Source:outputServices.ts
1/*---------------------------------------------------------------------------------------------2 * Copyright (c) Microsoft Corporation. All rights reserved.3 * Licensed under the MIT License. See License.txt in the project root for license information.4 *--------------------------------------------------------------------------------------------*/5import { Event, Emitter } from 'vs/base/common/event';6import { URI } from 'vs/base/common/uri';7import { IDisposable, dispose, Disposable } from 'vs/base/common/lifecycle';8import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';9import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';10import { Registry } from 'vs/platform/registry/common/platform';11import { IOutputChannel, IOutputService, OUTPUT_VIEW_ID, OUTPUT_SCHEME, LOG_SCHEME, LOG_MIME, OUTPUT_MIME, OutputChannelUpdateMode, IOutputChannelDescriptor, Extensions, IOutputChannelRegistry } from 'vs/workbench/services/output/common/output';12import { OutputLinkProvider } from 'vs/workbench/contrib/output/browser/outputLinkProvider';13import { ITextModelService, ITextModelContentProvider } from 'vs/editor/common/services/resolverService';14import { ITextModel } from 'vs/editor/common/model';15import { ILogService } from 'vs/platform/log/common/log';16import { ILifecycleService } from 'vs/workbench/services/lifecycle/common/lifecycle';17import { IOutputChannelModel } from 'vs/workbench/contrib/output/common/outputChannelModel';18import { IViewsService } from 'vs/workbench/common/views';19import { OutputViewPane } from 'vs/workbench/contrib/output/browser/outputView';20import { IOutputChannelModelService } from 'vs/workbench/contrib/output/common/outputChannelModelService';21import { ILanguageService } from 'vs/editor/common/languages/language';22const OUTPUT_ACTIVE_CHANNEL_KEY = 'output.activechannel';23class OutputChannel extends Disposable implements IOutputChannel {24 scrollLock: boolean = false;25 readonly model: IOutputChannelModel;26 readonly id: string;27 readonly label: string;28 readonly uri: URI;29 constructor(30 readonly outputChannelDescriptor: IOutputChannelDescriptor,31 @IOutputChannelModelService outputChannelModelService: IOutputChannelModelService,32 @ILanguageService languageService: ILanguageService,33 ) {34 super();35 this.id = outputChannelDescriptor.id;36 this.label = outputChannelDescriptor.label;37 this.uri = URI.from({ scheme: OUTPUT_SCHEME, path: this.id });38 this.model = this._register(outputChannelModelService.createOutputChannelModel(this.id, this.uri, outputChannelDescriptor.languageId ? languageService.createById(outputChannelDescriptor.languageId) : languageService.createByMimeType(outputChannelDescriptor.log ? LOG_MIME : OUTPUT_MIME), outputChannelDescriptor.file));39 }40 append(output: string): void {41 this.model.append(output);42 }43 update(mode: OutputChannelUpdateMode, till?: number): void {44 this.model.update(mode, till, true);45 }46 clear(): void {47 this.model.clear();48 }49 replace(value: string): void {50 this.model.replace(value);51 }52}53export class OutputService extends Disposable implements IOutputService, ITextModelContentProvider {54 declare readonly _serviceBrand: undefined;55 private channels: Map<string, OutputChannel> = new Map<string, OutputChannel>();56 private activeChannelIdInStorage: string;57 private activeChannel?: OutputChannel;58 private readonly _onActiveOutputChannel = this._register(new Emitter<string>());59 readonly onActiveOutputChannel: Event<string> = this._onActiveOutputChannel.event;60 constructor(61 @IStorageService private readonly storageService: IStorageService,62 @IInstantiationService private readonly instantiationService: IInstantiationService,63 @ITextModelService textModelResolverService: ITextModelService,64 @ILogService private readonly logService: ILogService,65 @ILifecycleService private readonly lifecycleService: ILifecycleService,66 @IViewsService private readonly viewsService: IViewsService,67 ) {68 super();69 this.activeChannelIdInStorage = this.storageService.get(OUTPUT_ACTIVE_CHANNEL_KEY, StorageScope.WORKSPACE, '');70 // Register as text model content provider for output71 textModelResolverService.registerTextModelContentProvider(OUTPUT_SCHEME, this);72 instantiationService.createInstance(OutputLinkProvider);73 // Create output channels for already registered channels74 const registry = Registry.as<IOutputChannelRegistry>(Extensions.OutputChannels);75 for (const channelIdentifier of registry.getChannels()) {76 this.onDidRegisterChannel(channelIdentifier.id);77 }78 this._register(registry.onDidRegisterChannel(this.onDidRegisterChannel, this));79 // Set active channel to first channel if not set80 if (!this.activeChannel) {81 const channels = this.getChannelDescriptors();82 this.setActiveChannel(channels && channels.length > 0 ? this.getChannel(channels[0].id) : undefined);83 }84 this._register(this.lifecycleService.onDidShutdown(() => this.dispose()));85 }86 provideTextContent(resource: URI): Promise<ITextModel> | null {87 const channel = <OutputChannel>this.getChannel(resource.path);88 if (channel) {89 return channel.model.loadModel();90 }91 return null;92 }93 async showChannel(id: string, preserveFocus?: boolean): Promise<void> {94 const channel = this.getChannel(id);95 if (this.activeChannel?.id !== channel?.id) {96 this.setActiveChannel(channel);97 this._onActiveOutputChannel.fire(id);98 }99 const outputView = await this.viewsService.openView<OutputViewPane>(OUTPUT_VIEW_ID, !preserveFocus);100 if (outputView && channel) {101 outputView.showChannel(channel, !!preserveFocus);102 }103 }104 getChannel(id: string): OutputChannel | undefined {105 return this.channels.get(id);106 }107 getChannelDescriptor(id: string): IOutputChannelDescriptor | undefined {108 return Registry.as<IOutputChannelRegistry>(Extensions.OutputChannels).getChannel(id);109 }110 getChannelDescriptors(): IOutputChannelDescriptor[] {111 return Registry.as<IOutputChannelRegistry>(Extensions.OutputChannels).getChannels();112 }113 getActiveChannel(): IOutputChannel | undefined {114 return this.activeChannel;115 }116 private async onDidRegisterChannel(channelId: string): Promise<void> {117 const channel = this.createChannel(channelId);118 this.channels.set(channelId, channel);119 if (!this.activeChannel || this.activeChannelIdInStorage === channelId) {120 this.setActiveChannel(channel);121 this._onActiveOutputChannel.fire(channelId);122 const outputView = this.viewsService.getActiveViewWithId<OutputViewPane>(OUTPUT_VIEW_ID);123 outputView?.showChannel(channel, true);124 }125 }126 private createChannel(id: string): OutputChannel {127 const channelDisposables: IDisposable[] = [];128 const channel = this.instantiateChannel(id);129 channel.model.onDispose(() => {130 if (this.activeChannel === channel) {131 const channels = this.getChannelDescriptors();132 const channel = channels.length ? this.getChannel(channels[0].id) : undefined;133 if (channel && this.viewsService.isViewVisible(OUTPUT_VIEW_ID)) {134 this.showChannel(channel.id);135 } else {136 this.setActiveChannel(undefined);137 }138 }139 Registry.as<IOutputChannelRegistry>(Extensions.OutputChannels).removeChannel(id);140 dispose(channelDisposables);141 }, channelDisposables);142 return channel;143 }144 private instantiateChannel(id: string): OutputChannel {145 const channelData = Registry.as<IOutputChannelRegistry>(Extensions.OutputChannels).getChannel(id);146 if (!channelData) {147 this.logService.error(`Channel '${id}' is not registered yet`);148 throw new Error(`Channel '${id}' is not registered yet`);149 }150 return this.instantiationService.createInstance(OutputChannel, channelData);151 }152 private setActiveChannel(channel: OutputChannel | undefined): void {153 this.activeChannel = channel;154 if (this.activeChannel) {155 this.storageService.store(OUTPUT_ACTIVE_CHANNEL_KEY, this.activeChannel.id, StorageScope.WORKSPACE, StorageTarget.USER);156 } else {157 this.storageService.remove(OUTPUT_ACTIVE_CHANNEL_KEY, StorageScope.WORKSPACE);158 }159 }160}161export class LogContentProvider {162 private channelModels: Map<string, IOutputChannelModel> = new Map<string, IOutputChannelModel>();163 constructor(164 @IOutputService private readonly outputService: IOutputService,165 @IOutputChannelModelService private readonly outputChannelModelService: IOutputChannelModelService,166 @ILanguageService private readonly languageService: ILanguageService167 ) {168 }169 provideTextContent(resource: URI): Promise<ITextModel> | null {170 if (resource.scheme === LOG_SCHEME) {171 const channelModel = this.getChannelModel(resource);172 if (channelModel) {173 return channelModel.loadModel();174 }175 }176 return null;177 }178 private getChannelModel(resource: URI): IOutputChannelModel | undefined {179 const channelId = resource.path;180 let channelModel = this.channelModels.get(channelId);181 if (!channelModel) {182 const channelDisposables: IDisposable[] = [];183 const outputChannelDescriptor = this.outputService.getChannelDescriptors().filter(({ id }) => id === channelId)[0];184 if (outputChannelDescriptor && outputChannelDescriptor.file) {185 channelModel = this.outputChannelModelService.createOutputChannelModel(channelId, resource, outputChannelDescriptor.languageId ? this.languageService.createById(outputChannelDescriptor.languageId) : this.languageService.createByMimeType(outputChannelDescriptor.log ? LOG_MIME : OUTPUT_MIME), outputChannelDescriptor.file);186 channelModel.onDispose(() => dispose(channelDisposables), channelDisposables);187 this.channelModels.set(channelId, channelModel);188 }189 }190 return channelModel;191 }...
Channels.js
Source:Channels.js
1import {2 ChannelsHamt,3 AddressesHamt,4 PulseLink,5 Channel,6 Address,7 Interpulse,8} from '.'9import assert from 'assert-fast'10import { IpldStruct } from './IpldStruct'11/**12type Channels struct {13 counter Int14 list HashMapRoot # Map of channelIds to Channels15 addresses HashMapRoot # reverse lookup of channels16 rxs [ Int ]17 txs [ Int ]18}19 */20const FIXED_CHANNEL_COUNT = 321export class Channels extends IpldStruct {22 static classMap = {23 list: ChannelsHamt,24 addresses: AddressesHamt,25 }26 static create() {27 const list = ChannelsHamt.create()28 const counter = FIXED_CHANNEL_COUNT29 const addresses = AddressesHamt.create()30 const rxs = []31 const txs = []32 return super.clone({ counter, list, addresses, rxs, txs })33 }34 assertLogic() {}35 async has(channelId) {36 assert(Number.isInteger(channelId))37 assert(channelId >= 0)38 assert(channelId < this.counter)39 return await this.list.has(channelId)40 }41 async hasAddress(address) {42 assert(address instanceof Address)43 assert(address.isRemote())44 return await this.addresses.has(address)45 }46 async getByAddress(address) {47 assert(address instanceof Address)48 const channelId = await this.addresses.get(address)49 return await this.getChannel(channelId)50 }51 async deleteChannel(channelId) {52 await this.#assertChannelIdValid(channelId)53 const list = this.list.delete(channelId)54 return this.setMap({ list })55 }56 async getChannel(channelId) {57 await this.#assertChannelIdValid(channelId)58 const channel = await this.list.get(channelId)59 assert.strictEqual(channelId, channel.channelId)60 return channel61 }62 async #assertChannelIdValid(channelId) {63 assert(Number.isInteger(channelId))64 assert(channelId >= 0)65 assert(channelId < this.counter)66 if (channelId >= FIXED_CHANNEL_COUNT) {67 assert(await this.list.has(channelId), `channelId not present`)68 }69 }70 async addChannel(channel) {71 assert(channel instanceof Channel)72 assert(Number.isInteger(this.counter))73 assert(this.counter >= FIXED_CHANNEL_COUNT)74 let { counter, addresses } = this75 const channelId = counter++76 assert.strictEqual(channelId, channel.channelId)77 const list = await this.list.set(channelId, channel)78 const { address } = channel79 if (address.isRemote()) {80 addresses = await this.addresses.set(address, channelId)81 }82 const next = this.setMap({ counter, list, addresses })83 return next.updateActives(channelId, channel)84 }85 async updateChannel(channel) {86 const { channelId } = channel87 await this.#assertChannelIdValid(channelId)88 let previous89 const isPrevious = await this.list.has(channelId)90 if (channelId >= FIXED_CHANNEL_COUNT || isPrevious) {91 previous = await this.list.get(channelId)92 assert(previous.isNext(channel))93 // TODO if channel is identical, return94 }95 const list = await this.list.set(channelId, channel)96 let { addresses } = this97 const isResolved = previous && !previous.isRemote() && channel.isRemote()98 const isNewResolved = !previous && channel.isRemote()99 if (isResolved || isNewResolved) {100 const { address } = channel101 addresses = await addresses.set(address, channelId)102 }103 const next = this.setMap({ list, addresses })104 return next.updateActives(channelId, channel)105 }106 updateActives(channelId, channel) {107 assert(Number.isInteger(channelId))108 assert(channelId >= 0)109 assert(channel instanceof Channel)110 const { address } = channel111 let { rxs, txs } = this112 if (!channel.rxIsEmpty()) {113 assert(!address.isRoot())114 if (!rxs.includes(channelId)) {115 rxs = [...rxs, channelId]116 }117 } else {118 if (rxs.includes(channelId)) {119 rxs = rxs.filter((id) => id !== channelId)120 if (address.isInvalid()) {121 // TODO delete the channel from the list and clean up aliases122 }123 }124 }125 if (rxs !== this.rxs) {126 // ensure loopback, parent, and io come before others127 rxs.sort((a, b) => a - b)128 }129 if (!channel.tx.isEmpty()) {130 assert(!address.isRoot())131 if (!txs.includes(channelId) && !address.isIo() && address.isResolved()) {132 txs = [...txs, channelId]133 }134 } else {135 if (txs.includes(channelId)) {136 txs = txs.filter((id) => id !== channelId)137 }138 }139 return this.setMap({ rxs, txs })140 }141 async getTx(channelId) {142 assert(Number.isInteger(channelId))143 assert(channelId >= 0)144 assert(this.txs.includes(channelId))145 const { tx } = await this.list.get(channelId)146 assert(!tx.isEmpty())147 return tx148 }149 async blankTxs(precedent) {150 assert(precedent instanceof PulseLink)151 let { list } = this152 for (const channelId of this.txs) {153 let channel = await list.get(channelId)154 assert(!channel.tx.isEmpty())155 const tx = channel.tx.blank(precedent)156 channel = channel.setMap({ tx })157 list = await list.set(channelId, channel)158 }159 return this.setMap({ list, txs: [] })160 }161 async ingestInterpulse(interpulse) {162 assert(interpulse instanceof Interpulse)163 const { source } = interpulse164 assert(await this.hasAddress(source), `No address: ${source}`)165 let channel = await this.getByAddress(source)166 channel = channel.ingestInterpulse(interpulse)167 return await this.updateChannel(channel)168 }169 async *rxChannels() {170 for (const channelId of this.rxs) {171 const channel = await this.getChannel(channelId)172 assert(!channel.rxIsEmpty())173 yield channel174 }175 }...
channel.js
Source:channel.js
1import { csrfFetch } from "./csrf";2//add, edit, delete3//--------------------------------------------set channels-----------------------4const SET_USER_CHANNELS = "channels/SetUserChannels";5export const setUserChannels = (channels) => {6 return { type: SET_USER_CHANNELS, channels };7};8//------------------------------------add channel---------------------------------9const ADD_CHANNEL = "Channels/AddChannel";10export const addChannel = (channel) => ({11 type: ADD_CHANNEL,12 channel,13});14export const postChannel = (channel) => async (dispatch) => {15 const res = await csrfFetch("/api/channels/", {16 method: "POST",17 body: JSON.stringify(channel),18 });19 const new_channel = await res.json();20 dispatch(addChannel(new_channel));21 return new_channel;22};23//------------------------------------edit channel---------------------------------24const UPDATE_CHANNEL = "channels/UpdateChannel";25export const updateChannel = (channel) => ({26 type: UPDATE_CHANNEL,27 channel,28});29export const putChannel = (channel) => async (dispatch) => {30 const res = await csrfFetch(`/api/channels/${channel.id}`, {31 method: "PUT",32 headers: { "Content-Type": "application/json" },33 body: JSON.stringify(channel),34 });35 const updatedChannel = await res.json();36 dispatch(updateChannel(updatedChannel));37};38//------------------------------------delete channel---------------------------------39const DELETE_CHANNEL = "channels/deleteChannel";40export const removeChannel = (channel_id) => ({41 type: DELETE_CHANNEL,42 channel_id,43});44export const deleteChannel = (channel_id) => async (dispatch) => {45 const res = await fetch(`/api/channels/${channel_id}`, {46 method: "DELETE",47 });48 const channelNum = await res.json();49 dispatch(removeChannel(channelNum));50};51//------------------------------------delete channel---------------------------------52const ADD_CHANNEL_MEMBER = "channels/addChannelMember";53export const addChannelMember = payload => ({54 type: ADD_CHANNEL_MEMBER,55 payload56})57export const addNewChannelMember = (channel_id, username) => async dispatch => {58 const res = await fetch(`/api/channels/${channel_id}/new_member`, {59 method: "POST",60 headers: { "Content-Type": "application/json" },61 body: JSON.stringify(username)62 });63 const newMember = await res.json();64 dispatch(addChannelMember(newMember));65}66//-----------------------------------channel reducer---------------------------------67const channelReducer = (68 state = { currentChannel: {}, currentView: {}, userChannels: {} },69 action70) => {71 let newState = { ...state };72 switch (action.type) {73 case SET_USER_CHANNELS: {74 action.channels.forEach(75 (channel) => (newState.userChannels[channel.channel_id] = channel)76 );77 return newState;78 }79 case ADD_CHANNEL: {80 newState.userChannels[action.channel.channel_id] = { ...action.channel };81 return newState;82 }83 case UPDATE_CHANNEL: {84 newState.userChannels[action.channel.channel_id] = action.channel;85 return newState;86 }87 case DELETE_CHANNEL: {88 delete newState.userChannels[action.channel_id.channel_id];89 return newState;90 }91 case ADD_CHANNEL_MEMBER: {92 if (newState.userChannels[action.payload.channel_id]) {93 newState.userChannels[action.payload.channel_id].channel_data.members = [...newState.userChannels[action.payload.channel_id].channel_data.members, action.payload];94 } else {95 newState.userChannels[action.payload.channel_id] = action.payload;96 }97 return newState;98 }99 default:100 return state;101 }102};...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.runTest(url, function(err, data) {4 if (err) return console.log(err);5 wpt.getTestResults(data.data.testId, function(err, data) {6 if (err) return console.log(err);7 console.log(data);8 });9});
Using AI Code Generation
1var wpt = require('webpagetest');2var api = new wpt('www.webpagetest.org');3api.channel('test', function(err, data) {4 if (err) return console.error(err);5 console.log(data);6});7var wpt = require('webpagetest');8var api = new wpt('www.webpagetest.org');9var options = {
Using AI Code Generation
1var wptools = require('wptools');2channel.get(function(err, resp) {3 console.log(resp);4});5var wptools = require('wptools');6channel.get(function(err, resp) {7 console.log(resp);8});9var wptools = require('wptools');10channel.get(function(err, resp) {11 console.log(resp);12});13var wptools = require('wptools');14channel.get(function(err, resp) {15 console.log(resp);16});17var wptools = require('wptools');18channel.get(function(err, resp) {19 console.log(resp);20});21var wptools = require('wptools');22channel.get(function(err, resp) {23 console.log(resp);24});25var wptools = require('wptools');26channel.get(function(err, resp) {27 console.log(resp);28});29var wptools = require('wptools');30channel.get(function(err, resp) {31 console.log(resp);32});33var wptools = require('wpt
Using AI Code Generation
1var wptools = require('wptools');2var channel = wptools.channel('en.wikipedia.org');3channel.get('Albert Einstein').then(function(doc) {4 console.log(doc);5}).catch(function(err) {6 console.log(err);7});8var wptools = require('wptools');9var category = wptools.category('en.wikipedia.org');10category.get('Category:Physics').then(function(doc) {11 console.log(doc);12}).catch(function(err) {13 console.log(err);14});15var wptools = require('wptools');16var template = wptools.template('en.wikipedia.org');17template.get('Template:Infobox person').then(function(doc) {18 console.log(doc);19}).catch(function(err) {20 console.log(err);21});22var wptools = require('wptools');23var list = wptools.list('en.wikipedia.org');24list.get('List of countries by GDP (nominal)').then(function(doc) {25 console.log(doc);26}).catch(function(err) {27 console.log(err);28});29- [bluebird](
Using AI Code Generation
1var wpt = require('webpagetest');2var client = wpt('www.webpagetest.org');3client.channel('test', 'runtest', {4}, function(err, data) {5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 }10});11var wpt = require('webpagetest');12var client = wpt('www.webpagetest.org');13client.channel('test', 'runtest', {14}, function(err, data) {15 if (err) {16 console.log(err);17 } else {18 console.log(data);19 }20});21var wpt = require('webpagetest');22var client = wpt('www.webpagetest.org');23client.channel('test', 'runtest', {24}, function(err, data) {25 if (err) {26 console.log(err);27 } else {28 console.log(data);29 }30});31var wpt = require('webpagetest');32var client = wpt('www.webpagetest.org');33client.channel('test', 'runtest', {34}, function(err, data) {35 if (err) {36 console.log(err);37 } else {38 console.log(data);39 }40});41var wpt = require('webpagetest');42var client = wpt('www.webpagetest.org');43client.channel('test', 'runtest', {44}, function(err, data) {
Using AI Code Generation
1var wptools = require('wptools');2var channel = wptools.channel('Stephen Colbert');3channel.get(function(err, res) {4 console.log(res);5});6var wptools = require('wptools');7var channel = wptools.channel('Stephen Colbert');8channel.get(function(err, res) {9 console.log(res);10});11var wptools = require('wptools');12var channel = wptools.channel('Stephen Colbert');13channel.get(function(err, res) {14 console.log(res);15});16var wptools = require('wptools');17var channel = wptools.channel('Stephen Colbert');18channel.get(function(err, res) {19 console.log(res);20});21var wptools = require('wptools');22var channel = wptools.channel('Stephen Colbert');23channel.get(function(err, res) {24 console.log(res);25});26var wptools = require('wptools');27var channel = wptools.channel('Stephen Colbert');28channel.get(function(err, res) {29 console.log(res);30});31var wptools = require('wptools');32var channel = wptools.channel('Stephen Colbert');33channel.get(function(err, res) {34 console.log(res);35});36var wptools = require('wptools');37var channel = wptools.channel('Stephen Colbert');38channel.get(function(err, res) {39 console.log(res);40});41var wptools = require('wptools');42var channel = wptools.channel('Stephen Colbert');43channel.get(function(err, res) {44 console.log(res);45});46var wptools = require('wptools');47var channel = wptools.channel('Stephen
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!