How to use scenarioName method in mountebank

Best JavaScript code snippet using mountebank

cache.js

Source:cache.js Github

copy

Full Screen

1const fs = require(`fs-extra`)2const { spawnSync } = require(`child_process`)3const path = require(`path`)4const os = require(`os`)5const _ = require(`lodash`)6const {7 ON_PRE_BOOTSTRAP_FILE_PATH,8 ON_POST_BUILD_FILE_PATH,9} = require(`../utils/constants`)10const { selectConfiguration } = require(`../utils/select-configuration`)11const { loadState } = require(`../utils/load-state`)12const { diff } = require(`../utils/nodes-diff`)13const getNodesSubStateByPlugins = (state, pluginNamesArray) =>14 _.mapValues(state.nodes, stateShard => {15 const filteredMap = new Map()16 stateShard.forEach(node => {17 if (pluginNamesArray.includes(node.internal.owner)) {18 filteredMap.set(node.id, node)19 }20 })21 return filteredMap22 })23const getDiskCacheSnapshotSubStateByPlugins = (state, pluginNamesArray) =>24 _.mapValues(state.diskCacheSnapshot, stateShard =>25 _.pick(stateShard, pluginNamesArray)26 )27jest.setTimeout(100000)28const gatsbyBin = path.join(`node_modules`, `gatsby`, `cli.js`)29const { compareState } = require(`../utils/nodes-diff`)30const stdio = `inherit`31const build = ({ updatePlugins } = {}) => {32 spawnSync(process.execPath, [gatsbyBin, `clean`], { stdio })33 selectConfiguration(1)34 let processOutput35 // First run, get state36 processOutput = spawnSync(process.execPath, [gatsbyBin, `build`], {37 stdio,38 env: {39 ...process.env,40 NODE_ENV: `production`,41 },42 })43 if (processOutput.status !== 0) {44 throw new Error(`Gatsby exited with non zero code`)45 }46 const preBootstrapStateFromFirstRun = loadState(ON_PRE_BOOTSTRAP_FILE_PATH)47 const postBuildStateFromFirstRun = loadState(ON_POST_BUILD_FILE_PATH)48 if (updatePlugins) {49 // Invalidations50 selectConfiguration(2)51 }52 // Second run, get state and compare with state from previous run53 processOutput = spawnSync(process.execPath, [gatsbyBin, `build`], {54 stdio,55 env: {56 ...process.env,57 NODE_ENV: `production`,58 },59 })60 if (processOutput.status !== 0) {61 throw new Error(`Gatsby exited with non zero code`)62 }63 const preBootstrapStateFromSecondRun = loadState(ON_PRE_BOOTSTRAP_FILE_PATH)64 const postBuildStateFromSecondRun = loadState(ON_POST_BUILD_FILE_PATH)65 return {66 nodes: {67 preBootstrapStateFromFirstRun: preBootstrapStateFromFirstRun.nodes,68 postBuildStateFromFirstRun: postBuildStateFromFirstRun.nodes,69 preBootstrapStateFromSecondRun: preBootstrapStateFromSecondRun.nodes,70 postBuildStateFromSecondRun: postBuildStateFromSecondRun.nodes,71 },72 diskCacheSnapshot: {73 preBootstrapStateFromFirstRun:74 preBootstrapStateFromFirstRun.diskCacheSnapshot,75 postBuildStateFromFirstRun: postBuildStateFromFirstRun.diskCacheSnapshot,76 preBootstrapStateFromSecondRun:77 preBootstrapStateFromSecondRun.diskCacheSnapshot,78 postBuildStateFromSecondRun:79 postBuildStateFromSecondRun.diskCacheSnapshot,80 },81 queryResults: {82 firstRun: postBuildStateFromFirstRun.queryResults,83 secondRun: postBuildStateFromSecondRun.queryResults,84 },85 }86}87beforeAll(async () => {88 selectConfiguration(1)89})90afterAll(() => {91 // go back to initial92 selectConfiguration(1)93 // delete saved states94 if (fs.existsSync(ON_PRE_BOOTSTRAP_FILE_PATH)) {95 fs.unlinkSync(ON_PRE_BOOTSTRAP_FILE_PATH)96 }97 if (fs.existsSync(ON_POST_BUILD_FILE_PATH)) {98 fs.unlinkSync(ON_POST_BUILD_FILE_PATH)99 }100})101describe(`nothing changed between gatsby runs`, () => {102 let states103 beforeAll(() => {104 states = build({105 updatePlugins: false,106 })107 })108 describe(`Nodes`, () => {109 it(`nodes are persisted between builds when nothing changes`, () => {110 const {111 nodes: {112 preBootstrapStateFromFirstRun,113 postBuildStateFromFirstRun,114 preBootstrapStateFromSecondRun,115 postBuildStateFromSecondRun,116 },117 } = states118 expect(preBootstrapStateFromFirstRun.size).toEqual(0)119 // sanity check to make sure there are any nodes after first run120 expect(postBuildStateFromFirstRun.size).toBeGreaterThan(0)121 // no nodes where invalidated if nothing changes122 expect(postBuildStateFromFirstRun).toEqual(preBootstrapStateFromSecondRun)123 // final nodes store is the same after first and second run124 expect(postBuildStateFromFirstRun).toEqual(postBuildStateFromSecondRun)125 })126 })127})128describe(`Some plugins changed between gatsby runs`, () => {129 let states130 beforeAll(() => {131 states = build({132 updatePlugins: true,133 })134 })135 describe(`Nodes`, () => {136 const getNodesTestArgs = (states, plugins) => {137 const nodesSubState = getNodesSubStateByPlugins(states, plugins)138 return {139 ...nodesSubState,140 compareState,141 }142 }143 it(`Sanity checks`, () => {144 // preconditions - we expect our cache to be empty on first run145 expect(states.nodes.preBootstrapStateFromFirstRun.size).toEqual(0)146 })147 describe(`Source plugins without transformers`, () => {148 it(`Not changing plugin doesn't invalidate nodes created by it`, () => {149 const {150 plugins,151 nodesTest,152 } = require(`../plugins/source/no-changes/scenario`)153 nodesTest(getNodesTestArgs(states, plugins))154 })155 it(`Adding plugin adds new node`, () => {156 const {157 plugins,158 nodesTest,159 } = require(`../plugins/source/plugin-added/scenario`)160 nodesTest(getNodesTestArgs(states, plugins))161 })162 it(`Removing plugin clears nodes owned by it`, () => {163 const {164 plugins,165 nodesTest,166 } = require(`../plugins/source/plugin-removed/scenario`)167 nodesTest(getNodesTestArgs(states, plugins))168 })169 it(`Changing plugin clears nodes owned by it and recreate nodes`, () => {170 const {171 plugins,172 nodesTest,173 } = require(`../plugins/source/plugin-changed/scenario`)174 nodesTest(getNodesTestArgs(states, plugins))175 })176 })177 describe(`Source plugins with transformers (child nodes)`, () => {178 describe(`Changes to source plugins`, () => {179 it(`Adding source plugin cause transformers to create child nodes`, () => {180 const {181 plugins,182 nodesTest,183 } = require(`../plugins/source-and-transformers-child-nodes/source-added/scenario`)184 nodesTest(getNodesTestArgs(states, plugins))185 })186 it(`Removing source plugin invalidate nodes owned by it and all children nodes`, () => {187 const {188 plugins,189 nodesTest,190 } = require(`../plugins/source-and-transformers-child-nodes/source-removed/scenario`)191 nodesTest(getNodesTestArgs(states, plugins))192 })193 it(`Changing source plugin invalidate nodes owned by it and all children nodes and recreates all nodes`, () => {194 const {195 plugins,196 nodesTest,197 } = require(`../plugins/source-and-transformers-child-nodes/source-changed/scenario`)198 nodesTest(getNodesTestArgs(states, plugins))199 })200 })201 describe(`Changes to transformer plugins`, () => {202 it(`Adding transformer adds child nodes to existing nodes`, () => {203 const {204 plugins,205 nodesTest,206 } = require(`../plugins/source-and-transformers-child-nodes/transformer-added/scenario`)207 nodesTest(getNodesTestArgs(states, plugins))208 })209 it(`Removing transformer clear nodes owned by it and remove children from parent nodes`, () => {210 const {211 plugins,212 nodesTest,213 } = require(`../plugins/source-and-transformers-child-nodes/transformer-removed/scenario`)214 nodesTest(getNodesTestArgs(states, plugins))215 })216 it(`Changing transformer clears and recreates nodes owned by it`, () => {217 const {218 plugins,219 nodesTest,220 } = require(`../plugins/source-and-transformers-child-nodes/transformer-changed/scenario`)221 nodesTest(getNodesTestArgs(states, plugins))222 })223 })224 })225 describe(`Source plugins with transformers (node fields)`, () => {226 describe(`Changes to source plugins`, () => {227 it(`Adding source plugin creates a node with fields`, () => {228 const {229 plugins,230 nodesTest,231 } = require(`../plugins/source-and-transformers-node-fields/source-added/scenario`)232 nodesTest(getNodesTestArgs(states, plugins))233 })234 it(`Changing source plugin clears and recreates nodes owned by it`, () => {235 const {236 plugins,237 nodesTest,238 } = require(`../plugins/source-and-transformers-node-fields/source-changed/scenario`)239 nodesTest(getNodesTestArgs(states, plugins))240 })241 })242 describe(`Changes to transformer plugins`, () => {243 it(`Adding transformer adds fields to node created by source plugin`, () => {244 const {245 plugins,246 nodesTest,247 } = require(`../plugins/source-and-transformers-node-fields/transformer-added/scenario`)248 nodesTest(getNodesTestArgs(states, plugins))249 })250 it(`Removing transformer removes fields from node created by source plugin`, () => {251 const {252 plugins,253 nodesTest,254 } = require(`../plugins/source-and-transformers-node-fields/transformer-removed/scenario`)255 nodesTest(getNodesTestArgs(states, plugins))256 })257 it(`Changing transformer removes fields from node created by source plugin and recreate fields`, () => {258 const {259 plugins,260 nodesTest,261 } = require(`../plugins/source-and-transformers-node-fields/transformer-changed/scenario`)262 nodesTest(getNodesTestArgs(states, plugins))263 })264 })265 })266 })267 describe(`Persisted key-value store (cache)`, () => {268 it(`Preserve disk cache if owner plugin did not changed`, () => {269 const {270 persistedKeyValueStoreTest,271 plugins,272 } = require(`../plugins/key-value-cache/no-changes/scenario`)273 persistedKeyValueStoreTest(274 getDiskCacheSnapshotSubStateByPlugins(states, plugins)275 )276 })277 it(`Removing owner plugin clears disk cache`, () => {278 const {279 persistedKeyValueStoreTest,280 plugins,281 } = require(`../plugins/key-value-cache/plugin-removed/scenario`)282 persistedKeyValueStoreTest(283 getDiskCacheSnapshotSubStateByPlugins(states, plugins)284 )285 })286 it(`Adding owner plugin creates disk cache`, () => {287 const {288 persistedKeyValueStoreTest,289 plugins,290 } = require(`../plugins/key-value-cache/plugin-added/scenario`)291 persistedKeyValueStoreTest(292 getDiskCacheSnapshotSubStateByPlugins(states, plugins)293 )294 })295 it(`Changing owner plugin clears disk cache and recreates it`, () => {296 const {297 persistedKeyValueStoreTest,298 plugins,299 } = require(`../plugins/key-value-cache/plugin-changed/scenario`)300 persistedKeyValueStoreTest(301 getDiskCacheSnapshotSubStateByPlugins(states, plugins)302 )303 })304 })305 describe(`Query results`, () => {306 const getQueryResultTestArgs = scenarioName => {307 if (os.platform() === "win32") {308 scenarioName = scenarioName.replace("/", "\\")309 }310 const result = {311 dataFirstRun: states.queryResults.firstRun[scenarioName].data,312 dataSecondRun: states.queryResults.secondRun[scenarioName].data,313 typesFirstRun: states.queryResults.firstRun[scenarioName].types,314 typesSecondRun: states.queryResults.secondRun[scenarioName].types,315 }316 if (result.dataFirstRun && result.dataSecondRun) {317 result.dataDiff = diff(result.dataFirstRun, result.dataSecondRun)318 }319 if (result.typesFirstRun && result.typesSecondRun) {320 result.typesDiff = diff(result.typesFirstRun, result.typesSecondRun)321 }322 return result323 }324 describe(`Source plugins without transformers`, () => {325 it(`Not changing plugin doesn't change query results`, () => {326 const scenarioName = `source/no-changes`327 const { queriesTest } = require(`../plugins/${scenarioName}/scenario`)328 queriesTest(getQueryResultTestArgs(scenarioName))329 })330 it(`Adding plugin adds a type to schema`, () => {331 const scenarioName = `source/plugin-added`332 const { queriesTest } = require(`../plugins/${scenarioName}/scenario`)333 queriesTest(getQueryResultTestArgs(scenarioName))334 })335 it(`Removing plugin removes a type from schema`, () => {336 const scenarioName = `source/plugin-removed`337 const { queriesTest } = require(`../plugins/${scenarioName}/scenario`)338 queriesTest(getQueryResultTestArgs(scenarioName))339 })340 it(`Changing plugin invalidates query results`, () => {341 const scenarioName = `source/plugin-changed`342 const { queriesTest } = require(`../plugins/${scenarioName}/scenario`)343 queriesTest(getQueryResultTestArgs(scenarioName))344 })345 })346 describe(`Source plugins with transformers`, () => {347 describe(`Changes to source plugins`, () => {348 it(`Adding source plugin creates parent and child types in schema and they are queryable on second run`, () => {349 const scenarioName = `source-and-transformers-child-nodes/source-added`350 const { queriesTest } = require(`../plugins/${scenarioName}/scenario`)351 queriesTest(getQueryResultTestArgs(scenarioName))352 })353 it(`Removing source plugin removes parent and child types from schema and they are queryable on first run`, () => {354 const scenarioName = `source-and-transformers-child-nodes/source-removed`355 const { queriesTest } = require(`../plugins/${scenarioName}/scenario`)356 queriesTest(getQueryResultTestArgs(scenarioName))357 })358 it(`Changing source plugin adjust schema and query result changes just certain fields`, () => {359 const scenarioName = `source-and-transformers-child-nodes/source-changed`360 const { queriesTest } = require(`../plugins/${scenarioName}/scenario`)361 queriesTest(getQueryResultTestArgs(scenarioName))362 })363 })364 describe(`Changes to transformer plugins`, () => {365 it(`Adding transformer plugin adds child type to schema and updates query result`, () => {366 const scenarioName = `source-and-transformers-child-nodes/transformer-added`367 const { queriesTest } = require(`../plugins/${scenarioName}/scenario`)368 queriesTest(getQueryResultTestArgs(scenarioName))369 })370 it(`Removing transformer plugin removes child type from schema and updates query result`, () => {371 const scenarioName = `source-and-transformers-child-nodes/transformer-removed`372 const { queriesTest } = require(`../plugins/${scenarioName}/scenario`)373 queriesTest(getQueryResultTestArgs(scenarioName))374 })375 it(`Changing transformer plugin adjusts schema and query result changes just certain fields`, () => {376 const scenarioName = `source-and-transformers-child-nodes/transformer-changed`377 const { queriesTest } = require(`../plugins/${scenarioName}/scenario`)378 queriesTest(getQueryResultTestArgs(scenarioName))379 })380 })381 })382 describe(`Source plugins with transformers (node fields)`, () => {383 describe(`Changes to source plugins`, () => {384 it(`Adding source plugin creates node and node field types in schema and they are queryable on second run`, () => {385 const scenarioName = `source-and-transformers-node-fields/source-added`386 const { queriesTest } = require(`../plugins/${scenarioName}/scenario`)387 queriesTest(getQueryResultTestArgs(scenarioName))388 })389 it(`Changing source plugin adjusts schema and they are queryable on second run`, () => {390 const scenarioName = `source-and-transformers-node-fields/source-changed`391 const { queriesTest } = require(`../plugins/${scenarioName}/scenario`)392 queriesTest(getQueryResultTestArgs(scenarioName))393 })394 })395 describe(`Changes to transformer plugins`, () => {396 it(`Adding transformer plugin adds fields type to schema and updates query result`, () => {397 const scenarioName = `source-and-transformers-node-fields/transformer-added`398 const { queriesTest } = require(`../plugins/${scenarioName}/scenario`)399 queriesTest(getQueryResultTestArgs(scenarioName))400 })401 it(`Removing transformer plugin removes fields type from schema and updates query result`, () => {402 const scenarioName = `source-and-transformers-node-fields/transformer-removed`403 const { queriesTest } = require(`../plugins/${scenarioName}/scenario`)404 queriesTest(getQueryResultTestArgs(scenarioName))405 })406 it(`Changing transformer plugin adjusts schema and query result changes just certain fields`, () => {407 const scenarioName = `source-and-transformers-node-fields/transformer-changed`408 const { queriesTest } = require(`../plugins/${scenarioName}/scenario`)409 queriesTest(getQueryResultTestArgs(scenarioName))410 })411 })412 })413 })...

Full Screen

Full Screen

utils.ts

Source:utils.ts Github

copy

Full Screen

1import { material, project } from '@alilc/lowcode-engine';2import { filterPackages } from '@alilc/lowcode-plugin-inject'3import { Message, Dialog } from '@alifd/next';4import { TransformStage } from '@alilc/lowcode-types';5export const loadIncrementalAssets = () => {6 material?.onChangeAssets(() => {7 Message.success('[MCBreadcrumb] 物料加载成功');8 });9 material.loadIncrementalAssets({10 packages: [11 {12 title: 'MCBreadcrumb',13 package: 'mc-breadcrumb',14 version: '1.0.0',15 urls: [16 'https://unpkg.alibaba-inc.com/mc-breadcrumb@1.0.0/dist/MCBreadcrumb.js',17 'https://unpkg.alibaba-inc.com/mc-breadcrumb@1.0.0/dist/MCBreadcrumb.css',18 ],19 library: 'MCBreadcrumb',20 },21 ],22 components: [23 {24 componentName: 'MCBreadcrumb',25 title: 'MCBreadcrumb',26 docUrl: '',27 screenshot: '',28 npm: {29 package: 'mc-breadcrumb',30 version: '1.0.0',31 exportName: 'MCBreadcrumb',32 main: 'lib/index.js',33 destructuring: false,34 subName: '',35 },36 props: [37 {38 name: 'prefix',39 propType: 'string',40 description: '样式类名的品牌前缀',41 defaultValue: 'next-',42 },43 {44 name: 'title',45 propType: 'string',46 description: '标题',47 defaultValue: 'next-',48 },49 {50 name: 'rtl',51 propType: 'bool',52 },53 {54 name: 'children',55 propType: {56 type: 'instanceOf',57 value: 'node',58 },59 description: '面包屑子节点,需传入 Breadcrumb.Item',60 },61 {62 name: 'maxNode',63 propType: {64 type: 'oneOfType',65 value: [66 'number',67 {68 type: 'oneOf',69 value: ['auto'],70 },71 ],72 },73 description:74 '面包屑最多显示个数,超出部分会被隐藏, 设置为 auto 会自动根据父元素的宽度适配。',75 defaultValue: 100,76 },77 {78 name: 'separator',79 propType: {80 type: 'instanceOf',81 value: 'node',82 },83 description: '分隔符,可以是文本或 Icon',84 },85 {86 name: 'component',87 propType: {88 type: 'oneOfType',89 value: ['string', 'func'],90 },91 description: '设置标签类型',92 defaultValue: 'nav',93 },94 {95 name: 'className',96 propType: 'any',97 },98 {99 name: 'style',100 propType: 'object',101 },102 ],103 configure: {104 component: {105 isContainer: true,106 isModel: true,107 rootSelector: 'div.MCBreadcrumb',108 },109 },110 },111 ],112 componentList: [113 {114 title: '常用',115 icon: '',116 children: [117 {118 componentName: 'MCBreadcrumb',119 title: 'MC面包屑',120 icon: '',121 package: 'mc-breadcrumb',122 library: 'MCBreadcrumb',123 snippets: [124 {125 title: 'MC面包屑',126 screenshot:127 'https://alifd.oss-cn-hangzhou.aliyuncs.com/fusion-cool/icons/icon-light/ic_light_breadcrumb.png',128 schema: {129 componentName: 'MCBreadcrumb',130 props: {131 title: '物料中心',132 prefix: 'next-',133 maxNode: 100,134 },135 },136 },137 ],138 },139 ],140 },141 ],142 });143};144export const preview = (scenarioName: string = 'index') => {145 saveSchema(scenarioName);146 setTimeout(() => {147 const search = location.search ? `${location.search}&scenarioName=${scenarioName}` : `?scenarioName=${scenarioName}`;148 window.open(`./preview.html${search}`);149 }, 500);150};151export const saveSchema = async (scenarioName: string = 'index') => {152 setProjectSchemaToLocalStorage(scenarioName);153 await setPackgesToLocalStorage(scenarioName);154 // window.localStorage.setItem(155 // 'projectSchema',156 // JSON.stringify(project.exportSchema(TransformStage.Save))157 // );158 // const packages = await filterPackages(material.getAssets().packages);159 // window.localStorage.setItem(160 // 'packages',161 // JSON.stringify(packages)162 // );163 Message.success('成功保存到本地');164};165export const resetSchema = async (scenarioName: string = 'index') => {166 try {167 await new Promise<void>((resolve, reject) => {168 Dialog.confirm({169 content: '确定要重置吗?您所有的修改都将消失!',170 onOk: () => {171 resolve();172 },173 onCancel: () => {174 reject()175 },176 })177 })178 } catch(err) {179 return180 }181 // 除了「综合场景」,其他场景没有默认 schema.json,这里构造空页面182 if (scenarioName !== 'index') {183 window.localStorage.setItem(184 getLSName(scenarioName),185 JSON.stringify({186 componentsTree: [{ componentName: 'Page', fileName: 'sample' }],187 componentsMap: material.componentsMap,188 version: '1.0.0',189 i18n: {},190 })191 );192 project.getCurrentDocument()?.importSchema({ componentName: 'Page', fileName: 'sample' });193 project.simulatorHost?.rerender();194 Message.success('成功重置页面');195 return;196 }197 let schema;198 try {199 schema = await request('./schema.json')200 } catch(err) {201 schema = {202 componentName: 'Page',203 fileName: 'sample',204 }205 }206 window.localStorage.setItem(207 getLSName('index'),208 JSON.stringify({209 componentsTree: [schema],210 componentsMap: material.componentsMap,211 version: '1.0.0',212 i18n: {},213 })214 );215 project.getCurrentDocument()?.importSchema(schema);216 project.simulatorHost?.rerender();217 Message.success('成功重置页面');218}219const getLSName = (scenarioName: string, ns: string = 'projectSchema') => `${scenarioName}:${ns}`;220export const getProjectSchemaFromLocalStorage = (scenarioName: string) => {221 if (!scenarioName) {222 console.error('scenarioName is required!');223 return;224 }225 return JSON.parse(window.localStorage.getItem(getLSName(scenarioName)) || '{}');226}227const setProjectSchemaToLocalStorage = (scenarioName: string) => {228 if (!scenarioName) {229 console.error('scenarioName is required!');230 return;231 }232 window.localStorage.setItem(233 getLSName(scenarioName),234 JSON.stringify(project.exportSchema(TransformStage.Save))235 );236}237const setPackgesToLocalStorage = async (scenarioName: string) => {238 if (!scenarioName) {239 console.error('scenarioName is required!');240 return;241 }242 const packages = await filterPackages(material.getAssets().packages);243 window.localStorage.setItem(244 getLSName(scenarioName, 'packages'),245 JSON.stringify(packages),246 );247}248export const getPackagesFromLocalStorage = (scenarioName: string) => {249 if (!scenarioName) {250 console.error('scenarioName is required!');251 return;252 }253 return JSON.parse(window.localStorage.getItem(getLSName(scenarioName, 'packages')) || '{}');254}255export const getPageSchema = async (scenarioName: string = 'index') => {256 const pageSchema = getProjectSchemaFromLocalStorage(scenarioName).componentsTree?.[0]257 if (pageSchema) {258 return pageSchema;259 }260 return await request('./schema.json');261};262function request(263 dataAPI: string,264 method = 'GET',265 data?: object | string,266 headers?: object,267 otherProps?: any,268): Promise<any> {269 return new Promise((resolve, reject): void => {270 if (otherProps && otherProps.timeout) {271 setTimeout((): void => {272 reject(new Error('timeout'));273 }, otherProps.timeout);274 }275 fetch(dataAPI, {276 method,277 credentials: 'include',278 headers,279 body: data,280 ...otherProps,281 })282 .then((response: Response): any => {283 switch (response.status) {284 case 200:285 case 201:286 case 202:287 return response.json();288 case 204:289 if (method === 'DELETE') {290 return {291 success: true,292 };293 } else {294 return {295 __success: false,296 code: response.status,297 };298 }299 case 400:300 case 401:301 case 403:302 case 404:303 case 406:304 case 410:305 case 422:306 case 500:307 return response308 .json()309 .then((res: object): any => {310 return {311 __success: false,312 code: response.status,313 data: res,314 };315 })316 .catch((): object => {317 return {318 __success: false,319 code: response.status,320 };321 });322 default:323 return null;324 }325 })326 .then((json: any): void => {327 if (json && json.__success !== false) {328 resolve(json);329 } else {330 delete json.__success;331 reject(json);332 }333 })334 .catch((err: Error): void => {335 reject(err);336 });337 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var scenarioName = mb.scenarioName;3var port = 2525;4 {5 {6 {7 equals: {8 }9 }10 {11 is: {12 headers: {13 }14 }15 }16 }17 }18];19mb.create({ imposters: imposters }, function (error, server) {20 console.log('Server started on port ' + server.port);21 var request = require('request');22 console.log('Response from first request: ' + body);23 console.log('Response from second request: ' + body);24 server.close(function () {25 console.log('Server closed');26 });27 });28 });29});30var mb = require('mountebank');31var scenarioName = mb.scenarioName;32var port = 2525;33 {34 {35 {36 equals: {37 }38 }39 {40 is: {41 headers: {42 }43 }44 }45 },46 {47 {48 equals: {49 }50 }51 {52 is: {53 headers: {54 }55 }56 }57 }58 }59];

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var server = mb.create({3});4server.then(function (server) {5 server.createImposter({ protocol: 'http', port: 3000, name: 'test' });6});7var stub = {8 {9 is: {10 headers: { 'Content-Type': 'text/html' },11 }12 }13};14server.then(function (server) {15 server.addStub(3000, stub);16});17var scenario = {18 {19 {20 equals: { method: 'GET', path: '/test' }21 }22 {23 is: {24 headers: { 'Content-Type': 'text/html' },25 }26 }27 }28};29server.then(function (server) {30 server.addStub(3000, scenario);31});32var scenario = {33 {34 {35 equals: { method: 'GET', path: '/test' }36 }37 {38 is: {39 headers: { 'Content-Type': 'text/html' },40 }41 }42 }43};44server.then(function (server) {45 server.addStub(3000, scenario);46});47server.then(function (server) {48 server.scenarioName(3000, 'test');49});50server.then(function (server) {51 server.scenarioState(3000, 'test', 'state1');52});53server.then(function (server) {54 server.getImposter(300

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var scenarioName = mb.scenarioName;3var imposter = {4 {5 {6 is: {7 headers: {8 },9 }10 }11 }12};13mb.create(imposter)14 .then(function (response) {15 return mb.get('/imposters');16 })17 .then(function (response) {18 console.log('Imposters:', response.body);19 return mb.del('/imposters/4545');20 })21 .then(function (response) {22 console.log('Imposter deleted');23 })24 .catch(function (error) {25 console.error('Error:', error.message);26 });27var imposter = {28 {29 {30 is: {31 headers: {32 },33 }34 }35 {36 equals: {37 query: {38 },39 headers: {40 }41 }42 }43 }44 {45 {46 {47 is: {48 headers: {49 },50 }51 }52 {53 equals: {54 query: {55 },56 headers: {57 }58 }59 }60 }61 }62};63mb.create(imposter)64 .then(function (response) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var mbHelper = mb.create('localhost', 2525);3mbHelper.get('/imposters').then(function (response) {4 console.log(response.body);5});6var mb = require('mountebank');7var mbHelper = mb.create('localhost', 2525);8mbHelper.get('/imposters').then(function (response) {9 console.log(response.body);10});11var mb = require('mountebank');12var mbHelper = mb.create('localhost', 2525);13mbHelper.get('/imposters').then(function (response) {14 console.log(response.body);15});16var mb = require('mountebank');17var mbHelper = mb.create('localhost', 2525);18mbHelper.get('/imposters').then(function (response) {19 console.log(response.body);20});21var mb = require('mountebank');22var mbHelper = mb.create('localhost', 2525);23mbHelper.get('/imposters').then(function (response) {24 console.log(response.body);25});26var mb = require('mountebank');27var mbHelper = mb.create('localhost', 2525);28mbHelper.get('/imposters').then(function (response) {29 console.log(response.body);30});31var mb = require('mountebank');32var mbHelper = mb.create('localhost', 2525);33mbHelper.get('/imposters').then(function (response) {34 console.log(response.body);35});36var mb = require('mountebank');37var mbHelper = mb.create('localhost', 2525);38mbHelper.get('/imposters').then(function (response) {39 console.log(response.body);40});41var mb = require('mountebank');

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var scenarioName = mb.scenarioName;3var port = 2525;4mb.create(port, function () {5mb.post('/test', {6scenarioName: scenarioName('test'),7{ is: { body: 'Hello, World!' } }8});9mb.get('/test', function (err, res) {10});11});12var mb = require('mountebank').create();13var port = 2525;14mb.create(port, function () {15mb.post('/test', {16{ is: { body: 'Hello, World!' } }17});18mb.get('/test', function (err, res) {19});20});

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 mountebank 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