How to use fs.mkdirp method in Cypress

Best JavaScript code snippet using cypress

test.js

Source:test.js Github

copy

Full Screen

1let expect = require('chai').expect;2let Resolver = require('./index');3let MemoryFS = require('memory-fs');4describe('Resolver', () => {5 describe('create', () => {6 it('should throw on invalid filesystem', () => {7 let fs = {};8 expect(() => new Resolver(fs)).to.throw(/filesystem/i);9 });10 it('should throw on null filesystem', () => {11 let fs = null;12 expect(() => new Resolver(fs)).to.throw(/filesystem/i);13 });14 it('should default to node fs', () => {15 new Resolver();16 });17 });18 describe('getMatchesSync', () => {19 it('throw when no filepath is passed', () => {20 let resolver = new Resolver();21 let filepath = null;22 expect(() => resolver.getMatchesSync(filepath)).to.throw(/filepath/i);23 });24 it('should resolve multiple levels', () => {25 // setup26 let fs = new MemoryFS();27 let resolver = new Resolver(fs);28 fs.mkdirpSync('/foo/bar');29 fs.mkdirpSync('/foo[mobile]/bar');30 fs.writeFileSync('/foo/bar/index.js', 'contents');31 fs.writeFileSync('/foo[mobile]/bar/index.js', 'contents');32 fs.writeFileSync('/foo[mobile]/bar/index[ios].js', 'contents');33 //test34 let filepath = '/foo/bar/index.js';35 let matches = resolver.getMatchesSync(filepath);36 expect(matches.raw).to.eql([37 {38 flags: ['mobile', 'ios'],39 value: '/foo[mobile]/bar/index[ios].js'40 },41 {42 flags: ['mobile'],43 value: '/foo[mobile]/bar/index.js'44 },45 {46 flags: [],47 value: '/foo/bar/index.js'48 }49 ]);50 });51 it('should resolve multiple levels invisible dirs', () => {52 // setup53 let fs = new MemoryFS();54 let resolver = new Resolver(fs);55 fs.mkdirpSync('/locales/[en]');56 fs.mkdirpSync('/locales/[US]/[en]');57 fs.mkdirpSync('/locales/[CA]/[en]');58 fs.mkdirpSync('/locales/[CA]/[fr]');59 fs.writeFileSync('/locales/[en]/sample.properties', 'contents');60 fs.writeFileSync('/locales/[US]/[en]/sample.properties', 'contents');61 fs.writeFileSync('/locales/[CA]/[en]/sample.properties', 'contents');62 fs.writeFileSync('/locales/[CA]/[fr]/sample.properties', 'contents');63 //test64 let filepath = '/locales/sample.properties';65 let matches = resolver.getMatchesSync(filepath);66 expect(matches.raw).to.eql([67 {68 flags: ['US', 'en'],69 value: '/locales/[US]/[en]/sample.properties'70 },71 {72 flags: ['CA', 'en'],73 value: '/locales/[CA]/[en]/sample.properties'74 },75 {76 flags: ['CA', 'fr'],77 value: '/locales/[CA]/[fr]/sample.properties'78 },79 {80 flags: ['en'],81 value: '/locales/[en]/sample.properties'82 }83 ]);84 });85 it('should cache for better perf', () => {86 // setup87 let fs = new MemoryFS();88 let resolver = new Resolver(fs);89 fs.mkdirpSync('/foo/bar/baz');90 fs.mkdirpSync('/foo[mobile]/bar/baz');91 fs.mkdirpSync('/foo[desktop]/bar/baz');92 fs.writeFileSync('/foo/bar/baz/index.js', 'contents');93 fs.writeFileSync('/foo[mobile]/bar/baz/index.js', 'contents');94 fs.writeFileSync('/foo[desktop]/bar/baz/index.js', 'contents');95 fs.writeFileSync('/foo[desktop]/bar/baz/index[windows].js', 'contents');96 //test97 let filepath = '/foo/bar/baz/index.js';98 // no cache99 let startNoCache = process.hrtime();100 let matchesNoCache = resolver.getMatchesSync(filepath);101 let elapsedNoCache = process.hrtime(startNoCache);102 expect(matchesNoCache.raw).to.eql([103 {104 flags: ['mobile'],105 value: '/foo[mobile]/bar/baz/index.js'106 },107 {108 flags: ['desktop', 'windows'],109 value: '/foo[desktop]/bar/baz/index[windows].js'110 },111 {112 flags: ['desktop'],113 value: '/foo[desktop]/bar/baz/index.js'114 },115 {116 flags: [],117 value: '/foo/bar/baz/index.js'118 }119 ]);120 // with cache121 let startWithCache = process.hrtime();122 let matchesWithCache = resolver.getMatchesSync(filepath);123 let elapsedWithCache = process.hrtime(startWithCache);124 expect(matchesWithCache.raw).to.eql([125 {126 flags: ['mobile'],127 value: '/foo[mobile]/bar/baz/index.js'128 },129 {130 flags: ['desktop', 'windows'],131 value: '/foo[desktop]/bar/baz/index[windows].js'132 },133 {134 flags: ['desktop'],135 value: '/foo[desktop]/bar/baz/index.js'136 },137 {138 flags: [],139 value: '/foo/bar/baz/index.js'140 }141 ]);142 let noCache = hrToMs(elapsedNoCache);143 let withCache = hrToMs(elapsedWithCache);144 console.log(`noCache: ${noCache.formatted}`);145 console.log(`withCache: ${withCache.formatted}`);146 expect(noCache.value / withCache.value).to.be.above(1);147 });148 });149 describe('resolveSync', () => {150 describe('api errors', () => {151 let resolver = new Resolver();152 it('throw when no filepath is passed', () => {153 let filepath = null;154 let flags = { ios: true };155 expect(() => resolver.resolveSync(filepath, flags)).to.throw(156 /filepath/i157 );158 });159 it('throw when no flags are passed', () => {160 let filepath = '/test/foo/file.text';161 let flags = null;162 expect(() => resolver.resolveSync(filepath, flags)).to.throw(/flags/i);163 });164 it('throw if a relative filepath is passed', () => {165 let filepath = './file.text';166 let flags = { ios: true };167 expect(() => resolver.resolveSync(filepath, flags)).to.throw(168 /filepath/i169 );170 });171 });172 describe('resolution', () => {173 it('should resolve existing directories', () => {174 // setup175 let fs = new MemoryFS();176 let resolver = new Resolver(fs);177 fs.mkdirpSync('/test/foo');178 //test179 let filepath = '/test/foo';180 let flags = { any: true };181 let resolved = resolver.resolveSync(filepath, flags);182 expect(resolved).to.equal('/test/foo');183 });184 it('should resolve existing files', () => {185 // setup186 let fs = new MemoryFS();187 let resolver = new Resolver(fs);188 fs.writeFileSync('/foo.js', 'contents');189 //test190 let filepath = '/foo.js';191 let flags = { any: true };192 let resolved = resolver.resolveSync(filepath, flags);193 expect(resolved).to.equal('/foo.js');194 });195 it('should resolve existing dotfiles', () => {196 // setup197 let fs = new MemoryFS();198 let resolver = new Resolver(fs);199 fs.writeFileSync('/.eslintrc', 'contents');200 //test201 let filepath = '/.eslintrc';202 let flags = { any: true };203 let resolved = resolver.resolveSync(filepath, flags);204 expect(resolved).to.equal('/.eslintrc');205 });206 it('should resolve adapted directories', () => {207 // setup208 let fs = new MemoryFS();209 let resolver = new Resolver(fs);210 fs.mkdirpSync('/test/foo');211 fs.mkdirpSync('/test[flag]/foo');212 //test213 let filepath = '/test/foo';214 let flags = { flag: true };215 let resolved = resolver.resolveSync(filepath, flags);216 expect(resolved).to.equal('/test[flag]/foo');217 });218 it('should resolve adapted dotfiles', () => {219 // setup220 let fs = new MemoryFS();221 let resolver = new Resolver(fs);222 fs.writeFileSync('/.eslintrc', 'contents');223 fs.writeFileSync('/.eslintrc[production]', 'contents');224 //test225 let filepath = '/.eslintrc';226 let flags = { production: true };227 let resolved = resolver.resolveSync(filepath, flags);228 expect(resolved).to.equal('/.eslintrc[production]');229 });230 it('should resolve multiple levels', () => {231 // setup232 let fs = new MemoryFS();233 let resolver = new Resolver(fs);234 fs.mkdirpSync('/foo/bar');235 fs.mkdirpSync('/foo[mobile]/bar');236 fs.writeFileSync('/foo/bar/index.js', 'contents');237 fs.writeFileSync('/foo[mobile]/bar/index.js', 'contents');238 fs.writeFileSync('/foo[mobile]/bar/index[ios].js', 'contents');239 //test240 let filepath = '/foo/bar/index.js';241 let flags = { mobile: true, ios: true };242 let resolved = resolver.resolveSync(filepath, flags);243 expect(resolved).to.equal('/foo[mobile]/bar/index[ios].js');244 });245 it('should not readapt path part', () => {246 // setup247 let fs = new MemoryFS();248 let resolver = new Resolver(fs);249 fs.mkdirpSync('/foo/bar');250 fs.mkdirpSync('/foo[mobile]/bar');251 fs.mkdirpSync('/foo[mobile+ios]/bar');252 fs.writeFileSync('/foo[mobile]/bar/index[ios].js', 'contents');253 fs.writeFileSync('/foo[mobile+ios]/bar/index.js', 'contents');254 //test255 let filepath = '/foo[mobile]/bar/index.js';256 let flags = { mobile: true, ios: true };257 let resolved = resolver.resolveSync(filepath, flags);258 expect(resolved).to.equal('/foo[mobile]/bar/index[ios].js');259 });260 it('should give priority to the most flags', () => {261 // setup262 let fs = new MemoryFS();263 let resolver = new Resolver(fs);264 fs.writeFileSync('/file.js', 'contents');265 fs.writeFileSync('/file[mobile].js', 'contents');266 fs.writeFileSync('/file[mobile+ios].js', 'contents');267 //test268 let filepath = '/file.js';269 let flags = { mobile: true, ios: true };270 let resolved = resolver.resolveSync(filepath, flags);271 expect(resolved).to.equal('/file[mobile+ios].js');272 });273 it('should throw on non existing paths', () => {274 // setup275 let fs = new MemoryFS();276 let resolver = new Resolver(fs);277 //test278 let filepath = '/nope';279 let flags = {};280 expect(() => resolver.resolveSync(filepath, flags)).to.throw(/exist/);281 });282 it('should throw on non-matching paths', () => {283 // setup284 let fs = new MemoryFS();285 let resolver = new Resolver(fs);286 fs.writeFileSync('/file[desktop].js', 'contents');287 fs.writeFileSync('/file[mobile].js', 'contents');288 let filepath = '/file.js';289 let flags = {};290 expect(() => resolver.resolveSync(filepath, flags)).to.throw(/match/);291 });292 it('should give priority to earlier directories', () => {293 // setup294 let fs = new MemoryFS();295 let resolver = new Resolver(fs);296 fs.mkdirpSync('/foo');297 fs.mkdirpSync('/foo[android]');298 fs.writeFileSync('/foo/file[android+another].js', 'contents');299 fs.writeFileSync('/foo[android]/file.js', 'contents');300 //test301 let filepath = '/foo/file.js';302 let flags = { android: true, another: true };303 let resolved = resolver.resolveSync(filepath, flags);304 expect(resolved).to.equal('/foo[android]/file.js');305 });306 it('should cache for better perf', () => {307 // setup308 let fs = new MemoryFS();309 let resolver = new Resolver(fs);310 fs.mkdirpSync('/foo/bar/baz');311 fs.mkdirpSync('/foo[mobile]/bar/baz');312 fs.mkdirpSync('/foo[desktop]/bar/baz');313 fs.writeFileSync('/foo/bar/baz/index.js', 'contents');314 fs.writeFileSync('/foo[mobile]/bar/baz/index.js', 'contents');315 fs.writeFileSync('/foo[desktop]/bar/baz/index.js', 'contents');316 fs.writeFileSync('/foo[desktop]/bar/baz/index[windows].js', 'contents');317 //test318 let filepath = '/foo/bar/baz/index.js';319 let flags = { desktop: true, windows: true };320 // no cache321 let startNoCache = process.hrtime();322 let resolvedNoCache = resolver.resolveSync(filepath, flags);323 let elapsedNoCache = process.hrtime(startNoCache);324 expect(resolvedNoCache).to.equal(325 '/foo[desktop]/bar/baz/index[windows].js'326 );327 // with cache328 let startWithCache = process.hrtime();329 let resolvedWithCache = resolver.resolveSync(filepath, flags);330 let elapsedWithCache = process.hrtime(startWithCache);331 expect(resolvedWithCache).to.equal(332 '/foo[desktop]/bar/baz/index[windows].js'333 );334 let noCache = hrToMs(elapsedNoCache);335 let withCache = hrToMs(elapsedWithCache);336 console.log(`noCache: ${noCache.formatted}`);337 console.log(`withCache: ${withCache.formatted}`);338 expect(noCache.value / withCache.value).to.be.above(1);339 });340 it('should handle multi-extension files', () => {341 // setup342 let fs = new MemoryFS();343 let resolver = new Resolver(fs);344 fs.writeFileSync('/template.marko.js', 'contents');345 fs.writeFileSync('/template[ios].marko.js', 'contents');346 //test347 let filepath = '/template.marko.js';348 let flags = { ios: true };349 let resolved = resolver.resolveSync(filepath, flags);350 expect(resolved).to.equal('/template[ios].marko.js');351 });352 it('should handle names with dots', () => {353 // setup354 let fs = new MemoryFS();355 let resolver = new Resolver(fs);356 fs.writeFileSync('/home.controller.js', 'contents');357 fs.writeFileSync('/home.controller[mobile].js', 'contents');358 //test359 let filepath = '/home.controller.js';360 let flags = { mobile: true };361 let resolved = resolver.resolveSync(filepath, flags);362 expect(resolved).to.equal('/home.controller[mobile].js');363 });364 it.skip('should fallback and try alternate directories', () => {365 // setup366 let fs = new MemoryFS();367 let resolver = new Resolver(fs);368 fs.mkdirpSync('/test/foo');369 fs.mkdirpSync('/test[mobile]/foo/');370 fs.writeFileSync('/test/foo/file[mobile].js', 'contents');371 // test372 let filepath = '/test/foo/file.js';373 let flags = { mobile: true };374 let resolved = resolver.resolveSync(filepath, flags);375 expect(resolved).to.equal('/test/foo/file[mobile].js');376 });377 it('should handle win32 paths', () => {378 // setup379 let fs = new MemoryFS();380 let resolver = new Resolver(fs);381 fs.mkdirpSync('C:\\test\\foo');382 fs.mkdirpSync('C:\\test[mobile]\\foo');383 // test384 let filepath = 'C:\\test\\foo';385 let flags = { mobile: true };386 let resolved = resolver.resolveSync(filepath, flags);387 expect(resolved).to.equal('C:\\test[mobile]\\foo');388 });389 });390 });391 describe('isAdaptiveSync', () => {392 describe('api errors', () => {393 let resolver = new Resolver();394 it('throw when no filepath is passed', () => {395 let filepath = null;396 expect(() => resolver.isAdaptiveSync(filepath)).to.throw(/filepath/i);397 });398 it('throw if a relative filepath is passed', () => {399 let filepath = './file.text';400 expect(() => resolver.isAdaptiveSync(filepath)).to.throw(/filepath/i);401 });402 });403 it('should check non-adaptive paths', () => {404 // setup405 let fs = new MemoryFS();406 let resolver = new Resolver(fs);407 fs.mkdirpSync('/test/foo');408 fs.mkdirpSync('/test/foo/bar');409 // test410 let filepath = '/test/foo/bar';411 let isAdaptive = resolver.isAdaptiveSync(filepath);412 expect(isAdaptive).to.equal(false);413 });414 it('should check adaptive paths', () => {415 // setup416 let fs = new MemoryFS();417 let resolver = new Resolver(fs);418 fs.mkdirpSync('/test/foo/bar');419 fs.mkdirpSync('/test[mobile]/foo/bar');420 // test421 let filepath = '/test/foo/bar';422 let isAdaptive = resolver.isAdaptiveSync(filepath);423 expect(isAdaptive).to.equal(true);424 });425 it('should check already adapted paths', () => {426 // setup427 let fs = new MemoryFS();428 let resolver = new Resolver(fs);429 fs.mkdirpSync('/test/foo/bar');430 fs.mkdirpSync('/test[mobile]/foo/bar');431 // test432 let filepath = '/test[mobile]/foo/bar';433 let isAdaptive = resolver.isAdaptiveSync(filepath);434 expect(isAdaptive).to.equal(false);435 });436 it('should not get confused by files', () => {437 // setup438 let fs = new MemoryFS();439 let resolver = new Resolver(fs);440 fs.mkdirpSync('/test/foo');441 fs.writeFileSync('/test.js', 'contents');442 fs.writeFileSync('/test/foo/index.js', 'contents');443 // test444 let filepath = '/test/foo/index.js';445 let isAdaptive = resolver.isAdaptiveSync(filepath);446 expect(isAdaptive).to.equal(false);447 });448 it('should handle win32 paths', () => {449 // setup450 let fs = new MemoryFS();451 let resolver = new Resolver(fs);452 fs.mkdirpSync('C:\\test\\foo');453 fs.mkdirpSync('C:\\test[mobile]\\foo');454 // test455 let filepath = 'C:\\test\\foo';456 let isAdaptive = resolver.isAdaptiveSync(filepath);457 expect(isAdaptive).to.equal(true);458 });459 });460 describe('clearCache', () => {461 it('clears the cache', () => {462 // setup463 let fs = new MemoryFS();464 let resolver = new Resolver(fs);465 // add a file and resolve466 fs.writeFileSync('/file[before].js', 'Test Contents');467 expect(resolver.resolveSync('/file.js', { before: true })).to.equal(468 '/file[before].js'469 );470 // add a new file, but it can't be found because it's using old cache471 fs.writeFileSync('/file[after].js', 'Test Contents');472 expect(() => resolver.resolveSync('/file.js'), { after: true }).to.throw;473 // clear the cache, now the new file can be found474 resolver.clearCache();475 expect(resolver.resolveSync('/file.js', { after: true })).to.equal(476 '/file[after].js'477 );478 });479 });480});481function hrToMs(hr) {482 let value = hr[0] * 1000 + hr[1] / 1000000;483 return {484 value,485 formatted: value.toFixed(3) + 'ms'486 };...

Full Screen

Full Screen

loadInputFiles.js

Source:loadInputFiles.js Github

copy

Full Screen

1import assert from 'assert';2import fs from 'fs-extra';3import mock from 'mock-fs';4import path from 'path';5import tmp from 'tmp';6import { utilsFS as utils } from '../../src/utils-fs';7describe('utils-fs.loadInputFiles', () => {8 let tmpInputDir;9 let batch1;10 let batch2;11 beforeEach(() => {12 tmpInputDir = tmp.dirSync({13 unsafeCleanup: true,14 });15 batch1 = path.join(tmpInputDir.name, 'batch_1');16 batch2 = path.join(tmpInputDir.name, 'batch_2');17 fs.mkdirpSync(batch2);18 fs.mkdirpSync(batch1);19 });20 afterEach(() => {21 try {22 tmpInputDir.removeCallback();23 } catch (ignore) {24 // ignore25 }26 });27 it('should only load files in batches', async () => {28 const outputFolder = path.join(tmpInputDir.name, 'downloaded');29 const uploadedFolder = path.join(tmpInputDir.name, 'uploaded');30 fs.mkdirpSync(outputFolder);31 fs.mkdirpSync(uploadedFolder);32 /**33 * Test folder structure:34 * downloaded/downloaded.fastq should be ignored35 * uploaded/uploaded.fastq should be ignored36 * batch_1/1.fastq should be picked up37 * batch_2/2.fastq should be picked up38 */39 fs.writeFileSync(path.join(batch1, '1.fastq'), '');40 fs.writeFileSync(path.join(batch2, '2.fastq'), '');41 fs.writeFileSync(path.join(batch2, '._2.fastq'), ''); // MC-6941 junk file42 fs.writeFileSync(path.join(outputFolder, 'downloaded.fastq'), '');43 fs.writeFileSync(path.join(uploadedFolder, 'uploaded.fastq'), '');44 const opts = {45 inputFolders: [tmpInputDir.name],46 outputFolder,47 uploadedFolder,48 filetype: '.fastq',49 };50 // stepping through the file system as this is intented to work:51 // first load one batch, then the next, then once all files are gone, return null52 await utils.loadInputFiles(opts).then(async (files) => {53 assert.equal(files.length, 3, 'files1 should find the one valid file');54 assert.equal(files[0].name, '1.fastq', 'should load the folders in alphabetical order');55 fs.unlinkSync(files[0].path);56 });57 await utils.loadInputFiles(opts).then(async (files2) => {58 assert.equal(files2.length, 2, 'files2 should find the one valid file');59 assert.equal(files2[0].name, '2.fastq', 'should load the folders in alphabetical order');60 fs.unlinkSync(files2[0].path);61 });62 fs.unlinkSync(path.join(uploadedFolder, 'uploaded.fastq')); // remove uploaded file63 await utils.loadInputFiles(opts).then((files3) => {64 assert.deepEqual(files3, [], 'should find no files');65 });66 });67 it('MC-7215 should skip undesirable file types', async () => {68 const inputFolder = path.join(tmpInputDir.name, 'data');69 const oneFolder = path.join(inputFolder, 'one');70 const twoFolder = path.join(inputFolder, 'two');71 const passFolder = path.join(inputFolder, 'pass');72 fs.mkdirpSync(inputFolder);73 fs.mkdirpSync(oneFolder);74 fs.mkdirpSync(twoFolder);75 fs.mkdirpSync(passFolder);76 /**77 * Test folder structure:78 * data/1.txt79 * data/fail/1.fast580 * data/fastq_fail/1.fastq81 * data/pass/1.fastq82 */83 fs.writeFileSync(path.join(oneFolder, '1.txt'), '');84 fs.writeFileSync(path.join(twoFolder, '1.fast5'), '');85 fs.writeFileSync(path.join(passFolder, '1.fastq'), '');86 fs.writeFileSync(path.join(inputFolder, '1.fastq'), '');87 const opts = {88 inputFolders: [inputFolder],89 outputFolder: path.join(inputFolder, 'output'),90 filetype: '.fastq',91 };92 await utils.loadInputFiles(opts).then(async (files) => {93 assert.deepEqual(files, [94 {95 name: '1.fastq',96 path: path.join(inputFolder, '1.fastq'),97 relative: '/1.fastq',98 size: 0,99 id: 'FILE_6',100 },101 {102 name: '1.fastq',103 path: path.join(inputFolder, 'pass', '1.fastq'),104 relative: '/pass/1.fastq',105 size: 0,106 id: 'FILE_7',107 },108 ]);109 });110 await fs.remove(inputFolder);111 });112 it('MC-7214 should skip both fail and fastq_fail', async () => {113 const inputFolder = path.join(tmpInputDir.name, 'data');114 const failFolder = path.join(inputFolder, 'fail');115 const fastqFailFolder = path.join(inputFolder, 'fastq_fail');116 const passFolder = path.join(inputFolder, 'pass');117 fs.mkdirpSync(inputFolder);118 fs.mkdirpSync(failFolder);119 fs.mkdirpSync(fastqFailFolder);120 fs.mkdirpSync(passFolder);121 /**122 * Test folder structure:123 * data/1.fastq124 * data/fail/1.fastq125 * data/fastq_fail/1.fastq126 * data/pass/1.fastq127 */128 fs.writeFileSync(path.join(failFolder, '1.fastq'), '');129 fs.writeFileSync(path.join(fastqFailFolder, '1.fastq'), '');130 fs.writeFileSync(path.join(passFolder, '1.fastq'), '');131 fs.writeFileSync(path.join(inputFolder, '1.fastq'), '');132 const opts = {133 inputFolders: [inputFolder],134 outputFolder: path.join(inputFolder, 'output'),135 filetype: '.fastq',136 };137 await utils.loadInputFiles(opts).then(async (files) => {138 assert.deepEqual(files, [139 {140 name: '1.fastq',141 path: path.join(inputFolder, '1.fastq'),142 relative: '/1.fastq',143 size: 0,144 id: 'FILE_8',145 },146 {147 name: '1.fastq',148 path: path.join(inputFolder, 'pass', '1.fastq'),149 relative: '/pass/1.fastq',150 size: 0,151 id: 'FILE_9',152 },153 ]);154 });155 await fs.remove(inputFolder);156 });157 it('MC-6727 should support array of desirable types (and "." addition)', async () => {158 const inputFolder = path.join(tmpInputDir.name, 'data');159 const oneFolder = path.join(inputFolder, 'one');160 const twoFolder = path.join(inputFolder, 'two');161 const passFolder = path.join(inputFolder, 'pass');162 fs.mkdirpSync(inputFolder);163 fs.mkdirpSync(oneFolder);164 fs.mkdirpSync(twoFolder);165 fs.mkdirpSync(passFolder);166 /**167 * Test folder structure:168 * data/1.txt169 * data/fail/1.fast5170 * data/fastq_fail/1.fastq171 * data/pass/1.fastq172 */173 fs.writeFileSync(path.join(oneFolder, '1.txt'), '');174 fs.writeFileSync(path.join(twoFolder, '1.fast5'), '');175 fs.writeFileSync(path.join(passFolder, '1.fq'), '');176 fs.writeFileSync(path.join(passFolder, '1.fq.gz'), '');177 fs.writeFileSync(path.join(inputFolder, '1.fastq'), '');178 fs.writeFileSync(path.join(inputFolder, '1.fastq.gz'), '');179 const opts = {180 inputFolders: [inputFolder],181 outputFolder: path.join(inputFolder, 'output'),182 filetype: ['.fastq', '.fastq.gz', 'fq', 'fq.gz'],183 };184 await utils.loadInputFiles(opts).then(async (files) => {185 assert.deepEqual(files, [186 {187 name: '1.fastq',188 path: path.join(inputFolder, '1.fastq'),189 relative: '/1.fastq',190 size: 0,191 id: 'FILE_10',192 },193 {194 name: '1.fastq.gz',195 path: path.join(inputFolder, '1.fastq.gz'),196 relative: '/1.fastq.gz',197 size: 0,198 id: 'FILE_11',199 },200 {201 name: '1.fq',202 path: path.join(inputFolder, 'pass', '1.fq'),203 relative: '/pass/1.fq',204 size: 0,205 id: 'FILE_12',206 },207 {208 name: '1.fq.gz',209 path: path.join(inputFolder, 'pass', '1.fq.gz'),210 relative: '/pass/1.fq.gz',211 size: 0,212 id: 'FILE_13',213 },214 ]);215 });216 await fs.remove(inputFolder);217 });218 it('MC-6788 should support recursive find through a file', async () => {219 const inputFolder = path.join(tmpInputDir.name, 'data');220 const inputFile = path.join(inputFolder, 'SeqLenti fasta reformat.fasta');221 fs.mkdirpSync(inputFolder);222 fs.writeFileSync(inputFile, '');223 const opts = {224 inputFolders: [inputFile],225 outputFolder: path.join(inputFolder, 'output'),226 filetype: ['.fasta', '.fasta.gz', 'fa', 'fa.gz'],227 };228 await utils.loadInputFiles(opts).then(async (files) => {229 assert.deepEqual(files, [230 {231 name: 'SeqLenti fasta reformat.fasta',232 path: path.join(inputFolder, 'SeqLenti fasta reformat.fasta'),233 relative: '/SeqLenti fasta reformat.fasta',234 size: 0,235 id: 'FILE_14',236 },237 ]);238 });239 await fs.remove(inputFolder);240 });241 describe('MC-7480', () => {242 let root;243 let experiment1Path;244 let experiment2Path;245 let outputFolder;246 beforeEach(() => {247 root = '/data';248 experiment1Path = `${root}/experiment/pass`;249 experiment2Path = `${root}/experiment2/pass`;250 outputFolder = `${root}/output/`;251 mock({252 [experiment1Path]: {253 '1.fastq': 'file content here',254 },255 [experiment2Path]: {256 '1.fastq': 'file content here',257 },258 [outputFolder]: {},259 });260 });261 afterEach(() => {262 mock.restore();263 });264 it('should accept an array of folders to watch', async () => {265 const opts = {266 inputFolders: [experiment1Path, experiment2Path],267 outputFolder,268 filetype: '.fastq',269 };270 await utils.loadInputFiles(opts).then(async (files) => {271 assert.deepEqual(files, [272 {273 name: '1.fastq',274 path: path.join(experiment1Path, '1.fastq'),275 relative: '/1.fastq',276 size: 17,277 id: 'FILE_15',278 },279 {280 name: '1.fastq',281 path: path.join(experiment2Path, '1.fastq'),282 relative: '/1.fastq',283 size: 17,284 id: 'FILE_16',285 },286 ]);287 });288 });289 it('should accept a single file', async () => {290 const opts = {291 inputFolders: [`${experiment1Path}/1.fastq`],292 outputFolder,293 filetype: '.fastq',294 };295 await utils.loadInputFiles(opts).then(async (files) => {296 assert.deepEqual(files, [297 {298 name: '1.fastq',299 path: path.join(experiment1Path, '1.fastq'),300 relative: '/1.fastq',301 size: 17,302 id: 'FILE_17',303 },304 ]);305 });306 });307 });308 describe('MC-7698', () => {309 let root;310 let experiment1Path;311 let outputFolder;312 beforeEach(() => {313 root = '/data';314 experiment1Path = `${root}/reference`;315 mock({316 [experiment1Path]: {317 '1.fasta': 'file content here',318 },319 [outputFolder]: {},320 });321 });322 afterEach(() => {323 mock.restore();324 });325 it('should identify a fasta file', async () => {326 const opts = {327 inputFolders: [`${experiment1Path}/1.fasta`],328 outputFolder,329 filetype: ['fasta'],330 };331 await utils.loadInputFiles(opts).then(async (files) => {332 assert.deepEqual(files, [333 {334 name: '1.fasta',335 path: path.join(experiment1Path, '1.fasta'),336 relative: '/1.fasta',337 size: 17,338 id: 'FILE_18',339 },340 ]);341 });342 });343 });...

Full Screen

Full Screen

tests_3_1_mkdirp.js

Source:tests_3_1_mkdirp.js Github

copy

Full Screen

...69 });70 describe("async", () => {71 it("should check missing value", () => {72 assert.throws(() => {73 fs.mkdirp();74 }, ReferenceError, "check missing \"directory\" value does not throw an error");75 assert.throws(() => {76 fs.mkdirp(__dirname);77 }, ReferenceError, "check missing \"callback\" value does not throw an error");78 });79 it("should check invalid value", () => {80 assert.throws(() => {81 fs.mkdirp(false, () => {82 // nothing to do here83 });84 }, Error, "check invalid \"directory\" value does not throw an error");85 assert.throws(() => {86 fs.mkdirp(__dirname, false);87 }, Error, "check invalid \"callback\" value does not throw an error");88 assert.throws(() => {89 fs.mkdirp(__dirname, false, () => {90 // nothing to do here91 });92 }, Error, "check invalid \"callback\" value does not throw an error");93 });94 it("should check empty content value", () => {95 assert.throws(() => {96 fs.mkdirp("", () => {97 // nothing to do here98 });99 }, Error, "check empty \"directory\" content value does not throw an error");100 });101 it("should create real existing directory", (done) => {102 const CURRENT_DIRECTORY = __dirname;103 fs.mkdirp(CURRENT_DIRECTORY, (err) => {104 assert.strictEqual(null, err, "\"" + CURRENT_DIRECTORY + "\" cannot be created");105 fs.mkdirp(__dirname, TEST_OPTION, (_err) => {106 assert.strictEqual(null, _err, "\"" + CURRENT_DIRECTORY + "\" cannot be created");107 done();108 });109 });110 });111 it("should create real new directory", (done) => {112 fs.mkdirp(DIR_TESTLVL3, (err) => {113 assert.strictEqual(null, err, "\"" + DIR_TESTLVL3 + "\" cannot be created");114 fs.isDirectory(DIR_TESTLVL3, (_err, exists) => {115 assert.strictEqual(null, _err, "\"" + DIR_TESTLVL3 + "\" cannot be created");116 assert.strictEqual(true, exists, "\"" + DIR_TESTLVL3 + "\" was not created");117 done();118 });119 });120 });121 it("should create real new directory with option", () => {122 return new Promise((resolve, reject) => {123 fs.mkdirp(DIR_TESTLVL3_WITHOPTIONS, TEST_OPTION, (err) => {124 return err ? reject(err) : resolve();125 });126 }).then(() => {127 return fs.isDirectoryProm(DIR_TESTLVL3_WITHOPTIONS).then((exists) => {128 assert.strictEqual(true, exists, "\"" + DIR_TESTLVL3_WITHOPTIONS + "\" was not created");129 return Promise.resolve();130 });131 });132 });133 });134 describe("promise", () => {135 it("should check missing value", (done) => {136 fs.mkdirpProm().then(() => {137 done("check missing value does not generate an error");...

Full Screen

Full Screen

autoConfigure.js

Source:autoConfigure.js Github

copy

Full Screen

1import assert from 'assert';2import fs from 'fs-extra';3import { merge } from 'lodash';4import path from 'path';5import sinon from 'sinon';6import tmp from 'tmp';7import { EPI2ME_FS as EPI2ME } from '../../src/epi2me-fs';8describe('epi2me.autoConfigure', () => {9 let clock;10 beforeEach(() => {11 clock = sinon.useFakeTimers();12 });13 afterEach(() => {14 clock.restore();15 });16 const clientFactory = (opts) =>17 new EPI2ME(18 merge(19 {20 url: 'https://epi2me-test.local',21 log: {22 debug: sinon.stub(),23 info: sinon.stub(),24 warn: sinon.stub(),25 error: sinon.stub(),26 json: sinon.stub(),27 },28 },29 opts,30 ),31 );32 it('should require inputFolder', async () => {33 const tmpDir = tmp.dirSync();34 const client = clientFactory();35 const autoStartCb = sinon.fake();36 const mkdirp = sinon.stub(fs, 'mkdirp').callsFake((folder, cb) => {37 cb();38 });39 const mkdirpSync = sinon.stub(fs, 'mkdirpSync').callsFake();40 let err;41 try {42 await client.autoConfigure({}, autoStartCb);43 } catch (e) {44 err = e;45 }46 assert(String(err).match(/must set inputFolder/));47 mkdirp.restore();48 mkdirpSync.restore();49 tmpDir.removeCallback();50 });51 it('should require outputFolder', async () => {52 const tmpDir = tmp.dirSync();53 const client = clientFactory({54 inputFolder: path.join(tmpDir.name, 'input'),55 });56 await client.setClassConfigREST({});57 const autoStartCb = sinon.fake();58 const mkdirp = sinon.stub(fs, 'mkdirp').callsFake((folder, cb) => {59 cb();60 });61 const mkdirpSync = sinon.stub(fs, 'mkdirpSync').callsFake();62 let err;63 try {64 await client.autoConfigure({}, autoStartCb);65 } catch (e) {66 err = e;67 }68 assert(String(err).match(/must set outputFolder/));69 mkdirp.restore();70 mkdirpSync.restore();71 tmpDir.removeCallback();72 });73 it('should require inputqueue', async () => {74 const tmpDir = tmp.dirSync();75 const client = clientFactory({76 inputFolders: [path.join(tmpDir.name, 'input')],77 outputFolder: path.join(tmpDir.name, 'output'),78 });79 await client.setClassConfigREST({});80 const autoStartCb = sinon.fake();81 const mkdirp = sinon.stub(fs, 'mkdirp').callsFake((folder, cb) => {82 cb();83 });84 const mkdirpSync = sinon.stub(fs, 'mkdirpSync').callsFake();85 let err;86 try {87 await client.autoConfigure({}, autoStartCb);88 } catch (e) {89 err = e;90 }91 assert(String(err).match(/inputQueueName must be set/));92 mkdirp.restore();93 mkdirpSync.restore();94 tmpDir.removeCallback();95 });96 /*97 it("should require outputqueue", () => {98 const tmpDir = tmp.dirSync();99 let client = clientFactory({100 inputFolder: path.join(tmpDir.name, "input"),101 outputFolder: path.join(tmpDir.name, "output"),102 });103 let autoStartCb = sinon.fake();104 let mkdirp = sinon.stub(fs, "mkdirp").callsFake((folder, cb) => { cb(); });105 let mkdirpSync = sinon.stub(fs, "mkdirpSync").callsFake();106 let createWriteStream = sinon.stub(fs, "createWriteStream").callsFake();107 let stub1 = sinon.stub(client.REST, "workflow_instance").callsFake();108 let stub2 = sinon.stub(client, "session").callsFake();109 assert.throws(() => {110 client.autoConfigure({111 inputqueue: "input_queue",112 }, autoStartCb);113 }, Error);114 stub1.restore();115 stub2.restore();116 mkdirp.restore();117 mkdirpSync.restore();118 createWriteStream.restore();119 tmpDir.removeCallback();120 });121 it("should autoconfigure", () => {122 const tmpDir = tmp.dirSync();123 let client = clientFactory({124 inputFolder: path.join(tmpDir.name, "input"),125 outputFolder: path.join(tmpDir.name, "output"),126 });127 let autoStartCb = sinon.fake();128 let mkdirp = sinon.stub(fs, "mkdirp").callsFake((folder, cb) => { cb(); });129 let mkdirpSync = sinon.stub(fs, "mkdirpSync").callsFake();130 let createWriteStream = sinon.stub(fs, "createWriteStream").callsFake();131 let stub1 = sinon.stub(client.REST, "workflow_instance").callsFake();132 let stub2 = sinon.stub(client, "loadUploadFiles").callsFake();133 let stub3 = sinon.stub(client, "session").callsFake((cb) => { cb(); });134 assert.doesNotThrow(() => {135 client.autoConfigure({136 inputqueue: "input_queue",137 outputqueue: "output_queue",138 id_user: 1234,139 id_workflow_instance: 56789,140 }, autoStartCb);141 }, Error, "path cannot join nulls");142 stub1.restore();143 stub2.restore();144 stub3.restore();145 mkdirp.restore();146 mkdirpSync.restore();147 createWriteStream.restore();148 tmpDir.removeCallback();149 });150*/...

Full Screen

Full Screen

mkdirp.js

Source:mkdirp.js Github

copy

Full Screen

1import { module, test } from "qunit";2import sinon from "sinon";3import mkdirpInjector from "inject-loader!utils/node/fs/mkdirp";4module( "utils/node/fs/mkdirp", function( hooks ) {5 /** @typedef {Object} TestContextUtilsNodeFsMkdirp */6 hooks.beforeEach( /** @this {TestContextUtilsNodeFsMkdirp} */ function() {7 this.mkdirStub = sinon.stub().callsFake( path => Promise.resolve( path ) );8 /** @type {Function} subject */9 this.subject = mkdirpInjector({10 fs: {11 promises: {12 mkdir: this.mkdirStub13 }14 }15 })[ "default" ];16 });17 test( "Error", async function( assert ) {18 /** @this {TestContextUtilsNodeFsMkdirp} */19 const err = new Error( "foo" );20 this.mkdirStub.rejects( err );21 await assert.rejects(22 this.subject( "/foo/bar" ),23 err,24 "Rejects with error"25 );26 assert.propEqual(27 this.mkdirStub.args,28 [[ "/foo/bar", { recursive: true } ]],29 "Sets the recursive option to true"30 );31 });32 test( "Simple parameters", async function( assert ) {33 /** @this {TestContextUtilsNodeFsMkdirp} */34 assert.strictEqual(35 await this.subject( "/foo/bar" ),36 "/foo/bar",37 "Returns the created path"38 );39 assert.propEqual(40 this.mkdirStub.args,41 [[ "/foo/bar", { recursive: true } ]],42 "Sets the recursive option to true"43 );44 });45 test( "Mode option", async function( assert ) {46 /** @this {TestContextUtilsNodeFsMkdirp} */47 assert.strictEqual(48 await this.subject( "/foo/bar", { mode: 0o111 } ),49 "/foo/bar",50 "Returns the created path"51 );52 assert.propEqual(53 this.mkdirStub.args,54 [[ "/foo/bar", { recursive: true, mode: 0o111 } ]],55 "Sets the recursive option to true and keeps the mode option"56 );57 });58 test( "Invalid options", async function( assert ) {59 /** @this {TestContextUtilsNodeFsMkdirp} */60 const options = { recursive: false, foo: "bar" };61 assert.strictEqual(62 await this.subject( "/foo/bar", options ),63 "/foo/bar",64 "Returns the created path"65 );66 assert.propEqual(67 this.mkdirStub.args,68 [[ "/foo/bar", { recursive: true, foo: "bar" } ]],69 "Always sets the recursive option to true and keeps other options"70 );71 assert.propEqual(72 options,73 { recursive: false, foo: "bar" },74 "Doesn't alter the input options properties"75 );76 });...

Full Screen

Full Screen

mkdirp.mjs

Source:mkdirp.mjs Github

copy

Full Screen

...25 info: 'invalid argument type errors with E_ARG_TYPE',26 },27 {28 fn: async () => {29 await fs.mkdirp(tmpDir)30 return await fs.exists(tmpDir)31 },32 before,33 expect: true,34 info: 'fs.mkdirp can create deep directories',35 },36 {37 fn: async () => await fs.mkdirp(process.cwd()),38 expect: true,39 info: 'fs.mkdirp returns true if directory exists',40 },...

Full Screen

Full Screen

fs.extra.js

Source:fs.extra.js Github

copy

Full Screen

1(function () {2 "use strict";3 var oldFs = require('fs')4 , extraFs = require('fs-extra')5 , fs = {}6 ;7 Object.keys(extraFs).forEach(function (key) {8 fs[key] = extraFs[key];9 });10 Object.keys(oldFs).forEach(function (key) {11 fs[key] = oldFs[key];12 });13 fs.copy = require('./fs.copy.js');14 fs.copyRecursive = require('./fs.copy-recursive.js');15 fs.move = require('./fs.move.js');16 fs.mkdirp = require('mkdirp');17 fs.mkdirpSync = fs.mkdirp.sync;18 // Alias19 fs.mkdirRecursive = fs.mkdirp;20 fs.mkdirRecursiveSync = fs.mkdirp.sync;21 fs.remove = extraFs.remove;22 fs.removeSync = extraFs.removeSync;23 // Alias24 fs.rmrf = extraFs.remove;25 fs.rmrfSync = extraFs.removeSync;26 fs.rmRecursive = extraFs.rmrf;27 fs.rmRecursiveSync = extraFs.rmrfSync;28 fs.walk = require('walk').walk;29 module.exports = fs;...

Full Screen

Full Screen

structure.js

Source:structure.js Github

copy

Full Screen

1const fs = require('fs-extra')2// criação de estrutura de pastas do projeto3function struct ({ creditor, wallet }) {4 createFolders(creditor, wallet)5}6function createFolders (creditor, wallet = '') {7 fs.mkdirpSync(`../../${creditor}/${wallet}/`)8 fs.mkdirpSync(`../../${creditor}/${wallet}/`)9 fs.mkdirpSync(`../../${creditor}/${wallet}/`)10 fs.mkdirpSync(`../../${creditor}/${wallet}/`)11 fs.mkdirpSync(`../../${creditor}/${wallet}/`)12 fs.mkdirpSync(`../../${creditor}/${wallet}/`)13 fs.mkdirpSync(`../../${creditor}/${wallet}/`)14 fs.mkdirpSync(`../../${creditor}/${wallet}/`)15}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My first test', () => {2 it('Does not do much!', () => {3 expect(true).to.equal(true)4 })5})6const fs = require('fs')7Cypress.Commands.add('mkdirp', (dir) => {8 return new Promise((resolve, reject) => {9 fs.mkdir(dir, { recursive: true }, (err) => {10 if (err) {11 reject(err)12 } else {13 resolve(dir)14 }15 })16 })17})18describe('My first test', () => {19 it('Does not do much!', () => {20 cy.mkdirp('cypress/screenshots')21 expect(true).to.equal(true)22 })23})24{25}

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Cypress fs.mkdirp', () => {2 it('should create a directory', () => {3 cy.fs.mkdirp('cypress/fixtures/abc')4 })5})6describe('Cypress fs.writeFile', () => {7 it('should write a file', () => {8 cy.fs.writeFile('cypress/fixtures/abc/xyz.txt', 'some text')9 })10})11describe('Cypress fs.readFile', () => {12 it('should read a file', () => {13 cy.fs.readFile('cypress/fixtures/abc/xyz.txt', 'utf8')14 .then((text) => {15 expect(text).to.equal('some text')16 })17 })18})19describe('Cypress fs.remove', () => {20 it('should remove a file', () => {21 cy.fs.remove('cypress/fixtures/abc/xyz.txt')22 })23})24describe('Cypress fs.rmdir', () => {25 it('should remove a directory', () => {26 cy.fs.rmdir('cypress/fixtures/abc')27 })28})29describe('Cypress fs.stat', () => {30 it('should return file stats', () => {31 cy.fs.stat('cypress/fixtures/abc')32 .then((stats) => {33 expect(stats.isDirectory()).to.be.true34 })35 })36})37describe('Cypress fs.readdir', () => {38 it('should return directory contents', () => {39 cy.fs.readdir('cypress/fixtures')40 .then((files) => {41 expect(files).to.deep.equal(['abc'])42 })43 })44})45describe('Cypress fs.copy', () => {46 it('should copy a file', () => {47 cy.fs.copy('cypress/fixtures/abc', 'cypress/fixtures/xyz')48 })49})50describe('Cypress fs

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('test', () => {2 it('test', () => {3 cy.writeFile('cypress/integration/test/test.txt', 'test')4 })5})6describe('test', () => {7 it('test', () => {8 cy.writeFile('cypress/integration/test/test.txt', 'test')9 })10})11Recommended Posts: Cypress | cy.readFile() command12Cypress | cy.writeFile() command13Cypress | cy.wrap() command14Cypress | cy.visit() command15Cypress | cy.clearLocalStorage() command16Cypress | cy.clearCookies() command17Cypress | cy.clearLocalStorage() command18Cypress | cy.contains() command19Cypress | cy.exec() command20Cypress | cy.go() command21Cypress | cy.hash() command22Cypress | cy.location() command23Cypress | cy.reload() command24Cypress | cy.screenshot() command25Cypress | cy.scrollTo() command26Cypress | cy.title() command27Cypress | cy.viewport() command28Cypress | cy.wait() command29Cypress | cy.wrap() command30Cypress | cy.get() command31Cypress | cy.getCookie() command32Cypress | cy.getCookies() command33Cypress | cy.getIframeBody() command34Cypress | cy.getIframeHead() command

Full Screen

Cypress Tutorial

Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.

Chapters:

  1. What is Cypress? -
  2. Why Cypress? - Learn why Cypress might be a good choice for testing your web applications.
  3. Features of Cypress Testing - Learn about features that make Cypress a powerful and flexible tool for testing web applications.
  4. Cypress Drawbacks - Although Cypress has many strengths, it has a few limitations that you should be aware of.
  5. Cypress Architecture - Learn more about Cypress architecture and how it is designed to be run directly in the browser, i.e., it does not have any additional servers.
  6. Browsers Supported by Cypress - Cypress is built on top of the Electron browser, supporting all modern web browsers. Learn browsers that support Cypress.
  7. Selenium vs Cypress: A Detailed Comparison - Compare and explore some key differences in terms of their design and features.
  8. Cypress Learning: Best Practices - Take a deep dive into some of the best practices you should use to avoid anti-patterns in your automation tests.
  9. How To Run Cypress Tests on LambdaTest? - Set up a LambdaTest account, and now you are all set to learn how to run Cypress tests.

Certification

You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.

YouTube

Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.

Run Cypress 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