How to use createIIFE method in ts-auto-mock

Best JavaScript code snippet using ts-auto-mock

twitch.user.ts

Source:twitch.user.ts Github

copy

Full Screen

1// ==UserScript==2// @encoding utf-83// @name Twitch Indirection4// @description Provides stream indirection to restore high quality streams on limited countries without proxying.5// @author HoJeong Go <seia@outlook.kr>6// @version 0.0.17//8// @grant none9// @run-at document-start10//11// @match https://*.twitch.tv/*12//13// @namespace https://github.com/seia-soto/filter-kr14// @homepageURL https://github.com/seia-soto/filter-kr15// @supportURL https://github.com/seia-soto/filter-kr16// @updateURL https://github.com/seia-soto/filter-kr/raw/master/scripts-compiled/twitch.user.js17// @downloadURL https://github.com/seia-soto/filter-kr/raw/master/scripts-compiled/twitch.user.js18// ==/UserScript==19const enum EProxyType {20 KwabangNet = 'kwabang-net',21}22type TFetchHandler = (request: () => Promise<Response>, info: RequestInfo, init: RequestInit) => Promise<Response | void>23(() => {24 // @ts-expect-error25 if (typeof unsafeWindow !== 'undefined') {26 // @ts-expect-error27 window = unsafeWindow28 }29 // Config30 const configKey = '__indirector_setting'31 const configSource = window.localStorage.getItem(configKey) ?? '{}'32 const config: {33 __version: number,34 proxyType: EProxyType,35 proxyUrl: string36 } = Object.assign({37 __version: 1,38 proxyType: EProxyType.KwabangNet,39 proxyUrl: 'https://api.twitch.tyo.kwabang.net/hls-raw/'40 }, JSON.parse(configSource))41 window.localStorage.removeItem(configKey)42 if (!config.proxyUrl.endsWith('/')) {43 config.proxyUrl += '/'44 }45 window.addEventListener('beforeunload', () => {46 window.localStorage.setItem(configKey, JSON.stringify(config))47 })48 // Hook49 const secret = (Date.now() + Math.random()).toString()50 const references = new Map<string, Blob[]>()51 const createIife = (fn: Function) => '(' + fn.toString() + ')(' + JSON.stringify(config) + ');\n'52 const hookFetchOnWorker = (kConfig: typeof config) => {53 const consumer = new Map<string, string>()54 let handler: TFetchHandler55 if (kConfig.proxyType === EProxyType.KwabangNet) {56 handler = async (request, info, init) => {57 const url = info.toString()58 if (url.startsWith('https://usher.ttvnw.net/api/channel/hls/')) {59 return fetch(kConfig.proxyUrl + url.split('/')[6])60 }61 }62 }63 const hook = new Proxy(64 fetch,65 {66 async apply(target, thisArg, argArray: [RequestInfo, RequestInit]) {67 const request = () => Reflect.apply(target, thisArg, argArray) as Promise<Response>68 try {69 const did = await handler(request, argArray[0], argArray[1])70 if (did) {71 return did72 }73 } catch (error) {74 console.error(error)75 }76 return request()77 },78 }79 )80 if (typeof window === 'undefined') {81 // @ts-expect-error82 fetch = hook83 } else {84 window.fetch = hook85 }86 }87 window.fetch = new Proxy(88 window.fetch,89 {90 async apply(target, thisArg, argArray: [RequestInfo, RequestInit]) {91 const request = () => Reflect.apply(target, thisArg, argArray) as Promise<Response>92 if (argArray[0].toString().includes('amazon-ivs-wasmworker')) {93 const response = await request()94 const text = await response.text()95 return async () => new Response(createIife(hookFetchOnWorker) + text)96 }97 return request()98 },99 }100 )101 window.Worker = new Proxy(102 window.Worker,103 {104 construct(target, argArray: [string], newTarget) {105 const fallback = () => Reflect.construct(target, argArray, newTarget)106 const [url] = argArray107 const entry = references.get(url)108 if (!entry) {109 return fallback()110 }111 // @ts-expect-error112 const retrieved = entry[0].text(secret) as string[]113 if (!Array.isArray(retrieved)) {114 return fallback()115 }116 const [source] = retrieved117 const kArgArray = [118 URL.createObjectURL(119 new Blob([createIife(hookFetchOnWorker) + source])120 )121 ]122 return Reflect.construct(target, kArgArray, newTarget)123 },124 }125 )126 window.Blob = new Proxy(127 window.Blob,128 {129 construct(target, argArray, newTarget) {130 const blob: Blob = Reflect.construct(target, argArray, newTarget)131 blob.text = new Proxy(132 blob.text,133 {134 apply(kTarget, kThisArg, kTargArray) {135 if (kTargArray[0] === secret) {136 return argArray137 }138 return Reflect.apply(kTarget, kThisArg, kTargArray)139 },140 }141 )142 return blob143 },144 }145 )146 window.URL.createObjectURL = new Proxy(147 window.URL.createObjectURL,148 {149 apply(target, thisArg, argArray) {150 const url = Reflect.apply(target, thisArg, argArray)151 references.set(url, argArray)152 return url153 },154 }155 )...

Full Screen

Full Screen

checkInteractiveListenerOfInteractiveCallbackedEvent.js

Source:checkInteractiveListenerOfInteractiveCallbackedEvent.js Github

copy

Full Screen

1"use strict";2const expect = require("assert");3const wait = require("./../../../utils/wait");4const createAbsoluteUrlToServerOnLocalhost = require("./../../modules/createAbsoluteUrlToServerOnLocalhost");5const {6 createTimeoutForPromise,7 resolveAwaitedPromise,8 maxTimeMsForTask9} = require("./modules/common");10const createOnceListener = require("./modules/createOnceListener");11const checkInteractiveListenerOfInteractiveCallbackedEvent = function(httpServer, browser) {12 return new Promise(async function(resolve, reject) {13 const timeout = createTimeoutForPromise(reject, maxTimeMsForTask);14 const tabs = browser.tabs;15 const idOfMessage = 2;16 const expectedResponse = 4;17 const propertyInWindow = "response";18 const srcOfSendingAndRecodingResponseScript = createScriptToSendMessageAndRecordResponse(19 idOfMessage,20 propertyInWindow21 );22 const onMessage = browser.runtime.onMessage;23 const listener = createOnceListener(onMessage, function(data, sender, sendResponse) {24 if (typeof data === "object" && data.idOfMessage === idOfMessage) {25 (async function() {26 sendResponse(expectedResponse);27 await wait(200);28 const responseInTab = await getValueFromWindow(tabs, tabId, propertyInWindow);29 if (responseInTab === expectedResponse) {30 resolveAwaitedPromise(timeout, resolve);31 } else {32 reject(new Error("Ответное сообщение отличается отожидаемого: " + responseInTab));33 }34 })();35 return true;36 }37 });38 const isListenerInteractive = true;39 await onMessage.addListener(listener, isListenerInteractive);40 const url = createAbsoluteUrlToServerOnLocalhost("home", httpServer.port);41 const { id: tabId } = await tabs.create({url});42 await tabs.executeScript(tabId, {43 code: srcOfSendingAndRecodingResponseScript44 });45 });46};47const createScriptToSendMessageAndRecordResponse = (function () {48 const sendMessageAndRecordResponse = async function(49 idOfMessage,50 nameOfPropertyInWindowToRecordResponse51 ) {52 console.log("sendMessageAndRecordResponse");53 window.wasScriptRunned = true;54 let response;55 try {56 response = await browser.runtime.sendMessage({57 idOfMessage58 });59 window[nameOfPropertyInWindowToRecordResponse] = response;60 console.log("sendMessageAndRecordResponse: response ", response);61 } catch(error) {62 console.log("sendMessageAndRecordResponse: error", error);63 }64 };65 return function(66 idOfMessage,67 nameOfPropertyInWindowToRecordResponse68 ) {69 return createIife(sendMessageAndRecordResponse, [70 idOfMessage,71 nameOfPropertyInWindowToRecordResponse72 ]);73 };74})();75const createIife = function(fn, args) {76 return "(" +77 fn.toString() +78 ").apply(null," + JSON.stringify(args) + ");";79};80const getValueFromWindow = async function(tabs, tabId, propertyInWindow) {81 const [value] = await tabs.executeScript(tabId, {82 code: createScrOfScriptToGetValueFromWindow(propertyInWindow)83 });84 return value;85};86const createScrOfScriptToGetValueFromWindow = (function() {87 const getValueFromWindow = function(nameOfProperty) {88 return window[nameOfProperty];89 };90 return function(nameOfProperty) {91 return createIife(getValueFromWindow, [nameOfProperty]);92 };93})();...

Full Screen

Full Screen

index.ts

Source:index.ts Github

copy

Full Screen

1import sltr = require("@fal-works/s-l-t-r");2import common = require("../../common");3import tsc = require("../../use/typescript/tsc");4import rollup = require("../../use/rollup");5import format = require("../../use/format");6import terser = require("../../use/terser");7import type { types } from "@fal-works/s-l-t-r";8const { seq, par } = sltr;9const { cleandir } = sltr.builtin;10/** Config fields required by `command()`. */11export interface BrowserModuleConfig12 extends tsc.TscConfig,13 rollup.RollupConfig,14 terser.TerserConfig {15 typesDir?: string;16 format?: boolean;17 minify?: boolean;18}19/** Creates `Command` that formats lib files. */20const formatLibCommand = (config: BrowserModuleConfig) => (21 distType: common.BrowserDistType22): types.Command => {23 const path = common.getDistFilePath(config, distType);24 return format.command(path);25};26/**27 * Returns `Command` that does everything for building a module for browsers.28 * See README for required library dependencies.29 */30export const command = (config: BrowserModuleConfig): types.Command => {31 const { Iife, Esm } = common.BrowserDistType;32 const { tsOutDir, distDir } = config;33 const typesDir = config.typesDir || distDir;34 const cleanBeforeTsc =35 typesDir !== distDir36 ? par(cleandir(tsOutDir), cleandir(typesDir)).collapse()37 : cleandir(tsOutDir);38 const runTsc = tsc.command(config);39 const transpile = seq(cleanBeforeTsc, runTsc).rename("tsc").collapse();40 const bundle = rollup.commandFromConfig(config);41 const formatLib = formatLibCommand(config);42 const minify = terser.commandFromConfig(config);43 const createIife: types.Command[] = [bundle(Iife)];44 const createEsm: types.Command[] = [bundle(Esm)];45 if (config.format !== false) {46 createIife.push(formatLib(Iife));47 createEsm.push(formatLib(Esm));48 }49 if (config.minify !== false) {50 createIife.push(minify(Iife));51 }52 const createLib = par(53 seq(...createIife).rename("iife"),54 seq(...createEsm).rename("esm")55 );56 const lib = seq(cleandir(distDir), createLib).rename("lib").collapse();57 const libAndTypes =58 config.format !== false59 ? par(format.command(`${typesDir}/**/*.d.ts`), lib)60 : lib;61 return seq(transpile, libAndTypes).hide();62};63/**64 * Calls `command()` and then runs the command immediately.65 * See README for required library dependencies.66 */67export const run = (config: BrowserModuleConfig): ReturnType<typeof sltr.run> =>...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { createIIFE } from 'ts-auto-mock';2const mock = createIIFE('test1');3console.log(mock);4import { createIIFE } from 'ts-auto-mock';5const mock = createIIFE('test2');6console.log(mock);7import { createIIFE } from 'ts-auto-mock';8const mock = createIIFE('test3');9console.log(mock);10import { createIIFE } from 'ts-auto-mock';11const mock = createIIFE('test4');12console.log(mock);13import { createIIFE } from 'ts-auto-mock';14const mock = createIIFE('test5');15console.log(mock);16import { createIIFE } from 'ts-auto-mock';17const mock = createIIFE('test6');18console.log(mock);19import { createIIFE } from 'ts-auto-mock';20const mock = createIIFE('test7');

Full Screen

Using AI Code Generation

copy

Full Screen

1import { createIIFE } from 'ts-auto-mock';2const result = createIIFE('test1');3console.log(result);4import { createIIFE } from 'ts-auto-mock';5const result = createIIFE('test2');6console.log(result);7import { createIIFE } from 'ts-auto-mock';8const result = createIIFE('test3');9console.log(result);10import { createIIFE } from 'ts-auto-mock';11const result = createIIFE('test4');12console.log(result);13import { createIIFE } from 'ts-auto-mock';14const result = createIIFE('test5');15console.log(result);16import { createIIFE } from 'ts-auto-mock';17const result = createIIFE('test6');18console.log(result);19import { createIIFE } from 'ts-auto-mock';20const result = createIIFE('test7');21console.log(result);22import { createIIFE } from 'ts-auto-mock';23const result = createIIFE('test8');24console.log(result);25import {

Full Screen

Using AI Code Generation

copy

Full Screen

1import { createIIFE } from 'ts-auto-mock';2import { MyInterface } from './MyInterface';3const myInterface: MyInterface = createIIFE<MyInterface>(MyInterface);4console.log(myInterface);5export interface MyInterface {6 myProperty: string;7 myMethod(): void;8}9{10 "compilerOptions": {11 }12}13{14 "scripts": {15 },16 "dependencies": {17 },18 "devDependencies": {19 }20}

Full Screen

Using AI Code Generation

copy

Full Screen

1import { createIIFE } from 'ts-auto-mock';2import { Foo } from './foo';3const foo: Foo = createIIFE<Foo>();4export class Foo {5 public bar: string;6}7import { createIIFE } from 'ts-auto-mock';8import { Foo } from './foo';9const foo: Foo = createIIFE<Foo>(['bar']);10export class Foo {11 public bar: string;12}13import { createIIFE } from 'ts-auto-mock';14import { Foo } from './foo';15const foo: Foo = createIIFE<Foo>(['bar'], ['bar']);16export class Foo {17 public bar: string;18}19import { createIIFE } from 'ts-auto-mock';20import { Foo } from './foo';21const foo: Foo = createIIFE<Foo>(['bar'], ['bar'], { bar: 'bar' });22export class Foo {23 public bar: string;24}25import { createIIFE } from 'ts-auto-mock';26import { Foo } from './foo';27const foo: Foo = createIIFE<Foo>(['bar'], ['bar'], { bar: 'bar' }, true);28export class Foo {29 public bar: string;30}31import { createIIFE } from 'ts-auto-mock';32import { Foo } from './foo';33const foo: Foo = createIIFE<Foo>(['bar'], ['bar'], { bar: 'bar' }, true, 1);34export class Foo {35 public bar: string;36}37import { createIIFE } from 'ts-auto-mock';38import { Foo } from './foo';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { createIIFE } from 'ts-auto-mock';2import { mock } from 'ts-mock-imports';3import { myModule } from 'myModule';4describe('test1', () => {5 it('should work', () => {6 const mockedMyModule = createIIFE(myModule);7 mockedMyModule.myFunction.mockReturnValue('mocked');8 const mockedMyModule = mock(myModule);9 mockedMyModule.myFunction.mockReturnValue('mocked');10 });11});12import { createIIFE } from 'ts-auto-mock';13import { mock } from 'ts-mock-imports';14import { myModule } from 'myModule';15describe('test2', () => {16 it('should work', () => {17 const mockedMyModule = createIIFE(myModule);18 mockedMyModule.myFunction.mockReturnValue('mocked');19 const mockedMyModule = mock(myModule);20 mockedMyModule.myFunction.mockReturnValue('mocked');21 });22});23import { createIIFE } from 'ts-auto-mock';24import { mock } from 'ts-mock-imports';25import { myModule } from 'myModule';26describe('test3', () => {27 it('should work', () => {28 const mockedMyModule = createIIFE(myModule);29 mockedMyModule.myFunction.mockReturnValue('mocked');30 const mockedMyModule = mock(myModule);31 mockedMyModule.myFunction.mockReturnValue('mocked');32 });33});34import { createIIFE } from 'ts-auto-mock';35import

Full Screen

Using AI Code Generation

copy

Full Screen

1import { createIIFE } from 'ts-auto-mock';2const { mock } = createIIFE('test1');3const result = mock<test1>();4console.log(result);5import { createIIFE } from 'ts-auto-mock';6const { mock } = createIIFE('test2');7const result = mock<test2>();8console.log(result);9import { createIIFE } from 'ts-auto-mock';10const { mock } = createIIFE('test3');11const result = mock<test3>();12console.log(result);13import { createIIFE } from 'ts-auto-mock';14const { mock } = createIIFE('test4');15const result = mock<test4>();16console.log(result);17import { createIIFE } from 'ts-auto-mock';18const { mock } = createIIFE('test5');19const result = mock<test5>();20console.log(result);21import { createIIFE } from 'ts-auto-mock';22const { mock } = createIIFE('test6');23const result = mock<test6>();24console.log(result);25import { createIIFE } from 'ts-auto-mock';26const { mock } = createIIFE('test7');27const result = mock<test7>();28console.log(result);29import { createIIFE } from 'ts-auto-mock';30const { mock } = createIIFE('test8');31const result = mock<test8>();32console.log(result);33import { createIIFE } from 'ts-auto-mock';34const { mock } = createIIFE('test9');35const result = mock<test9>();

Full Screen

Using AI Code Generation

copy

Full Screen

1import { createIIFE } from 'ts-auto-mock';2const mock = createIIFE('test1');3import { createIIFE } from 'ts-auto-mock';4const mock = createIIFE('test2');5import { createIIFE } from 'ts-auto-mock';6const mock = createIIFE('test3');7import { createIIFE } from 'ts-auto-mock';8const mock = createIIFE('test4');9import { createIIFE } from 'ts-auto-mock';10const mock = createIIFE('test5');11import { createIIFE } from 'ts-auto-mock';12const mock = createIIFE('test6');13import { createIIFE } from 'ts-auto-mock';14const mock = createIIFE('test7');15import { createIIFE } from 'ts-auto-mock';16const mock = createIIFE('test8');17import { createIIFE } from 'ts-auto

Full Screen

Using AI Code Generation

copy

Full Screen

1import { createIIFE } from 'ts-auto-mock';2const mock = createIIFE<Interface>();3import { createMock } from 'ts-auto-mock';4const mock = createMock<Interface>();5import { createMock } from 'ts-auto-mock';6const mock = createMock<Interface>(true);7import { createMock } from 'ts-auto-mock';8const mock = createMock<Interface>(false);9import { createMock } from 'ts-auto-mock';10const mock = createMock<Interface>(true, true);11import { createMock } from 'ts-auto-mock';12const mock = createMock<Interface>(false, true);

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ts-auto-mock automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful