How to use fsExtra method in mountebank

Best JavaScript code snippet using mountebank

plantumltoimage.js

Source:plantumltoimage.js Github

copy

Full Screen

1/*2 * Licensed under the Apache License, Version 2.0 (the "License");3 * you may not use this file except in compliance with the License.4 * You may obtain a copy of the License at5 *6 * http://www.apache.org/licenses/LICENSE-2.07 *8 * Unless required by applicable law or agreed to in writing, software9 * distributed under the License is distributed on an "AS IS" BASIS,10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11 * See the License for the specific language governing permissions and12 * limitations under the License.13 */14'use strict';15const sinon = require('sinon');16const chai = require('chai');17chai.should();18chai.use(require('chai-things'));19chai.use(require('chai-as-promised'));20const path = require('path');21const yargs = require('yargs');22const mockery = require('mockery');23describe('PlantUmlToImage', () => {24 let sandbox;25 let fsextraStubs = {};26 let statsStub = {};27 let consoleErrorStub;28 let processExitStub;29 let pathStub;30 let pipeSpy;31 beforeEach(() => {32 mockery.enable({33 warnOnReplace: false,34 warnOnUnregistered: false35 });36 sandbox = sinon.sandbox.create();37 // setup the stubs for handling yargs and the process exit38 sandbox.stub(yargs, 'options').returns(yargs(['--inputDir=path/to/dir', '--outputDir=path/to/output', '--format=svg']));39 sandbox.stub(yargs, 'usage').returns(yargs);40 sandbox.stub(yargs, 'argv').returns();41 processExitStub = sandbox.stub(process, 'exit');42 // Use Mockery to great effect to clean out the fs-extra and the plantuml43 // Allows greater control of what they need to fake44 // make a fake object that mockery will use, and provide it with sinon stubs45 fsextraStubs.readdir = sandbox.stub();46 fsextraStubs.ensureFileSync = sandbox.stub();47 fsextraStubs.statSync = sandbox.stub();48 fsextraStubs.createWriteStream = sandbox.stub();49 statsStub = { isDirectory: sandbox.stub(), isFile: sandbox.stub() };50 fsextraStubs.statSync.returns(statsStub);51 mockery.registerMock('fs-extra', fsextraStubs);52 pipeSpy = sinon.spy();53 // also crreate fake version of plantumkl54 mockery.registerMock('node-plantuml', {55 generate: function () {56 return { out: { pipe: pipeSpy } };57 }58 });59 pathStub = sandbox.stub(path, 'parse');60 // and get console to shutup61 consoleErrorStub = sandbox.stub(console,'error');62 });63 afterEach(() => {64 mockery.deregisterAll();65 sandbox.restore();66 });67 it('Should set up yargs correctly and log an error in the console if directory cannot be read', () => {68 delete require.cache[path.resolve(__dirname, '../../lib/tools/plantumltoimage.js')];69 require('../../lib/tools/plantumltoimage.js');70 // trigger the callback for the list of files71 fsextraStubs.readdir.yield('Directory cannot be read', []);72 consoleErrorStub.should.have.been.calledWith('Could not list the directory.', 'Directory cannot be read');73 processExitStub.should.have.been.calledWith(1);74 });75 it('Should set up yargs correctly and not call other functions if elements are not a directory or file', function () {76 delete require.cache[path.resolve(__dirname, '../../lib/tools/plantumltoimage.js')];77 require('../../lib/tools/plantumltoimage.js');78 statsStub.isFile.returns(false);79 statsStub.isDirectory.returns(false);80 // trigger the callback for the list of files81 fsextraStubs.readdir.yield(null, ['dir1', 'dir2']);82 fsextraStubs.readdir.should.have.been.calledOnce;83 });84 it('Should set up yargs correctly and call processDirectory with each sub-directory', function () {85 delete require.cache[path.resolve(__dirname, '../../lib/tools/plantumltoimage.js')];86 require('../../lib/tools/plantumltoimage.js');87 statsStub.isDirectory.returns(true);88 // trigger the callback for the list of files89 fsextraStubs.readdir.yield(null, ['dir1', 'dir2']);90 fsextraStubs.readdir.should.have.been.calledThrice;91 fsextraStubs.readdir.getCall(1).args[0].should.include('path/to/dir/dir1');92 fsextraStubs.readdir.getCall(2).args[0].should.include('path/to/dir/dir2');93 });94 it('Should set up yargs correctly and call the processFile with each found file and do action when uml', function () {95 delete require.cache[path.resolve(__dirname, '../../lib/tools/plantumltoimage.js')];96 require('../../lib/tools/plantumltoimage.js');97 statsStub.isFile.returns(true);98 pathStub.callsFake((filepath) => {99 return {100 name: filepath.split('/').slice(-1),101 ext: '.uml'102 };103 });104 // trigger the callback with the list of files105 fsextraStubs.readdir.yield(null, ['file1.uml', 'file2.uml']);106 pathStub.should.have.been.calledTwice;107 pathStub.getCall(0).args.should.include('path/to/dir/file1.uml');108 pathStub.getCall(1).args.should.include('path/to/dir/file2.uml');109 fsextraStubs.ensureFileSync.should.have.been.calledTwice;110 fsextraStubs.ensureFileSync.getCall(0).args[0].should.deep.equal('path/to/output/file1.uml.svg');111 fsextraStubs.ensureFileSync.getCall(1).args[0].should.deep.equal('path/to/output/file2.uml.svg');112 fsextraStubs.createWriteStream.should.have.been.calledTwice;113 fsextraStubs.createWriteStream.getCall(0).args[0].should.deep.equal('path/to/output/file1.uml.svg');114 fsextraStubs.createWriteStream.getCall(1).args[0].should.deep.equal('path/to/output/file2.uml.svg');115 pipeSpy.should.have.been.calledTwice;116 });117 it('Should set up yargs correctly and call the processFile with each found file and not do action when not uml', function () {118 delete require.cache[path.resolve(__dirname, '../../lib/tools/plantumltoimage.js')];119 require('../../lib/tools/plantumltoimage.js');120 statsStub.isFile.returns(true);121 pathStub.callsFake((filepath) => {122 return {123 name: filepath.split('/').slice(-1),124 ext: '.txt'125 };126 });127 // trigger the callback with the list of files128 fsextraStubs.readdir.yield(null, ['file1.txt', 'file2.txt']);129 pathStub.should.have.been.calledTwice;130 pathStub.getCall(0).args.should.include('path/to/dir/file1.txt');131 pathStub.getCall(1).args.should.include('path/to/dir/file2.txt');132 pipeSpy.should.not.have.been.called;133 });...

Full Screen

Full Screen

cli.eject-helpers.test.js

Source:cli.eject-helpers.test.js Github

copy

Full Screen

1import consola from 'consola'2import fsExtra from 'fs-extra'3import { ejectTheme, ejectTemplates, ejectTemplate } from 'src/cli/commands/eject'4import * as utils from 'src/utils'5import { resetUtilMocks as _resetUtilMocks } from 'test-utils'6jest.mock('src/utils')7const resetUtilMocks = utilNames => _resetUtilMocks(utils, utilNames)8jest.mock('fs-extra')9describe('eject helpers', () => {10 beforeAll(() => resetUtilMocks())11 afterEach(() => jest.resetAllMocks())12 test('ejectTheme logs warning when source is empty', async () => {13 fsExtra.readFile.mockReturnValue(false)14 const nuxt = {}15 const options = {}16 const discoveryPath = '/var/nuxt'17 await ejectTheme(nuxt, options, discoveryPath)18 expect(fsExtra.readFile).toHaveBeenCalledTimes(1)19 expect(fsExtra.readFile).toHaveBeenCalledWith('/var/nuxt/theme.css')20 expect(consola.warn).toHaveBeenCalledTimes(1)21 expect(consola.warn).toHaveBeenCalledWith('Reading from theme.css returned empty content, eject aborted')22 })23 test('ejectTheme logs info when theme ejected', async () => {24 fsExtra.readFile.mockReturnValue(true)25 const nuxt = { options: { rootDir: '/var/nuxt' } }26 const options = {}27 const discoveryPath = '/var/nuxt'28 await ejectTheme(nuxt, options, discoveryPath)29 expect(fsExtra.appendFile).toHaveBeenCalledTimes(1)30 expect(fsExtra.appendFile).toHaveBeenCalledWith('/var/nuxt/nuxt.press.css', true)31 expect(consola.info).toHaveBeenCalledTimes(1)32 expect(consola.info).toHaveBeenCalledWith('Ejected to ./nuxt.press.css')33 })34 test('ejectTemplates creates main template dir', async () => {35 fsExtra.readFile.mockReturnValue(true)36 const nuxt = {37 options: {38 rootDir: '/var/nuxt',39 srcDir: '/var/nuxt',40 dir: {41 app: 'app'42 }43 }44 }45 const options = { appDir: 'test-dir' }46 const templates = []47 await ejectTemplates(nuxt, options, templates)48 expect(fsExtra.ensureDir).toHaveBeenCalledTimes(1)49 expect(fsExtra.ensureDir).toHaveBeenCalledWith('/var/nuxt/app/test-dir')50 })51 test('ejectTemplate logs warning when source is empty', async () => {52 fsExtra.readFile.mockReturnValue(false)53 const nuxt = {54 options: {55 rootDir: '/var/nuxt',56 srcDir: '/var/nuxt',57 dir: {58 app: 'app'59 }60 }61 }62 const options = { appDir: 'test-dir' }63 const template = { src: '/var/the/source', dst: 'the/destination' }64 const resolvedAppDir = undefined65 await ejectTemplate(nuxt, options, template, resolvedAppDir)66 expect(fsExtra.readFile).toHaveBeenCalledTimes(1)67 expect(fsExtra.readFile).toHaveBeenCalledWith('/var/the/source')68 expect(consola.warn).toHaveBeenCalledTimes(1)69 expect(consola.warn).toHaveBeenCalledWith('Reading source template file returned empty content, eject aborted for: ../the/source')70 })71 test('ejectTemplate logs info when template ejected', async () => {72 fsExtra.readFile.mockReturnValue(true)73 const nuxt = {74 options: {75 rootDir: '/var/nuxt',76 srcDir: '/var/nuxt',77 dir: {78 app: 'app'79 }80 }81 }82 const options = { appDir: 'test-dir' }83 const template = { src: 'the/source', dst: 'the/destination' }84 const resolvedAppDir = undefined85 await ejectTemplate(nuxt, options, template, resolvedAppDir)86 expect(consola.debug).toHaveBeenCalledTimes(1)87 expect(consola.debug).toHaveBeenCalledWith(`Ejecting template 'the/source' to '/var/nuxt/app/test-dir/the/destination'`)88 expect(fsExtra.readFile).toHaveBeenCalledTimes(1)89 expect(fsExtra.readFile).toHaveBeenCalledWith('the/source')90 expect(fsExtra.ensureDir).toHaveBeenCalledTimes(1)91 expect(fsExtra.ensureDir).toHaveBeenCalledWith('/var/nuxt/app/test-dir/the')92 expect(consola.info).toHaveBeenCalledTimes(1)93 expect(consola.info).toHaveBeenCalledWith('Ejected app/test-dir/the/destination')94 })...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const fs = require('fs-extra');2const mountebank = require('mountebank');3const path = require('path');4const mb = mountebank.create({5 pidfile: path.join(__dirname, 'mb.pid'),6 logfile: path.join(__dirname, 'mb.log'),7});8mb.start()9 .then(() => {10 console.log('Mountebank server started');11 return mb.post('/imposters', {12 {13 {14 is: {15 headers: {16 },17 body: JSON.stringify({ message: 'Hello World!' }),18 },19 },20 },21 });22 })23 .then(() => {24 console.log('Imposter created');25 return mb.get('/imposters');26 })27 .then((response) => {28 console.log('Imposter retrieved');29 const imposter = response.body[0];30 console.log(`Imposter port is ${imposter.port}`);31 return mb.delete(`/imposters/${imposter.port}`);32 })33 .then(() => {34 console.log('Imposter deleted');35 return mb.stop();36 })37 .then(() => {38 console.log('Mountebank server stopped');39 })40 .catch((error) => {41 console.error(error);42 process.exit(1);43 });

Full Screen

Using AI Code Generation

copy

Full Screen

1const fs = require('fs-extra');2const mb = require('mountebank');3const path = require('path');4const util = require('util');5const exec = util.promisify(require('child_process').exec);6const mbPath = path.join(__dirname, 'mb');7const mbConfigPath = path.join(__dirname, 'mb', 'mb.json');8const mbConfig = {9 pidfile: path.join(__dirname, 'mb', 'mb.pid'),10 logfile: path.join(__dirname, 'mb', 'mb.log'),11 protofile: path.join(__dirname, 'mb', 'mb.proto'),

Full Screen

Using AI Code Generation

copy

Full Screen

1var fs = require('fs-extra');2var mb = require('mountebank');3var path = require('path');4var port = 2525;5var imposter = {6 stubs: [{7 predicates: [{8 equals: {9 }10 }],11 responses: [{12 is: {13 headers: {14 },15 body: JSON.stringify({16 })17 }18 }]19 }]20};21var imposterPath = path.join(__dirname, 'imposter.json');22fs.writeJsonSync(imposterPath, imposter);23mb.create({ port: port, pidfile: 'mb.pid', logfile: 'mb.log', protofile: 'mb.proto' }, function (error, mb) {24 mb.startImposterFromFile(imposterPath, function (error, imposter) {25 console.log('Imposter started, with error: ' + error + ', and imposter: ' + JSON.stringify(imposter));26 });27});28var assert = require('assert');29var request = require('request');30describe('test', function () {31 it('should return 200', function (done) {32 assert.equal(response.statusCode, 200);33 done();34 });35 });36});

Full Screen

Using AI Code Generation

copy

Full Screen

1const fs = require('fs');2const path = require('path');3const mountebank = require('mountebank');4const mb = mountebank.create({ port: 2525, allowInjection: true, loglevel: 'debug', pidfile: 'mb.pid' });5mb.start()6.then(() => {7 console.log('mountebank started');8 {9 {10 {11 is: {12 headers: {13 }14 }15 }16 }17 }18 ];19 return mb.post('/imposters', imposters);20})21.then(response => {22 console.log('created imposter', response.body);23 return mb.get('/imposters');24})25.then(response => {26 console.log('imposters', response.body);27 return mb.del('/imposters');28})29.then(response => {30 console.log('deleted imposters', response.body);31 return mb.stop();32})33.then(() => {34 console.log('mountebank stopped');35 process.exit(0);36})37.catch(error => {38 console.error('mountebank error', error);39 process.exit(1);40});41fs.writeFile('mb.pid', 'Hello World!', function (err) {42 if (err) throw err;43 console.log('Saved!');44});45I can't reproduce this on Windows 10. What version of node are you using? Can you try with the latest LTS version (12.13.0)?

Full Screen

Using AI Code Generation

copy

Full Screen

1const fsExtra = require('fs-extra');2const mb = require('mountebank');3const port = 2525;4const impostersPath = './imposters';5const imposters = fsExtra.readJsonSync(impostersPath);6mb.start({ port, imposters }, () => {7 console.log(`Mountebank started on port ${port}`);8});9{10 {11 {12 {13 "is": {14 "headers": {15 },16 "body": "{\"status\": \"OK\"}"17 }18 }19 }20 }21}22const request = require('request');23const port = 2525;24 if (error) {25 console.log(error);26 } else {27 console.log(body);28 }29});30{ "status": "OK" }31{ "status": "OK" }32const request = require('request');33const port = 2525;34const stub = {35 {36 "is": {37 "headers": {38 },39 "body": "{\"status\": \"OK\"}"40 }41 }42};43request.post({

Full Screen

Using AI Code Generation

copy

Full Screen

1const fsExtra = require('fs-extra');2const path = require('path');3const mb = require('mountebank');4mb.start({5}, function () {6 fsExtra.copySync(path.join(__dirname, 'imposters'), path.join(__dirname, 'mb/imposters'));7});8mb.stop({pidfile: 'mb.pid'}, function () {9 fsExtra.removeSync(path.join(__dirname, 'mb'));10});

Full Screen

Using AI Code Generation

copy

Full Screen

1var fsExtra = require('fs-extra');2var path = require('path');3var fs = require('fs');4var mb = require('mountebank');5var imposter = {6 {7 {8 {9 equals: {10 headers: {11 },12 }13 }14 }15 {16 is: {17 headers: {18 },19 body: JSON.stringify({ "status": "success" })20 }21 }22 }23 };24var imposterPromise = mb.create(imposter);25imposterPromise.then(function (imposter) {26 console.log(imposter.port);27 console.log('imposter started');28}).catch(function (error) {29 console.log(error);30});31var imposter = {32 {33 {34 {35 equals: {36 headers: {37 },38 }39 }40 }41 {42 is: {43 headers: {44 },45 body: JSON.stringify({ "status": "success" })46 }47 }48 }49};50var imposterPromise = mb.create(imposter);51imposterPromise.then(function (imposter) {52 console.log(imposter.port);53 console.log('imposter started');54}).catch(function (error) {55 console.log(error);56});57var imposter = {58 {59 {60 {61 equals: {62 headers: {63 },64 }65 }66 }

Full Screen

Using AI Code Generation

copy

Full Screen

1var fsExtra = require('fs-extra');2var fs = require('fs');3var path = require('path');4var mb = require('mountebank');5var port = 2525;6var mbPath = 'C:/Users/username/AppData/Roaming/npm/node_modules/mountebank';7var mbPath = path.resolve(__dirname, mbPath);8var mbPath = path.resolve(mbPath, 'bin/mb');9var mbPath = path.resolve(mbPath, 'mb');

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