How to use fs.mkdir method in Cypress

Best JavaScript code snippet using cypress

resolveCache.js

Source:resolveCache.js Github

copy

Full Screen

1var path = require('path');2var mout = require('mout');3var rimraf = require('rimraf');4var fs = require('graceful-fs');5var Q = require('q');6var expect = require('expect.js');7var mkdirp = require('mkdirp');8var ResolveCache = require('../../lib/core/ResolveCache');9var defaultConfig = require('../../lib/config');10var cmd = require('../../lib/util/cmd');11var copy = require('../../lib/util/copy');12var md5 = require('../../lib/util/md5');13describe('ResolveCache', function () {14 var resolveCache;15 var testPackage = path.resolve(__dirname, '../assets/package-a');16 var tempPackage = path.resolve(__dirname, '../assets/temp');17 var tempPackage2 = path.resolve(__dirname, '../assets/temp2');18 var cacheDir = path.join(__dirname, '../assets/temp-resolve-cache');19 before(function (next) {20 // Delete cache folder21 rimraf.sync(cacheDir);22 // Instantiate resolver cache23 resolveCache = new ResolveCache(mout.object.deepMixIn(defaultConfig, {24 storage: {25 packages: cacheDir26 }27 }));28 // Checkout test package version 0.2.029 cmd('git', ['checkout', '0.2.0'], { cwd: testPackage })30 .then(next.bind(next, null), next);31 });32 beforeEach(function () {33 // Reset in memory cache for each test34 resolveCache.reset();35 });36 after(function () {37 // Remove cache folder afterwards38 rimraf.sync(cacheDir);39 });40 describe('.constructor', function () {41 beforeEach(function () {42 // Delete temp folder43 rimraf.sync(tempPackage);44 });45 after(function () {46 // Delete temp folder47 rimraf.sync(tempPackage);48 });49 function initialize(cacheDir) {50 return new ResolveCache(mout.object.deepMixIn(defaultConfig, {51 storage: {52 packages: cacheDir53 }54 }));55 }56 it('should create the cache folder if it doesn\'t exists', function () {57 initialize(tempPackage);58 expect(fs.existsSync(tempPackage)).to.be(true);59 });60 it('should not error out if the cache folder already exists', function () {61 mkdirp.sync(tempPackage);62 initialize(tempPackage);63 });64 });65 describe('.store', function () {66 var oldFsRename = fs.rename;67 beforeEach(function (next) {68 // Restore oldFsRename69 fs.rename = oldFsRename;70 // Create a fresh copy of the test package into temp71 rimraf.sync(tempPackage);72 copy.copyDir(testPackage, tempPackage, { ignore: ['.git'] })73 .then(next.bind(next, null), next);74 });75 it('should move the canonical dir to source-md5/version/ folder if package meta has a version', function (next) {76 resolveCache.store(tempPackage, {77 name: 'foo',78 version: '1.0.0',79 _source: 'foo',80 _target: '*'81 })82 .then(function (dir) {83 expect(dir).to.equal(path.join(cacheDir, md5('foo'), '1.0.0'));84 expect(fs.existsSync(dir)).to.be(true);85 expect(fs.existsSync(path.join(dir, 'baz'))).to.be(true);86 expect(fs.existsSync(tempPackage)).to.be(false);87 next();88 })89 .done();90 });91 it('should move the canonical dir to source-md5/target/ folder if package meta has no version', function (next) {92 resolveCache.store(tempPackage, {93 name: 'foo',94 _source: 'foo',95 _target: 'some-branch'96 })97 .then(function (dir) {98 expect(dir).to.equal(path.join(cacheDir, md5('foo'), 'some-branch'));99 expect(fs.existsSync(dir)).to.be(true);100 expect(fs.existsSync(path.join(dir, 'baz'))).to.be(true);101 expect(fs.existsSync(tempPackage)).to.be(false);102 next();103 })104 .done();105 });106 it('should move the canonical dir to source-md5/_wildcard/ folder if package meta has no version and target is *', function (next) {107 resolveCache.store(tempPackage, {108 name: 'foo',109 _source: 'foo',110 _target: '*'111 })112 .then(function (dir) {113 expect(dir).to.equal(path.join(cacheDir, md5('foo'), '_wildcard'));114 expect(fs.existsSync(dir)).to.be(true);115 expect(fs.existsSync(path.join(dir, 'baz'))).to.be(true);116 expect(fs.existsSync(tempPackage)).to.be(false);117 next();118 })119 .done();120 });121 it('should overwrite if the exact same package source/version exists', function (next) {122 var cachePkgDir = path.join(cacheDir, md5('foo'), '1.0.0-rc.blehhh');123 mkdirp.sync(cachePkgDir);124 fs.writeFileSync(path.join(cachePkgDir, '_bleh'), 'w00t');125 resolveCache.store(tempPackage, {126 name: 'foo',127 version: '1.0.0-rc.blehhh',128 _source: 'foo',129 _target: '*'130 })131 .then(function (dir) {132 expect(dir).to.equal(cachePkgDir);133 expect(fs.existsSync(dir)).to.be(true);134 expect(fs.existsSync(path.join(dir, 'baz'))).to.be(true);135 expect(fs.existsSync(tempPackage)).to.be(false);136 expect(fs.existsSync(path.join(cachePkgDir, '_bleh'))).to.be(false);137 next();138 })139 .done();140 });141 it('should read the package meta if not present', function (next) {142 var pkgMeta = path.join(tempPackage, '.bower.json');143 // Copy bower.json to .bower.json and add some props144 copy.copyFile(path.join(tempPackage, 'component.json'), pkgMeta)145 .then(function () {146 return Q.nfcall(fs.readFile, pkgMeta)147 .then(function (contents) {148 var json = JSON.parse(contents.toString());149 json._target = '~0.2.0';150 json._source = 'git://github.com/bower/test-package.git';151 return Q.nfcall(fs.writeFile, pkgMeta, JSON.stringify(json, null, ' '));152 });153 })154 // Store as usual155 .then(function () {156 return resolveCache.store(tempPackage);157 })158 .then(function (dir) {159 expect(dir).to.equal(path.join(cacheDir, md5('git://github.com/bower/test-package.git'), '0.2.0'));160 expect(fs.existsSync(dir)).to.be(true);161 expect(fs.existsSync(path.join(dir, 'baz'))).to.be(true);162 expect(fs.existsSync(tempPackage)).to.be(false);163 next();164 })165 .done();166 });167 it('should error out when reading the package meta if the file does not exist', function (next) {168 resolveCache.store(tempPackage)169 .then(function () {170 next(new Error('Should have failed'));171 }, function (err) {172 expect(err).to.be.an(Error);173 expect(err.code).to.equal('ENOENT');174 expect(err.message).to.contain(path.join(tempPackage, '.bower.json'));175 next();176 })177 .done();178 });179 it('should error out when reading an invalid package meta', function (next) {180 var pkgMeta = path.join(tempPackage, '.bower.json');181 return Q.nfcall(fs.writeFile, pkgMeta, 'w00t')182 .then(function () {183 return resolveCache.store(tempPackage)184 .then(function () {185 next(new Error('Should have failed'));186 }, function (err) {187 expect(err).to.be.an(Error);188 expect(err.code).to.equal('EMALFORMED');189 expect(err.message).to.contain(path.join(tempPackage, '.bower.json'));190 next();191 });192 })193 .done();194 });195 it('should move the canonical dir, even if it is in a different drive', function (next) {196 var hittedMock = false;197 fs.rename = function (src, dest, cb) {198 hittedMock = true;199 setTimeout(function () {200 var err = new Error();201 err.code = 'EXDEV';202 cb(err);203 }, 10);204 };205 resolveCache.store(tempPackage, {206 name: 'foo',207 _source: 'foo',208 _target: 'some-branch'209 })210 .then(function (dir) {211 // Ensure mock was called212 expect(hittedMock).to.be(true);213 expect(dir).to.equal(path.join(cacheDir, md5('foo'), 'some-branch'));214 expect(fs.existsSync(dir)).to.be(true);215 expect(fs.existsSync(path.join(dir, 'baz'))).to.be(true);216 expect(fs.existsSync(tempPackage)).to.be(false);217 next();218 })219 .done();220 });221 it('should update the in-memory cache', function (next) {222 // Feed the cache223 resolveCache.versions('test-in-memory')224 // Copy temp package to temp package 2225 .then(function () {226 return copy.copyDir(tempPackage, tempPackage2, { ignore: ['.git'] });227 })228 // Store the two packages229 .then(function () {230 return resolveCache.store(tempPackage, {231 name: 'foo',232 version: '1.0.0',233 _source: 'test-in-memory',234 _target: '*'235 });236 })237 .then(function () {238 return resolveCache.store(tempPackage2, {239 name: 'foo',240 version: '1.0.1',241 _source: 'test-in-memory',242 _target: '*'243 });244 })245 // Cache should have been updated246 .then(function () {247 return resolveCache.versions('test-in-memory')248 .then(function (versions) {249 expect(versions).to.eql(['1.0.1', '1.0.0']);250 next();251 });252 })253 .done();254 });255 it('should url encode target when storing to the fs', function (next) {256 resolveCache.store(tempPackage, {257 name: 'foo',258 _source: 'foo',259 _target: 'foo/bar'260 })261 .then(function (dir) {262 expect(dir).to.equal(path.join(cacheDir, md5('foo'), 'foo%2Fbar'));263 expect(fs.existsSync(dir)).to.be(true);264 expect(fs.existsSync(path.join(dir, 'baz'))).to.be(true);265 expect(fs.existsSync(tempPackage)).to.be(false);266 next();267 })268 .done();269 });270 });271 describe('.versions', function () {272 it('should resolve to an array', function (next) {273 resolveCache.versions(String(Math.random()))274 .then(function (versions) {275 expect(versions).to.be.an('array');276 next();277 })278 .done();279 });280 it('should ignore non-semver folders of the source', function (next) {281 var source = String(Math.random());282 var sourceId = md5(source);283 var sourceDir = path.join(cacheDir, sourceId);284 // Create some versions285 fs.mkdirSync(sourceDir);286 fs.mkdirSync(path.join(sourceDir, '0.0.1'));287 fs.mkdirSync(path.join(sourceDir, '0.1.0'));288 fs.mkdirSync(path.join(sourceDir, 'foo'));289 resolveCache.versions(source)290 .then(function (versions) {291 expect(versions).to.not.contain('foo');292 expect(versions).to.contain('0.0.1');293 expect(versions).to.contain('0.1.0');294 next();295 })296 .done();297 });298 it('should order the versions', function (next) {299 var source = String(Math.random());300 var sourceId = md5(source);301 var sourceDir = path.join(cacheDir, sourceId);302 // Create some versions303 fs.mkdirSync(sourceDir);304 fs.mkdirSync(path.join(sourceDir, '0.0.1'));305 fs.mkdirSync(path.join(sourceDir, '0.1.0'));306 fs.mkdirSync(path.join(sourceDir, '0.1.0-rc.1'));307 resolveCache.versions(source)308 .then(function (versions) {309 expect(versions).to.eql(['0.1.0', '0.1.0-rc.1', '0.0.1']);310 next();311 })312 .done();313 });314 it('should cache versions to speed-up subsequent calls', function (next) {315 var source = String(Math.random());316 var sourceId = md5(source);317 var sourceDir = path.join(cacheDir, sourceId);318 // Create some versions319 fs.mkdirSync(sourceDir);320 fs.mkdirSync(path.join(sourceDir, '0.0.1'));321 resolveCache.versions(source)322 .then(function () {323 // Remove folder324 rimraf.sync(sourceDir);325 return resolveCache.versions(source);326 })327 .then(function (versions) {328 expect(versions).to.eql(['0.0.1']);329 next();330 })331 .done();332 });333 });334 describe('.retrieve', function () {335 it('should resolve to empty if there are no packages for the requested source', function (next) {336 resolveCache.retrieve(String(Math.random()))337 .spread(function () {338 expect(arguments.length).to.equal(0);339 next();340 })341 .done();342 });343 it('should resolve to empty if there are no suitable packages for the requested target', function (next) {344 var source = String(Math.random());345 var sourceId = md5(source);346 var sourceDir = path.join(cacheDir, sourceId);347 // Create some versions348 fs.mkdirSync(sourceDir);349 fs.mkdirSync(path.join(sourceDir, '0.0.1'));350 fs.mkdirSync(path.join(sourceDir, '0.1.0'));351 fs.mkdirSync(path.join(sourceDir, '0.1.9'));352 fs.mkdirSync(path.join(sourceDir, '0.2.0'));353 resolveCache.retrieve(source, '~0.3.0')354 .spread(function () {355 expect(arguments.length).to.equal(0);356 return resolveCache.retrieve(source, 'some-branch');357 })358 .spread(function () {359 expect(arguments.length).to.equal(0);360 next();361 })362 .done();363 });364 it('should remove invalid packages from the cache if their package meta is missing or invalid', function (next) {365 var source = String(Math.random());366 var sourceId = md5(source);367 var sourceDir = path.join(cacheDir, sourceId);368 // Create some versions369 fs.mkdirSync(sourceDir);370 fs.mkdirSync(path.join(sourceDir, '0.0.1'));371 fs.mkdirSync(path.join(sourceDir, '0.1.0'));372 fs.mkdirSync(path.join(sourceDir, '0.1.9'));373 fs.mkdirSync(path.join(sourceDir, '0.2.0'));374 // Create an invalid package meta375 fs.writeFileSync(path.join(sourceDir, '0.2.0', '.bower.json'), 'w00t');376 resolveCache.retrieve(source, '~0.1.0')377 .spread(function () {378 var dirs = fs.readdirSync(sourceDir);379 expect(arguments.length).to.equal(0);380 expect(dirs).to.contain('0.0.1');381 expect(dirs).to.contain('0.2.0');382 next();383 })384 .done();385 });386 it('should resolve to the highest package that matches a range target, ignoring pre-releases', function (next) {387 var source = String(Math.random());388 var sourceId = md5(source);389 var sourceDir = path.join(cacheDir, sourceId);390 var json = { name: 'foo' };391 // Create some versions392 fs.mkdirSync(sourceDir);393 json.version = '0.0.1';394 fs.mkdirSync(path.join(sourceDir, '0.0.1'));395 fs.writeFileSync(path.join(sourceDir, '0.0.1', '.bower.json'), JSON.stringify(json, null, ' '));396 json.version = '0.1.0';397 fs.mkdirSync(path.join(sourceDir, '0.1.0'));398 fs.writeFileSync(path.join(sourceDir, '0.1.0', '.bower.json'), JSON.stringify(json, null, ' '));399 json.version = '0.1.0-rc.1';400 fs.mkdirSync(path.join(sourceDir, '0.1.0-rc.1'));401 fs.writeFileSync(path.join(sourceDir, '0.1.0-rc.1', '.bower.json'), JSON.stringify(json, null, ' '));402 json.version = '0.1.9';403 fs.mkdirSync(path.join(sourceDir, '0.1.9'));404 fs.writeFileSync(path.join(sourceDir, '0.1.9', '.bower.json'), JSON.stringify(json, null, ' '));405 json.version = '0.2.0';406 fs.mkdirSync(path.join(sourceDir, '0.2.0'));407 fs.writeFileSync(path.join(sourceDir, '0.2.0', '.bower.json'), JSON.stringify(json, null, ' '));408 resolveCache.retrieve(source, '~0.1.0')409 .spread(function (canonicalDir, pkgMeta) {410 expect(pkgMeta).to.be.an('object');411 expect(pkgMeta.version).to.equal('0.1.9');412 expect(canonicalDir).to.equal(path.join(sourceDir, '0.1.9'));413 return resolveCache.retrieve(source, '*');414 })415 .spread(function (canonicalDir, pkgMeta) {416 expect(pkgMeta).to.be.an('object');417 expect(pkgMeta.version).to.equal('0.2.0');418 expect(canonicalDir).to.equal(path.join(sourceDir, '0.2.0'));419 next();420 })421 .done();422 });423 it('should resolve to the highest package that matches a range target, not ignoring pre-releases if they are the only versions', function (next) {424 var source = String(Math.random());425 var sourceId = md5(source);426 var sourceDir = path.join(cacheDir, sourceId);427 var json = { name: 'foo' };428 // Create some versions429 fs.mkdirSync(sourceDir);430 json.version = '0.1.0-rc.1';431 fs.mkdirSync(path.join(sourceDir, '0.1.0-rc.1'));432 fs.writeFileSync(path.join(sourceDir, '0.1.0-rc.1', '.bower.json'), JSON.stringify(json, null, ' '));433 json.version = '0.1.0-rc.2';434 fs.mkdirSync(path.join(sourceDir, '0.1.0-rc.2'));435 fs.writeFileSync(path.join(sourceDir, '0.1.0-rc.2', '.bower.json'), JSON.stringify(json, null, ' '));436 resolveCache.retrieve(source, '~0.1.0')437 .spread(function (canonicalDir, pkgMeta) {438 expect(pkgMeta).to.be.an('object');439 expect(pkgMeta.version).to.equal('0.1.0-rc.2');440 expect(canonicalDir).to.equal(path.join(sourceDir, '0.1.0-rc.2'));441 next();442 })443 .done();444 });445 it('should resolve to exact match (including build metadata) if available', function (next) {446 var source = String(Math.random());447 var sourceId = md5(source);448 var sourceDir = path.join(cacheDir, sourceId);449 var json = { name: 'foo' };450 // Create some versions451 fs.mkdirSync(sourceDir);452 json.version = '0.1.0';453 fs.mkdirSync(path.join(sourceDir, '0.1.0'));454 fs.writeFileSync(path.join(sourceDir, '0.1.0', '.bower.json'), JSON.stringify(json, null, ' '));455 json.version = '0.1.0+build.4';456 fs.mkdirSync(path.join(sourceDir, '0.1.0+build.4'));457 fs.writeFileSync(path.join(sourceDir, '0.1.0+build.4', '.bower.json'), JSON.stringify(json, null, ' '));458 json.version = '0.1.0+build.5';459 fs.mkdirSync(path.join(sourceDir, '0.1.0+build.5'));460 fs.writeFileSync(path.join(sourceDir, '0.1.0+build.5', '.bower.json'), JSON.stringify(json, null, ' '));461 json.version = '0.1.0+build.6';462 fs.mkdirSync(path.join(sourceDir, '0.1.0+build.6'));463 fs.writeFileSync(path.join(sourceDir, '0.1.0+build.6', '.bower.json'), JSON.stringify(json, null, ' '));464 resolveCache.retrieve(source, '0.1.0+build.5')465 .spread(function (canonicalDir, pkgMeta) {466 expect(pkgMeta).to.be.an('object');467 expect(pkgMeta.version).to.equal('0.1.0+build.5');468 expect(canonicalDir).to.equal(path.join(sourceDir, '0.1.0+build.5'));469 next();470 })471 .done();472 });473 it('should resolve to the _wildcard package if target is * and there are no semver versions', function (next) {474 var source = String(Math.random());475 var sourceId = md5(source);476 var sourceDir = path.join(cacheDir, sourceId);477 var json = { name: 'foo' };478 // Create some versions479 fs.mkdirSync(sourceDir);480 fs.mkdirSync(path.join(sourceDir, '_wildcard'));481 fs.writeFileSync(path.join(sourceDir, '_wildcard', '.bower.json'), JSON.stringify(json, null, ' '));482 resolveCache.retrieve(source, '*')483 .spread(function (canonicalDir, pkgMeta) {484 expect(pkgMeta).to.be.an('object');485 expect(canonicalDir).to.equal(path.join(sourceDir, '_wildcard'));486 next();487 })488 .done();489 });490 it('should resolve to the exact target it\'s not a semver range', function (next) {491 var source = String(Math.random());492 var sourceId = md5(source);493 var sourceDir = path.join(cacheDir, sourceId);494 var json = { name: 'foo' };495 // Create some versions496 fs.mkdirSync(sourceDir);497 fs.mkdirSync(path.join(sourceDir, 'some-branch'));498 fs.writeFileSync(path.join(sourceDir, 'some-branch', '.bower.json'), JSON.stringify(json, null, ' '));499 fs.mkdirSync(path.join(sourceDir, 'other-branch'));500 fs.writeFileSync(path.join(sourceDir, 'other-branch', '.bower.json'), JSON.stringify(json, null, ' '));501 resolveCache.retrieve(source, 'some-branch')502 .spread(function (canonicalDir, pkgMeta) {503 expect(pkgMeta).to.be.an('object');504 expect(pkgMeta).to.not.have.property('version');505 next();506 })507 .done();508 });509 });510 describe('.eliminate', function () {511 beforeEach(function () {512 mkdirp.sync(cacheDir);513 });514 it('should delete the source-md5/version folder', function (next) {515 var source = String(Math.random());516 var sourceId = md5(source);517 var sourceDir = path.join(cacheDir, sourceId);518 // Create some versions519 fs.mkdirSync(sourceDir);520 fs.mkdirSync(path.join(sourceDir, '0.0.1'));521 fs.mkdirSync(path.join(sourceDir, '0.1.0'));522 resolveCache.eliminate({523 name: 'foo',524 version: '0.0.1',525 _source: source,526 _target: '*'527 })528 .then(function () {529 expect(fs.existsSync(path.join(sourceDir, '0.0.1'))).to.be(false);530 expect(fs.existsSync(path.join(sourceDir, '0.1.0'))).to.be(true);531 next();532 })533 .done();534 });535 it('should delete the source-md5/target folder', function (next) {536 var source = String(Math.random());537 var sourceId = md5(source);538 var sourceDir = path.join(cacheDir, sourceId);539 // Create some versions540 fs.mkdirSync(sourceDir);541 fs.mkdirSync(path.join(sourceDir, '0.0.1'));542 fs.mkdirSync(path.join(sourceDir, 'some-branch'));543 resolveCache.eliminate({544 name: 'foo',545 _source: source,546 _target: 'some-branch'547 })548 .then(function () {549 expect(fs.existsSync(path.join(sourceDir, 'some-branch'))).to.be(false);550 expect(fs.existsSync(path.join(sourceDir, '0.0.1'))).to.be(true);551 next();552 })553 .done();554 });555 it('should delete the source-md5/_wildcard folder', function (next) {556 var source = String(Math.random());557 var sourceId = md5(source);558 var sourceDir = path.join(cacheDir, sourceId);559 // Create some versions560 fs.mkdirSync(sourceDir);561 fs.mkdirSync(path.join(sourceDir, '0.0.1'));562 fs.mkdirSync(path.join(sourceDir, '_wildcard'));563 resolveCache.eliminate({564 name: 'foo',565 _source: source,566 _target: '*'567 })568 .then(function () {569 expect(fs.existsSync(path.join(sourceDir, '_wildcard'))).to.be(false);570 expect(fs.existsSync(path.join(sourceDir, '0.0.1'))).to.be(true);571 next();572 })573 .done();574 });575 it('should delete the source-md5 folder if empty', function (next) {576 var source = String(Math.random());577 var sourceId = md5(source);578 var sourceDir = path.join(cacheDir, sourceId);579 // Create some versions580 fs.mkdirSync(sourceDir);581 fs.mkdirSync(path.join(sourceDir, '0.0.1'));582 resolveCache.eliminate({583 name: 'foo',584 version: '0.0.1',585 _source: source,586 _target: '*'587 })588 .then(function () {589 expect(fs.existsSync(path.join(sourceDir, '0.0.1'))).to.be(false);590 expect(fs.existsSync(path.join(sourceDir))).to.be(false);591 next();592 })593 .done();594 });595 it('should remove entry from in memory cache if the source-md5 folder was deleted', function (next) {596 var source = String(Math.random());597 var sourceId = md5(source);598 var sourceDir = path.join(cacheDir, sourceId);599 // Create some versions600 fs.mkdirSync(sourceDir);601 fs.mkdirSync(path.join(sourceDir, '0.0.1'));602 // Feed up the cache603 resolveCache.versions(source)604 // Eliminate605 .then(function () {606 return resolveCache.eliminate({607 name: 'foo',608 version: '0.0.1',609 _source: source,610 _target: '*'611 });612 })613 .then(function () {614 // At this point the parent folder should be deleted615 // To test against the in-memory cache, we create a folder616 // manually and request the versions617 mkdirp.sync(path.join(sourceDir, '0.0.2'));618 resolveCache.versions(source)619 .then(function (versions) {620 expect(versions).to.eql(['0.0.2']);621 next();622 });623 })624 .done();625 });626 });627 describe('.clear', function () {628 beforeEach(function () {629 mkdirp.sync(cacheDir);630 });631 it('should empty the whole cache folder', function (next) {632 resolveCache.clear()633 .then(function () {634 var files;635 expect(fs.existsSync(cacheDir)).to.be(true);636 files = fs.readdirSync(cacheDir);637 expect(files.length).to.be(0);638 next();639 })640 .done();641 });642 it('should erase the in-memory cache', function (next) {643 var source = String(Math.random());644 var sourceId = md5(source);645 var sourceDir = path.join(cacheDir, sourceId);646 // Create some versions647 fs.mkdirSync(sourceDir);648 fs.mkdirSync(path.join(sourceDir, '0.0.1'));649 // Feed the in-memory cache650 resolveCache.versions(source)651 // Clear652 .then(function () {653 return resolveCache.clear();654 })655 .then(function () {656 // To test against the in-memory cache, we create a folder657 // manually and request the versions658 mkdirp.sync(path.join(sourceDir, '0.0.2'));659 resolveCache.versions(source)660 .then(function (versions) {661 expect(versions).to.eql(['0.0.2']);662 next();663 });664 })665 .done();666 });667 });668 describe('.reset', function () {669 it('should erase the in-memory cache', function (next) {670 var source = String(Math.random());671 var sourceId = md5(source);672 var sourceDir = path.join(cacheDir, sourceId);673 // Create some versions674 fs.mkdirSync(sourceDir);675 fs.mkdirSync(path.join(sourceDir, '0.0.1'));676 // Feed the in-memory cache677 resolveCache.versions(source)678 .then(function () {679 // Delete 0.0.1 and create 0.0.2680 fs.rmdirSync(path.join(sourceDir, '0.0.1'));681 fs.mkdirSync(path.join(sourceDir, '0.0.2'));682 // Reset cache683 resolveCache.reset();684 // Get versions685 return resolveCache.versions(source);686 })687 .then(function (versions) {688 expect(versions).to.eql(['0.0.2']);689 next();690 })691 .done();692 });693 });694 describe('.list', function () {695 beforeEach(function () {696 rimraf.sync(cacheDir);697 mkdirp.sync(cacheDir);698 });699 it('should resolve to an empty array if the cache is empty', function (next) {700 resolveCache.list()701 .then(function (entries) {702 expect(entries).to.be.an('array');703 expect(entries.length).to.be(0);704 next();705 })706 .done();707 });708 it('should resolve to an ordered array of entries (name ASC, release ASC)', function (next) {709 var source = 'list-package-1';710 var sourceId = md5(source);711 var sourceDir = path.join(cacheDir, sourceId);712 var source2 = 'list-package-2';713 var sourceId2 = md5(source2);714 var sourceDir2 = path.join(cacheDir, sourceId2);715 var json = {716 name: 'foo'717 };718 // Create some versions for different sources719 fs.mkdirSync(sourceDir);720 fs.mkdirSync(path.join(sourceDir, '0.0.1'));721 json.version = '0.0.1';722 fs.writeFileSync(path.join(sourceDir, '0.0.1', '.bower.json'), JSON.stringify(json, null, ' '));723 fs.mkdirSync(path.join(sourceDir, '0.1.0'));724 json.version = '0.1.0';725 fs.writeFileSync(path.join(sourceDir, '0.1.0', '.bower.json'), JSON.stringify(json, null, ' '));726 delete json.version;727 fs.mkdirSync(path.join(sourceDir, 'foo'));728 json._target = 'foo';729 fs.writeFileSync(path.join(sourceDir, 'foo', '.bower.json'), JSON.stringify(json, null, ' '));730 fs.mkdirSync(path.join(sourceDir, 'bar'));731 json._target = 'bar';732 fs.writeFileSync(path.join(sourceDir, 'bar', '.bower.json'), JSON.stringify(json, null, ' '));733 fs.mkdirSync(path.join(sourceDir, 'aa'));734 json._target = 'aa';735 fs.writeFileSync(path.join(sourceDir, 'aa', '.bower.json'), JSON.stringify(json, null, ' '));736 delete json._target;737 fs.mkdirSync(sourceDir2);738 fs.mkdirSync(path.join(sourceDir2, '0.2.1'));739 json.version = '0.2.1';740 fs.writeFileSync(path.join(sourceDir2, '0.2.1', '.bower.json'), JSON.stringify(json, null, ' '));741 fs.mkdirSync(path.join(sourceDir2, '0.2.0'));742 json.name = 'abc';743 json.version = '0.2.0';744 fs.writeFileSync(path.join(sourceDir2, '0.2.0', '.bower.json'), JSON.stringify(json, null, ' '));745 resolveCache.list()746 .then(function (entries) {747 var expectedJson;748 var bowerDir = path.join(__dirname, '../..');749 expect(entries).to.be.an('array');750 expectedJson = fs.readFileSync(path.join(__dirname, '../assets/resolve-cache/list-json-1.json'));751 expectedJson = expectedJson.toString();752 mout.object.forOwn(entries, function (entry) {753 // Trim absolute bower path from json754 entry.canonicalDir = entry.canonicalDir.substr(bowerDir.length);755 // Convert windows \ paths to /756 entry.canonicalDir = entry.canonicalDir.replace(/\\/g, '/');757 });758 json = JSON.stringify(entries, null, ' ');759 expect(json).to.equal(expectedJson);760 next();761 })762 .done();763 });764 it('should ignore lurking files where dirs are expected', function (next) {765 var source = 'list-package-1';766 var sourceId = md5(source);767 var sourceDir = path.join(cacheDir, sourceId);768 var json = {769 name: 'foo'770 };771 // Create some versions772 fs.mkdirSync(sourceDir);773 fs.mkdirSync(path.join(sourceDir, '0.0.1'));774 json.version = '0.0.1';775 fs.writeFileSync(path.join(sourceDir, '0.0.1', '.bower.json'), JSON.stringify(json, null, ' '));776 // Create lurking files777 fs.writeFileSync(path.join(cacheDir, 'foo'), 'w00t');778 fs.writeFileSync(path.join(cacheDir, '.DS_Store'), '');779 fs.writeFileSync(path.join(sourceDir, 'foo'), 'w00t');780 fs.writeFileSync(path.join(sourceDir, '.DS_Store'), '');781 // It should not error out782 resolveCache.list()783 .then(function (entries) {784 expect(entries).to.be.an('array');785 expect(entries.length).to.be(1);786 expect(entries[0].pkgMeta).to.eql(json);787 // Lurking file should have been removed788 expect(fs.existsSync(path.join(cacheDir, 'foo'))).to.be(false);789 expect(fs.existsSync(path.join(cacheDir, '.DS_Store'))).to.be(false);790 expect(fs.existsSync(path.join(sourceDir, 'foo'))).to.be(false);791 expect(fs.existsSync(path.join(sourceDir, '.DS_Store'))).to.be(false);792 next();793 })794 .done();795 });796 it('should delete entries if failed to read package meta', function (next) {797 var source = 'list-package-1';798 var sourceId = md5(source);799 var sourceDir = path.join(cacheDir, sourceId);800 var json = {801 name: 'foo'802 };803 // Create invalid versions804 fs.mkdirSync(sourceDir);805 fs.mkdirSync(path.join(sourceDir, '0.0.1'));806 fs.mkdirSync(path.join(sourceDir, '0.0.2'));807 fs.writeFileSync(path.join(sourceDir, '0.0.2', '.bower.json'), 'w00t');808 // Create valid version809 fs.mkdirSync(path.join(sourceDir, '0.0.3'));810 json.version = '0.0.3';811 fs.writeFileSync(path.join(sourceDir, '0.0.3', '.bower.json'), JSON.stringify(json, null, ' '));812 // It should not error out813 resolveCache.list()814 .then(function (entries) {815 expect(entries).to.be.an('array');816 expect(entries.length).to.be(1);817 expect(entries[0].pkgMeta).to.eql(json);818 // Packages with invalid metas should have been removed819 expect(fs.existsSync(path.join(sourceDir, '0.0.1'))).to.be(false);820 expect(fs.existsSync(path.join(sourceDir, '0.0.2'))).to.be(false);821 next();822 })823 .done();824 });825 });826 describe('#clearRuntimeCache', function () {827 it('should clear the in-memory cache for all sources', function (next) {828 var source = String(Math.random());829 var sourceId = md5(source);830 var sourceDir = path.join(cacheDir, sourceId);831 var source2 = String(Math.random());832 var sourceId2 = md5(source2);833 var sourceDir2 = path.join(cacheDir, sourceId2);834 // Create some versions835 fs.mkdirSync(sourceDir);836 fs.mkdirSync(path.join(sourceDir, '0.0.1'));837 fs.mkdirSync(sourceDir2);838 fs.mkdirSync(path.join(sourceDir2, '0.0.2'));839 // Feed the cache840 resolveCache.versions(source)841 .then(function () {842 return resolveCache.versions(source2);843 })844 .then(function () {845 // Create some more846 fs.mkdirSync(path.join(sourceDir, '0.0.3'));847 fs.mkdirSync(path.join(sourceDir2, '0.0.4'));848 // Reset cache849 ResolveCache.clearRuntimeCache();850 })851 .then(function () {852 return resolveCache.versions(source)853 .then(function (versions) {854 expect(versions).to.eql(['0.0.3', '0.0.1']);855 return resolveCache.versions(source2);856 })857 .then(function (versions) {858 expect(versions).to.eql(['0.0.4', '0.0.2']);859 next();860 });861 })862 .done();863 });864 });...

Full Screen

Full Screen

project.spec.js

Source:project.spec.js Github

copy

Full Screen

1// Test Modules2import { expect, assert } from 'chai';3import simple, { mock } from 'simple-mock';4// System Modules5import yargs from 'yargs';6import { default as promptly } from 'promptly';7import fs from 'fs';8import util from 'util';9import { bold, green } from 'chalk';10import $LogProvider from 'angie-log';11// Angie Modules12const TEST_ENV = global.TEST_ENV || 'src',13 project = require(`../../../../${TEST_ENV}/util/scaffold/project`),14 $$ProjectCreationError = require(`../../../../${TEST_ENV}/services/$Exceptions`).$$ProjectCreationError,15 p = process;16describe('$$createProject', function() {17 let noop = () => null;18 beforeEach(function() {19 yargs([]);20 mock(fs, 'mkdirSync', noop);21 mock(fs, 'readFileSync', noop);22 mock(util, 'format', () => 'test');23 mock(fs, 'writeFileSync', noop);24 mock($LogProvider, 'info', noop);25 mock(p, 'exit', noop);26 mock(promptly, 'confirm', function(_, fn) {27 fn(null, true);28 });29 mock(promptly, 'prompt', function(_, obj = {}, fn) {30 fn(null, true);31 });32 });33 afterEach(() => simple.restore());34 it('test $$createProject called without a name', function() {35 expect(project).to.throw($$ProjectCreationError);36 });37 it('test $$createProject called without a name', function() {38 expect(project.bind(null, {39 name: '111'40 })).to.throw($$ProjectCreationError);41 expect(project.bind(null, {42 name: '#][]\\$%'43 })).to.throw($$ProjectCreationError);44 });45 it('test $$createProject scaffolding error', function() {46 fs.mkdirSync.returnWith(new Error());47 expect(project).to.throw($$ProjectCreationError);48 });49 it('test successful project creation with directory', function() {50 project({51 name: 'test',52 dir: 'test/'53 });54 expect(fs.mkdirSync.calls[0].args[0]).to.eq('test');55 expect(fs.mkdirSync.calls[1].args[0]).to.eq('test/src');56 expect(fs.mkdirSync.calls[2].args[0]).to.eq('test/src/constants');57 expect(fs.mkdirSync.calls[3].args[0]).to.eq('test/src/configs');58 expect(fs.mkdirSync.calls[4].args[0]).to.eq('test/src/services');59 expect(fs.mkdirSync.calls[5].args[0]).to.eq('test/src/factories');60 expect(fs.mkdirSync.calls[6].args[0]).to.eq('test/src/controllers');61 expect(fs.mkdirSync.calls[7].args[0]).to.eq('test/src/directives');62 expect(fs.mkdirSync.calls[8].args[0]).to.eq('test/test');63 expect(fs.mkdirSync.calls[9].args[0]).to.eq('test/static');64 expect(fs.mkdirSync.calls[10].args[0]).to.eq('test/templates');65 expect(promptly.confirm.calls[0].args[0]).to.eq(66 `${bold(green('Do you want Angie to cache static assets?'))} :`67 );68 expect(util.format.calls[0].args.slice(0, 4)).to.deep.eq([69 fs.readFileSync(70 '../../../../src/templates/json/AngieFile.template.json'71 ),72 'test',73 'test',74 true75 ]);76 expect(util.format.calls[0].args[4].val).to.eq(true);77 expect(fs.writeFileSync.calls[0].args).to.deep.eq([78 'test/AngieFile.json', 'test', 'utf8'79 ]);80 expect(81 $LogProvider.info.calls[0].args[0]82 ).to.eq('Project successfully created');83 expect(p.exit.calls[0].args[0]).to.eq(0);84 });85 it('test successful project creation with -n argument', function() {86 yargs([ '-n', 'test' ]);87 project({88 name: 'test1',89 dir: 'test/'90 });91 expect(fs.mkdirSync.calls[0].args[0]).to.eq('test');92 expect(fs.mkdirSync.calls[1].args[0]).to.eq('test/src');93 expect(fs.mkdirSync.calls[2].args[0]).to.eq('test/src/constants');94 expect(fs.mkdirSync.calls[3].args[0]).to.eq('test/src/configs');95 expect(fs.mkdirSync.calls[4].args[0]).to.eq('test/src/services');96 expect(fs.mkdirSync.calls[5].args[0]).to.eq('test/src/factories');97 expect(fs.mkdirSync.calls[6].args[0]).to.eq('test/src/controllers');98 expect(fs.mkdirSync.calls[7].args[0]).to.eq('test/src/directives');99 expect(fs.mkdirSync.calls[8].args[0]).to.eq('test/test');100 expect(fs.mkdirSync.calls[9].args[0]).to.eq('test/static');101 expect(fs.mkdirSync.calls[10].args[0]).to.eq('test/templates');102 expect(promptly.confirm.calls[0].args[0]).to.eq(103 `${bold(green('Do you want Angie to cache static assets?'))} :`104 );105 expect(util.format.calls[0].args.slice(0, 4)).to.deep.eq([106 fs.readFileSync(107 '../../../../src/templates/json/AngieFile.template.json'108 ),109 'test',110 'test',111 true112 ]);113 expect(util.format.calls[0].args[4].val).to.eq(true);114 expect(fs.writeFileSync.calls[0].args).to.deep.eq([115 'test/AngieFile.json', 'test', 'utf8'116 ]);117 expect(118 $LogProvider.info.calls[0].args[0]119 ).to.eq('Project successfully created');120 expect(p.exit.calls[0].args[0]).to.eq(0);121 });122 it('test successful project creation with --name argument', function() {123 yargs([ '--name', 'test' ]);124 project({125 name: 'test1',126 dir: 'test/'127 });128 expect(fs.mkdirSync.calls[0].args[0]).to.eq('test');129 expect(fs.mkdirSync.calls[1].args[0]).to.eq('test/src');130 expect(fs.mkdirSync.calls[2].args[0]).to.eq('test/src/constants');131 expect(fs.mkdirSync.calls[3].args[0]).to.eq('test/src/configs');132 expect(fs.mkdirSync.calls[4].args[0]).to.eq('test/src/services');133 expect(fs.mkdirSync.calls[5].args[0]).to.eq('test/src/factories');134 expect(fs.mkdirSync.calls[6].args[0]).to.eq('test/src/controllers');135 expect(fs.mkdirSync.calls[7].args[0]).to.eq('test/src/directives');136 expect(fs.mkdirSync.calls[8].args[0]).to.eq('test/test');137 expect(fs.mkdirSync.calls[9].args[0]).to.eq('test/static');138 expect(fs.mkdirSync.calls[10].args[0]).to.eq('test/templates');139 expect(promptly.confirm.calls[0].args[0]).to.eq(140 `${bold(green('Do you want Angie to cache static assets?'))} :`141 );142 expect(util.format.calls[0].args.slice(0, 4)).to.deep.eq([143 fs.readFileSync(144 '../../../../src/templates/json/AngieFile.template.json'145 ),146 'test',147 'test',148 true149 ]);150 expect(util.format.calls[0].args[4].val).to.eq(true);151 expect(fs.writeFileSync.calls[0].args).to.deep.eq([152 'test/AngieFile.json', 'test', 'utf8'153 ]);154 expect(155 $LogProvider.info.calls[0].args[0]156 ).to.eq('Project successfully created');157 expect(p.exit.calls[0].args[0]).to.eq(0);158 });159 it('test successful project creation with directory false confirm', function() {160 mock(promptly, 'confirm', function(_, fn) {161 fn(false);162 });163 mock(promptly, 'prompt', function(_, obj = {}, fn) {164 fn(null, false);165 });166 project({167 name: 'test',168 dir: 'test/'169 });170 expect(fs.mkdirSync.calls[0].args[0]).to.eq('test');171 expect(fs.mkdirSync.calls[1].args[0]).to.eq('test/src');172 expect(fs.mkdirSync.calls[2].args[0]).to.eq('test/src/constants');173 expect(fs.mkdirSync.calls[3].args[0]).to.eq('test/src/configs');174 expect(fs.mkdirSync.calls[4].args[0]).to.eq('test/src/services');175 expect(fs.mkdirSync.calls[5].args[0]).to.eq('test/src/factories');176 expect(fs.mkdirSync.calls[6].args[0]).to.eq('test/src/controllers');177 expect(fs.mkdirSync.calls[7].args[0]).to.eq('test/src/directives');178 expect(fs.mkdirSync.calls[8].args[0]).to.eq('test/test');179 expect(fs.mkdirSync.calls[9].args[0]).to.eq('test/static');180 expect(fs.mkdirSync.calls[10].args[0]).to.eq('test/templates');181 expect(promptly.confirm.calls[0].args[0]).to.eq(182 `${bold(green('Do you want Angie to cache static assets?'))} :`183 );184 assert(promptly.prompt.called);185 expect(util.format.calls[0].args.slice(0, 4)).to.deep.eq([186 fs.readFileSync(187 '../../../../src/templates/json/AngieFile.template.json'188 ),189 'test',190 'test',191 false192 ]);193 expect(util.format.calls[0].args[4].val).to.eq(false);194 expect(fs.writeFileSync.calls[0].args).to.deep.eq([195 'test/AngieFile.json', 'test', 'utf8'196 ]);197 expect(198 $LogProvider.info.calls[0].args[0]199 ).to.eq('Project successfully created');200 expect(p.exit.calls[0].args[0]).to.eq(0);201 });202 it('test successful project creation with "." directory', function() {203 project({204 name: 'test',205 dir: '.'206 });207 expect(fs.mkdirSync.calls[0].args[0]).to.eq('src');208 expect(fs.mkdirSync.calls[1].args[0]).to.eq('src/constants');209 expect(fs.mkdirSync.calls[2].args[0]).to.eq('src/configs');210 expect(fs.mkdirSync.calls[3].args[0]).to.eq('src/services');211 expect(fs.mkdirSync.calls[4].args[0]).to.eq('src/factories');212 expect(fs.mkdirSync.calls[5].args[0]).to.eq('src/controllers');213 expect(fs.mkdirSync.calls[6].args[0]).to.eq('src/directives');214 expect(fs.mkdirSync.calls[7].args[0]).to.eq('test');215 expect(fs.mkdirSync.calls[8].args[0]).to.eq('static');216 expect(fs.mkdirSync.calls[9].args[0]).to.eq('templates');217 expect(promptly.confirm.calls[0].args[0]).to.eq(218 `${bold(green('Do you want Angie to cache static assets?'))} :`219 );220 assert(promptly.prompt.called);221 expect(util.format.calls[0].args.slice(0, 4)).to.deep.eq([222 fs.readFileSync(223 '../../../../src/templates/json/AngieFile.template.json'224 ),225 'test',226 'test',227 true228 ]);229 expect(util.format.calls[0].args[4].val).to.eq(true);230 expect(fs.writeFileSync.calls[0].args).to.deep.eq([231 'AngieFile.json', 'test', 'utf8'232 ]);233 expect(234 $LogProvider.info.calls[0].args[0]235 ).to.eq('Project successfully created');236 expect(p.exit.calls[0].args[0]).to.eq(0);237 });238 it('test successful project creation with -d', function() {239 yargs([ '-d', 'test' ]);240 project({241 name: 'test',242 dir: 'test/'243 });244 expect(fs.mkdirSync.calls[0].args[0]).to.eq('test');245 expect(fs.mkdirSync.calls[1].args[0]).to.eq('test/src');246 expect(fs.mkdirSync.calls[2].args[0]).to.eq('test/src/constants');247 expect(fs.mkdirSync.calls[3].args[0]).to.eq('test/src/configs');248 expect(fs.mkdirSync.calls[4].args[0]).to.eq('test/src/services');249 expect(fs.mkdirSync.calls[5].args[0]).to.eq('test/src/factories');250 expect(fs.mkdirSync.calls[6].args[0]).to.eq('test/src/controllers');251 expect(fs.mkdirSync.calls[7].args[0]).to.eq('test/src/directives');252 expect(fs.mkdirSync.calls[8].args[0]).to.eq('test/test');253 expect(fs.mkdirSync.calls[9].args[0]).to.eq('test/static');254 expect(fs.mkdirSync.calls[10].args[0]).to.eq('test/templates');255 expect(promptly.confirm.calls[0].args[0]).to.eq(256 `${bold(green('Do you want Angie to cache static assets?'))} :`257 );258 expect(util.format.calls[0].args.slice(0, 4)).to.deep.eq([259 fs.readFileSync(260 '../../../../src/templates/json/AngieFile.template.json'261 ),262 'test',263 'test',264 true265 ]);266 expect(util.format.calls[0].args[4].val).to.eq(true);267 expect(fs.writeFileSync.calls[0].args).to.deep.eq([268 'test/AngieFile.json', 'test', 'utf8'269 ]);270 expect(271 $LogProvider.info.calls[0].args[0]272 ).to.eq('Project successfully created');273 expect(p.exit.calls[0].args[0]).to.eq(0);274 });275 it('test successful project creation with --dir', function() {276 yargs([ '--dir', 'test' ]);277 project({278 name: 'test',279 dir: 'test/'280 });281 expect(fs.mkdirSync.calls[0].args[0]).to.eq('test');282 expect(fs.mkdirSync.calls[1].args[0]).to.eq('test/src');283 expect(fs.mkdirSync.calls[2].args[0]).to.eq('test/src/constants');284 expect(fs.mkdirSync.calls[3].args[0]).to.eq('test/src/configs');285 expect(fs.mkdirSync.calls[4].args[0]).to.eq('test/src/services');286 expect(fs.mkdirSync.calls[5].args[0]).to.eq('test/src/factories');287 expect(fs.mkdirSync.calls[6].args[0]).to.eq('test/src/controllers');288 expect(fs.mkdirSync.calls[7].args[0]).to.eq('test/src/directives');289 expect(fs.mkdirSync.calls[8].args[0]).to.eq('test/test');290 expect(fs.mkdirSync.calls[9].args[0]).to.eq('test/static');291 expect(fs.mkdirSync.calls[10].args[0]).to.eq('test/templates');292 expect(promptly.confirm.calls[0].args[0]).to.eq(293 `${bold(green('Do you want Angie to cache static assets?'))} :`294 );295 expect(util.format.calls[0].args.slice(0, 4)).to.deep.eq([296 fs.readFileSync(297 '../../../../src/templates/json/AngieFile.template.json'298 ),299 'test',300 'test',301 true302 ]);303 expect(util.format.calls[0].args[4].val).to.eq(true);304 expect(fs.writeFileSync.calls[0].args).to.deep.eq([305 'test/AngieFile.json', 'test', 'utf8'306 ]);307 expect(308 $LogProvider.info.calls[0].args[0]309 ).to.eq('Project successfully created');310 expect(p.exit.calls[0].args[0]).to.eq(0);311 });312 it('test successful project creation with no directory', function() {313 const CWD = p.cwd();314 project({315 name: 'test'316 });317 expect(fs.mkdirSync.calls[0].args[0]).to.eq(`${CWD}/test`);318 expect(fs.mkdirSync.calls[1].args[0]).to.eq(`${CWD}/test/src`);319 expect(fs.mkdirSync.calls[2].args[0]).to.eq(320 `${CWD}/test/src/constants`321 );322 expect(fs.mkdirSync.calls[3].args[0]).to.eq(323 `${CWD}/test/src/configs`324 );325 expect(fs.mkdirSync.calls[4].args[0]).to.eq(326 `${CWD}/test/src/services`327 );328 expect(fs.mkdirSync.calls[5].args[0]).to.eq(329 `${CWD}/test/src/factories`330 );331 expect(fs.mkdirSync.calls[6].args[0]).to.eq(332 `${CWD}/test/src/controllers`333 );334 expect(fs.mkdirSync.calls[7].args[0]).to.eq(335 `${CWD}/test/src/directives`336 );337 expect(338 fs.mkdirSync.calls[8].args[0]339 ).to.eq(`${CWD}/test/test`);340 expect(341 fs.mkdirSync.calls[9].args[0]342 ).to.eq(`${CWD}/test/static`);343 expect(344 fs.mkdirSync.calls[10].args[0]345 ).to.eq(`${CWD}/test/templates`);346 expect(promptly.confirm.calls[0].args[0]).to.eq(347 `${bold(green('Do you want Angie to cache static assets?'))} :`348 );349 assert(promptly.prompt.called);350 expect(util.format.calls[0].args.slice(0, 4)).to.deep.eq([351 fs.readFileSync(352 '../../../../src/templates/json/AngieFile.template.json'353 ),354 'test',355 'test',356 true357 ]);358 expect(util.format.calls[0].args[4].val).to.eq(true);359 expect(fs.writeFileSync.calls[0].args).to.deep.eq([360 `${CWD}/test/AngieFile.json`, 'test', 'utf8'361 ]);362 expect(363 $LogProvider.info.calls[0].args[0]364 ).to.eq('Project successfully created');365 expect(p.exit.calls[0].args[0]).to.eq(0);366 });...

Full Screen

Full Screen

test-fs-mkdir.js

Source:test-fs-mkdir.js Github

copy

Full Screen

...31}32// fs.mkdir creates directory using assigned path33{34 const pathname = path.join(tmpdir.path, nextdir());35 fs.mkdir(pathname, common.mustCall(function(err) {36 assert.strictEqual(err, null);37 assert.strictEqual(fs.existsSync(pathname), true);38 }));39}40// fs.mkdir creates directory with assigned mode value41{42 const pathname = path.join(tmpdir.path, nextdir());43 fs.mkdir(pathname, 0o777, common.mustCall(function(err) {44 assert.strictEqual(err, null);45 assert.strictEqual(fs.existsSync(pathname), true);46 }));47}48// mkdirSync successfully creates directory from given path49{50 const pathname = path.join(tmpdir.path, nextdir());51 fs.mkdirSync(pathname);52 const exists = fs.existsSync(pathname);53 assert.strictEqual(exists, true);54}55// mkdirSync and mkdir require path to be a string, buffer or url.56// Anything else generates an error.57[false, 1, {}, [], null, undefined].forEach((i) => {58 assert.throws(59 () => fs.mkdir(i, common.mustNotCall()),60 {61 code: 'ERR_INVALID_ARG_TYPE',62 name: 'TypeError'63 }64 );65 assert.throws(66 () => fs.mkdirSync(i),67 {68 code: 'ERR_INVALID_ARG_TYPE',69 name: 'TypeError'70 }71 );72});73// mkdirpSync when both top-level, and sub-folders do not exist.74{75 const pathname = path.join(tmpdir.path, nextdir(), nextdir());76 fs.mkdirSync(pathname, { recursive: true });77 const exists = fs.existsSync(pathname);78 assert.strictEqual(exists, true);79 assert.strictEqual(fs.statSync(pathname).isDirectory(), true);80}81// mkdirpSync when folder already exists.82{83 const pathname = path.join(tmpdir.path, nextdir(), nextdir());84 fs.mkdirSync(pathname, { recursive: true });85 // Should not cause an error.86 fs.mkdirSync(pathname, { recursive: true });87 const exists = fs.existsSync(pathname);88 assert.strictEqual(exists, true);89 assert.strictEqual(fs.statSync(pathname).isDirectory(), true);90}91// mkdirpSync ../92{93 const pathname = `${tmpdir.path}/${nextdir()}/../${nextdir()}/${nextdir()}`;94 fs.mkdirSync(pathname, { recursive: true });95 const exists = fs.existsSync(pathname);96 assert.strictEqual(exists, true);97 assert.strictEqual(fs.statSync(pathname).isDirectory(), true);98}99// mkdirpSync when path is a file.100{101 const pathname = path.join(tmpdir.path, nextdir(), nextdir());102 fs.mkdirSync(path.dirname(pathname));103 fs.writeFileSync(pathname, '', 'utf8');104 assert.throws(105 () => { fs.mkdirSync(pathname, { recursive: true }); },106 {107 code: 'EEXIST',108 message: /EEXIST: .*mkdir/,109 name: 'Error',110 syscall: 'mkdir',111 }112 );113}114// mkdirpSync when part of the path is a file.115{116 const filename = path.join(tmpdir.path, nextdir(), nextdir());117 const pathname = path.join(filename, nextdir(), nextdir());118 fs.mkdirSync(path.dirname(filename));119 fs.writeFileSync(filename, '', 'utf8');120 assert.throws(121 () => { fs.mkdirSync(pathname, { recursive: true }); },122 {123 code: 'ENOTDIR',124 message: /ENOTDIR: .*mkdir/,125 name: 'Error',126 syscall: 'mkdir',127 path: pathname // See: https://github.com/nodejs/node/issues/28015128 }129 );130}131// `mkdirp` when folder does not yet exist.132{133 const pathname = path.join(tmpdir.path, nextdir(), nextdir());134 fs.mkdir(pathname, { recursive: true }, common.mustCall(function(err) {135 assert.strictEqual(err, null);136 assert.strictEqual(fs.existsSync(pathname), true);137 assert.strictEqual(fs.statSync(pathname).isDirectory(), true);138 }));139}140// `mkdirp` when path is a file.141{142 const pathname = path.join(tmpdir.path, nextdir(), nextdir());143 fs.mkdirSync(path.dirname(pathname));144 fs.writeFileSync(pathname, '', 'utf8');145 fs.mkdir(pathname, { recursive: true }, common.mustCall((err) => {146 assert.strictEqual(err.code, 'EEXIST');147 assert.strictEqual(err.syscall, 'mkdir');148 assert.strictEqual(fs.statSync(pathname).isDirectory(), false);149 }));150}151// `mkdirp` when part of the path is a file.152{153 const filename = path.join(tmpdir.path, nextdir(), nextdir());154 const pathname = path.join(filename, nextdir(), nextdir());155 fs.mkdirSync(path.dirname(filename));156 fs.writeFileSync(filename, '', 'utf8');157 fs.mkdir(pathname, { recursive: true }, common.mustCall((err) => {158 assert.strictEqual(err.code, 'ENOTDIR');159 assert.strictEqual(err.syscall, 'mkdir');160 assert.strictEqual(fs.existsSync(pathname), false);161 // See: https://github.com/nodejs/node/issues/28015162 // The path field varies slightly in Windows errors, vs., other platforms163 // see: https://github.com/libuv/libuv/issues/2661, for this reason we164 // use startsWith() rather than comparing to the full "pathname".165 assert(err.path.startsWith(filename));166 }));167}168// mkdirpSync dirname loop169// XXX: windows and smartos have issues removing a directory that you're in.170if (common.isMainThread && (common.isLinux || common.isOSX)) {171 const pathname = path.join(tmpdir.path, nextdir());172 fs.mkdirSync(pathname);173 process.chdir(pathname);174 fs.rmdirSync(pathname);175 assert.throws(176 () => { fs.mkdirSync('X', { recursive: true }); },177 {178 code: 'ENOENT',179 message: /ENOENT: .*mkdir/,180 name: 'Error',181 syscall: 'mkdir',182 }183 );184 fs.mkdir('X', { recursive: true }, (err) => {185 assert.strictEqual(err.code, 'ENOENT');186 assert.strictEqual(err.syscall, 'mkdir');187 });188}189// mkdirSync and mkdir require options.recursive to be a boolean.190// Anything else generates an error.191{192 const pathname = path.join(tmpdir.path, nextdir());193 ['', 1, {}, [], null, Symbol('test'), () => {}].forEach((recursive) => {194 const received = common.invalidArgTypeHelper(recursive);195 assert.throws(196 () => fs.mkdir(pathname, { recursive }, common.mustNotCall()),197 {198 code: 'ERR_INVALID_ARG_TYPE',199 name: 'TypeError',200 message: 'The "options.recursive" property must be of type boolean.' +201 received202 }203 );204 assert.throws(205 () => fs.mkdirSync(pathname, { recursive }),206 {207 code: 'ERR_INVALID_ARG_TYPE',208 name: 'TypeError',209 message: 'The "options.recursive" property must be of type boolean.' +210 received211 }212 );213 });214}215// `mkdirp` returns first folder created, when all folders are new.216{217 const dir1 = nextdir();218 const dir2 = nextdir();219 const firstPathCreated = path.join(tmpdir.path, dir1);220 const pathname = path.join(tmpdir.path, dir1, dir2);221 fs.mkdir(pathname, { recursive: true }, common.mustCall(function(err, path) {222 assert.strictEqual(err, null);223 assert.strictEqual(fs.existsSync(pathname), true);224 assert.strictEqual(fs.statSync(pathname).isDirectory(), true);225 assert.strictEqual(path, firstPathCreated);226 }));227}228// `mkdirp` returns first folder created, when last folder is new.229{230 const dir1 = nextdir();231 const dir2 = nextdir();232 const pathname = path.join(tmpdir.path, dir1, dir2);233 fs.mkdirSync(path.join(tmpdir.path, dir1));234 fs.mkdir(pathname, { recursive: true }, common.mustCall(function(err, path) {235 assert.strictEqual(err, null);236 assert.strictEqual(fs.existsSync(pathname), true);237 assert.strictEqual(fs.statSync(pathname).isDirectory(), true);238 assert.strictEqual(path, pathname);239 }));240}241// `mkdirp` returns undefined, when no new folders are created.242{243 const dir1 = nextdir();244 const dir2 = nextdir();245 const pathname = path.join(tmpdir.path, dir1, dir2);246 fs.mkdirSync(path.join(tmpdir.path, dir1, dir2), { recursive: true });247 fs.mkdir(pathname, { recursive: true }, common.mustCall(function(err, path) {248 assert.strictEqual(err, null);249 assert.strictEqual(fs.existsSync(pathname), true);250 assert.strictEqual(fs.statSync(pathname).isDirectory(), true);251 assert.strictEqual(path, undefined);252 }));253}254// `mkdirp.sync` returns first folder created, when all folders are new.255{256 const dir1 = nextdir();257 const dir2 = nextdir();258 const firstPathCreated = path.join(tmpdir.path, dir1);259 const pathname = path.join(tmpdir.path, dir1, dir2);260 const p = fs.mkdirSync(pathname, { recursive: true });261 assert.strictEqual(fs.existsSync(pathname), true);...

Full Screen

Full Screen

builder.js

Source:builder.js Github

copy

Full Screen

1/**2 * 项目构建模块3 *4 *5 * @desc A generator for building front-end project.6 * @author [@soulteary](soulteary@qq.com)7 * @website http://soulteary.com8 * @date 2015.07.019 */10/* global module */11'use strict';12var fs = require('fs');13var pathPrefix = '../templates/';14var helper = require('../common/helper');15/* istanbul ignore next */16function mixPath(fileName) {17 return pathPrefix + fileName;18}19/* istanbul ignore next */20module.exports = function(yeoman, options) {21 var modeDir = options.mode + '/';22 // .editorconfig23 yeoman.template(mixPath('editorconfig'), '.editorconfig');24 // .gitattributes25 yeoman.template(mixPath('gitattributes'), '.gitattributes');26 // .gittgnore27 yeoman.template(mixPath('gitignore'), '.gitignore');28 // .jscsrc29 yeoman.template(mixPath('jscsrc'), '.jscsrc');30 // .jshintrc31 yeoman.template(mixPath('jshintrc'), '.jshintrc');32 // .npmignore33 yeoman.template(mixPath('npmignore'), '.npmignore');34 // package.json35 yeoman.template(mixPath(modeDir + '_package.json'), 'package.json');36 // README.md37 yeoman.template(mixPath('_README.md'), 'README.md');38 // js tasker39 switch (yeoman.data.tasker.type) {40 case 'gulp':41 yeoman.template(mixPath(modeDir + 'gulpfile.js'), 'gulpfile.js');42 break;43 case 'grunt':44 helper.console.log('grunt待稍后更新。');45 break;46 }47 // LICENSE48 yeoman.template(mixPath('licenses/' + options.license.type), 'LICENSE');49 switch (options.mode) {50 case 'static':51 yeoman.template(mixPath(modeDir + 'robots.txt'), 'robots.txt');52 /**53 ├── .gitignore // git的忽略文件配置54 ├── Gulpfile.js // gulp的任务配置55 ├── README.md // 项目说明56 ├── asset // build后的文件存放位置,与src的目录结构一致57 ├── demo // 开发中的测试demo58 ├── doc // 项目文档59 ├── package.json // 项目package信息及依赖的模块信息配置60 └── src61 ├── font // 字体文件目录62 ├── img // 图片63 ├── js64 │ ├── common // 通用可复用的组件基本功能,与业务无关(复杂功能可在里面再自建目录进行分类)65 │ ├── conf // 配置相关66 │ ├── general // 与业务有关的组件功能或零碎的功能(复杂功能可在里面再自建目录进行分类)67 │ ├── lib //基础库和第三方库68 │ ├── page // 与页面对应的入口文件,加载general中实现的各业务功能69 │ ├── tpl // 模板文件70 │ └── util // 其它各零碎小功能71 └── style // 样式文件目录72 ├── base73 ├── icon74 ├── page75 ├── util76 ├── view77 └── widget78 */79 fs.mkdirSync('asset');80 fs.mkdirSync('demo');81 fs.mkdirSync('demo/asset');82 fs.mkdirSync('doc');83 fs.mkdirSync('src');84 fs.mkdirSync('src/fonts');85 fs.mkdirSync('src/img');86 fs.mkdirSync('src/js');87 fs.mkdirSync('src/js/common');88 fs.mkdirSync('src/js/conf');89 fs.mkdirSync('src/js/general');90 fs.mkdirSync('src/js/lib');91 fs.mkdirSync('src/js/page');92 fs.mkdirSync('src/js/tpl');93 fs.mkdirSync('src/js/util');94 fs.mkdirSync('src/style');95 fs.mkdirSync('src/style/base');96 fs.mkdirSync('src/style/icon');97 fs.mkdirSync('src/style/page');98 fs.mkdirSync('src/style/util');99 fs.mkdirSync('src/style/view');100 fs.mkdirSync('src/style/widget');101 // js lib: jquery102 switch (yeoman.data.js.jquery){103 case 1:104 yeoman.template(mixPath('common/jquery-1.11.3.js'), 'src/js/lib/jquery-1.11.3.js');105 break;106 case 2:107 yeoman.template(mixPath('common/jquery-2.1.4.js'), 'src/js/lib/jquery-2.1.4.js');108 break;109 }110 break;111 default :112 break;113 }...

Full Screen

Full Screen

directoryTests.js

Source:directoryTests.js Github

copy

Full Screen

1var expect = require('chai').expect2 should = require('chai').should()3 sinon = require('sinon')4 proxyquire = require('proxyquire')5 path = require('path')67describe('directory', function () {89 var directory,10 _fs,11 _mocks1213 beforeEach(function () {14 _fs = {15 'access': sinon.stub().callsArgWith(1, new Error()),16 'mkdir': sinon.stub().callsArgWith(1, new Error())17 }18 _mocks = {19 'fs': _fs,20 'original-fs': _fs21 }22 directory = proxyquire('../lib/directory.js', _mocks)23 })2425 it('does not create a directory when dir is root', function (done) {26 directory.create('/', function (err) {27 expect(_fs.mkdir.called).to.be.false28 done();29 })30 })3132 if(require('os').platform() === 'win32') {33 it('does not create a directory when dir is a windows root', function (done) {34 directory.create('C:\\', function (err) {35 expect(_fs.mkdir.called).to.be.false36 done();37 });38 })3940 it('creates a windows directory without errors', function (done) {41 _fs.mkdir.withArgs('C:\\a').callsArg(1);42 directory.create('C:\\a', function (err) {43 expect(err).to.not.be.ok44 expect(_fs.mkdir.called).to.be.true45 done();46 });47 })48 }4950 it('creates a directory without errors', function (done) {51 _fs.mkdir.withArgs('/a').callsArg(1);52 directory.create('/a', function (err) {53 expect(err).to.not.be.ok54 expect(_fs.mkdir.called).to.be.true55 done();56 });57 })5859 it('creates all directories in a path', function (done) {60 _fs.mkdir.withArgs('/a').callsArg(1);61 _fs.mkdir.withArgs('/a/b').callsArg(1);62 _fs.mkdir.withArgs('/a/b/c').callsArg(1);63 _fs.mkdir.withArgs('/a/b/c/d').callsArg(1);64 directory.create('/a/b/c/d', function (err) {65 expect(_fs.mkdir.calledWith('/a')).to.be.true66 expect(_fs.mkdir.calledWith('/a/b')).to.be.true67 expect(_fs.mkdir.calledWith('/a/b/c')).to.be.true68 expect(_fs.mkdir.calledWith('/a/b/c/d')).to.be.true69 done()70 })71 })7273 it('creates directory even if part of path already exists', function (done) {74 _fs.mkdir.withArgs('/a').callsArgWith(1, {code: 'EEXIST'})75 _fs.mkdir.withArgs('/a/b').callsArgWith(1, {code: 'EEXIST'})76 _fs.mkdir.withArgs('/a/b/c').callsArg(1)77 _fs.mkdir.withArgs('/a/b/c/d').callsArg(1)78 directory.create('/a/b/c/d', function (err) {79 expect(_fs.mkdir.calledWith('/a')).to.be.true80 expect(_fs.mkdir.calledWith('/a/b')).to.be.true81 expect(_fs.mkdir.calledWith('/a/b/c')).to.be.true82 expect(_fs.mkdir.calledWith('/a/b/c/d')).to.be.true83 done()84 })85 })8687 it('it succeeds even if path already exists', function (done) {88 _fs.mkdir.callsArgWith(1, {code: 'EEXIST'})89 directory.create('/a/b/c/d', function (err) {90 expect(err).to.be.undefined91 done()92 })93 })9495 it('creates a relative directory', function (done) {96 _fs.mkdir.withArgs('a').callsArg(1);97 directory.create('a', function (err) {98 expect(_fs.mkdir.calledWith('a')).to.be.true99 done()100 })101 })102103 it('creates all relative directories', function (done) {104 _fs.mkdir.withArgs('a').callsArg(1);105 _fs.mkdir.withArgs('a/b').callsArg(1);106 _fs.mkdir.withArgs('a/b/c').callsArg(1);107 directory.create('a/b/c', function (err) {108 expect(_fs.mkdir.calledWith('a')).to.be.true109 expect(_fs.mkdir.calledWith('a/b')).to.be.true110 expect(_fs.mkdir.calledWith('a/b/c')).to.be.true111 done()112 })113 }) ...

Full Screen

Full Screen

FileStream.js

Source:FileStream.js Github

copy

Full Screen

1const fs = require('fs');2exports.createConfigFileInDashboard = (filePath, appName, mode = true,OtherProps) =>{3 let props = '';4 for (const [key, value] of Object.entries(OtherProps)) {5 if(value != undefined)6 props +=`${key}: ${value}, `;7 }8 // if(!fs.existsSync(filePath)){9 let data = `app.constant('config', { APP_NAME :"${appName}", PRODUCTION: ${mode}, ${props} });`;10 fs.writeFileSync(filePath, data)11 // }12};13exports.dataOfStateCitiesFile = () => {14 let data = fs.readFileSync(`${__dirname}/state_cities.json`);15 return (JSON.parse(data))16}17exports.createEssentialDirectories = () => {18 let uploads = './core/uploads';19 let admin = `${uploads}/admin`;20 let download = `${uploads}/download`;21 let franchisee = `${uploads}/franchisee`;22 let offers = `${uploads}/offers`;23 let products = `${uploads}/products`;24 let img = `${products}/img`;25 let techDetails = `${products}/techDetails`;26 let vis = `${products}/vis`;27 let reps = `${uploads}/reps`;28 let temp = `${uploads}/temp`;29 let companyAbout = `${uploads}/companyAbout`;30 let promotinalPics = `${uploads}/promotinalPics`;31 let certificates = `${uploads}/certificates`;32 if(!fs.existsSync(uploads)){33 fs.mkdirSync(uploads);34 fs.mkdirSync(admin);35 fs.mkdirSync(download);36 fs.mkdirSync(franchisee);37 fs.mkdirSync(offers);38 fs.mkdirSync(reps);39 fs.mkdirSync(temp);40 fs.mkdirSync(products);41 fs.mkdirSync(img);42 fs.mkdirSync(techDetails);43 fs.mkdirSync(vis);44 fs.mkdirSync(companyAbout);45 fs.mkdirSync(promotinalPics);46 fs.mkdirSync(certificates);47 }48 else{49 if(!fs.existsSync(admin)) fs.mkdirSync(admin);50 if(!fs.existsSync(download)) fs.mkdirSync(download);51 if(!fs.existsSync(franchisee)) fs.mkdirSync(franchisee);52 if(!fs.existsSync(offers)) fs.mkdirSync(offers);53 if(!fs.existsSync(reps)) fs.mkdirSync(reps);54 if(!fs.existsSync(temp)) fs.mkdirSync(temp);55 if(!fs.existsSync(companyAbout)) fs.mkdirSync(companyAbout);56 if(!fs.existsSync(promotinalPics)) fs.mkdirSync(promotinalPics);57 if(!fs.existsSync(certificates)) fs.mkdirSync(certificates);58 if(!fs.existsSync(products)) fs.mkdirSync(products);59 else{60 if(!fs.existsSync(img)) fs.mkdirSync(img);61 if(!fs.existsSync(techDetails)) fs.mkdirSync(techDetails);62 if(!fs.existsSync(vis)) fs.mkdirSync(vis);63 } 64 }...

Full Screen

Full Screen

Project.js

Source:Project.js Github

copy

Full Screen

1Ext.define('Command.module.Project', {2 extend: 'Command.module.Abstract',3 description: 'Utility actions to work a project',4 actions: {5 create: [6 "Generate a new project with the recommended structure",7 ['name', 'p', 'The name of the application to create', 'string', null, 'MyApp']8 ]9 },10 11 constructor: function() {12 this.templates = {};13 14 this.callParent(arguments);15 },16 create: function(name) {17 this.args = {18 name: name19 };20 21 console.log(this.args);22 23 this.createDirectories(name);24 this.copyFiles(name);25 26 },27 28 createDirectories: function(name) {29 var fs = require('fs'),30 path = require('path');31 32 fs.mkdirSync(name);33 34 fs.mkdirSync(path.join(name, 'app'));35 fs.mkdirSync(path.join(name, 'app', 'model'));36 fs.mkdirSync(path.join(name, 'app', 'view'));37 fs.mkdirSync(path.join(name, 'app', 'controller'));38 fs.mkdirSync(path.join(name, 'app', 'store'));39 fs.mkdirSync(path.join(name, 'app', 'profile'));40 41 fs.mkdirSync(path.join(name, 'deploy'));42 },43 44 template: function(template, destination) {45 var fs = require('fs'),46 path = require('path');47 48 template = this.getTemplate(template);49 50 console.log(template.apply(this.args));51 52 fs.writeFile(path || template, template.apply(this.args));53 },54 55 copyFiles: function(name) {56 var fs = require('fs'),57 path = require('path');58 59 this.template('index.html')60 },61 62 getTemplate: function(name) {63 var templates = this.templates,64 template = templates[name],65 filePath;66 if (!template) {67 filePath = require('path').resolve(this.cli.getCurrentPath(), 'src/module/Project/templates/' + name + '.tpl');68 templates[name] = template = Ext.create('Ext.XTemplate', this.getModule('fs').read(filePath));69 }70 return template;71 }72});73// this.log("Generate application at " + path + " with namespace: " + namespace);74// this.info("Generate application at " + path + " with namespace: " + namespace);75// this.warn("Generate application at " + path + " with namespace: " + namespace);...

Full Screen

Full Screen

rmdir-recursive-test.js

Source:rmdir-recursive-test.js Github

copy

Full Screen

1// rmdir-recursive-test.js2'use strict';3var fs = require('fs');4var rmdirRecursive = require('rmdir-recursive').rmdirRecursive;5var rmdirRecursiveSync = require('rmdir-recursive').rmdirRecursiveSync;6function callback(err) {7 if (err) console.log(err);8}9if (process.platform === 'win32') {10 rmdirRecursiveSync('c:\\xxxx1');11 rmdirRecursiveSync('c:\\wwww1');12 rmdirRecursiveSync('c:/xxxx2');13 rmdirRecursiveSync('c:/wwww2');14 fs.mkdirSync('c:\\xxxx1');15 fs.mkdirSync('c:\\xxxx1\\yyyy');16 fs.mkdirSync('c:\\xxxx1\\yyyy\\zzzz');17 fs.mkdirSync('c:\\wwww1');18 fs.mkdirSync('c:\\wwww1\\xxxx');19 fs.mkdirSync('c:\\wwww1\\xxxx\\yyyy');20 fs.mkdirSync('c:\\wwww1\\xxxx\\yyyy\\xxxx');21 fs.mkdirSync('c:/xxxx2');22 fs.mkdirSync('c:/xxxx2/yyyy');23 fs.mkdirSync('c:/xxxx2/yyyy/zzzz');24 fs.mkdirSync('c:/wwww2');25 fs.mkdirSync('c:/wwww2/xxxx');26 fs.mkdirSync('c:/wwww2/xxxx/yyyy');27 fs.mkdirSync('c:/wwww2/xxxx/yyyy/xxxx');28 rmdirRecursiveSync('c:\\xxxx1');29 rmdirRecursive('c:\\wwww1', callback);30 rmdirRecursiveSync('c:/xxxx2');31 rmdirRecursive('c:/wwww2', callback);32 rmdirRecursive('c:\\xxxx3', callback);33 rmdirRecursive('c:\\wwww3', callback);34 rmdirRecursive('c:/xxxx4', callback);35 rmdirRecursive('c:/wwww4', callback);36}37else {38 rmdirRecursiveSync('/tmp/xxxx1');39 rmdirRecursiveSync('/tmp/wwww1');40 fs.mkdirSync('/tmp/xxxx1');41 fs.mkdirSync('/tmp/xxxx1/yyyy');42 fs.mkdirSync('/tmp/xxxx1/yyyy/zzzz');43 fs.mkdirSync('/tmp/wwww1');44 fs.mkdirSync('/tmp/wwww1/xxxx');45 fs.mkdirSync('/tmp/wwww1/xxxx/yyyy');46 fs.mkdirSync('/tmp/wwww1/xxxx/yyyy/xxxx');47 rmdirRecursiveSync('/tmp/xxxx1');48 rmdirRecursive('/tmp/wwww1', callback);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', function() {2 it('Does not do much!', function() {3 cy.contains('type').click()4 cy.url().should('include', '/commands/actions')5 cy.get('.action-email')6 .type('

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 it('Create a folder', () => {6 cy.writeFile('cypress/fixtures/test.txt', 'Hello world')7 })8})9{10}11describe('My First Test', () => {12 it('Does not do much!', () => {13 expect(true).to.equal(true)14 })15 it('Create a folder', () => {16 cy.readFile('cypress/fixtures/test.txt').should('equal', 'Hello world')17 })18})19{20}21describe('My First Test', () => {22 it('Does not do much!', () => {23 expect(true).to.equal(true)24 })25 it('Create a folder', () => {26 cy.readFile('cypress/fixtures/test.txt').should('equal', 'Hello world')27 })28})29{30}31describe('My First Test', () => {32 it('Does not do much!', () => {33 expect(true).to.equal(true)34 })35 it('Create a folder', () => {36 cy.readFile('cypress/fixtures/test.txt').should('equal', 'Hello world')37 })38})39{40}41describe('My First Test', () => {42 it('Does not do much!', () => {43 expect(true).to.equal(true)44 })45 it('Create a folder', () => {46 cy.readFile('cypress/fixtures/test.txt').should('equal', 'Hello world')47 })48})49{50}51describe('My First Test', () => {52 it('Does not do much!', () => {53 expect(true

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Cypress', () => {2 it('Create a folder', () => {3 cy.task('mkdir', 'cypress/output')4 })5})6describe('Cypress', () => {7 it('Write a file', () => {8 cy.task('writeFile', {9 })10 })11})12describe('Cypress', () => {13 it('Read a file', () => {14 cy.readFile('cypress/output/test.txt').then((text) => {15 console.log(text)16 })17 })18})19describe('Cypress', () => {20 it('Remove a folder', () => {21 cy.task('remove', 'cypress/output')22 })23})24describe('Cypress', () => {25 it('Copy a file', () => {26 cy.task('copy', {27 })28 })29})30describe('Cypress', () => {31 it('Move a file', () => {32 cy.task('move', {33 })34 })35})36describe('Cypress', () => {37 it('Rename a file', () => {38 cy.task('rename', {39 })40 })41})

Full Screen

Using AI Code Generation

copy

Full Screen

1const fs = require('fs');2fs.mkdir('cypress/integration/test', function(err) {3 if (err) {4 console.log(err);5 } else {6 console.log('Directory created successfully!');7 }8});9const fs = require('fs');10fs.writeFile('cypress/integration/test/test.js', 'Hello World!', function(err) {11 if (err) {12 console.log(err);13 } else {14 console.log('File created successfully!');15 }16});17const fs = require('fs');18fs.appendFile('cypress/integration/test/test.js', 'Hello World!', function(err) {19 if (err) {20 console.log(err);21 } else {22 console.log('File updated successfully!');23 }24});25const fs = require('fs');26fs.readFile('cypress/integration/test/test.js', 'utf8', function(err, data) {27 if (err) {28 console.log(err);29 } else {30 console.log(data);31 }32});

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