Best JavaScript code snippet using cypress
symbolic-links.js
Source:symbolic-links.js
1const { defaultOptions, prep, Volume } = require('./_common');2const crypto = require('crypto'),3 clone = require('clone'),4 path = require('path');5describe('When hashing a symbolic link', async function () {6 it('should follow a symbolic link follow=resolve (default)', function () {7 const fs = Volume.fromJSON({ file: 'content' }, 'folder');8 fs.symlinkSync('folder/file', 'soft-link');9 const hash = prep(fs);10 return hash('.', {}).then(result => {11 const symlink = result.children[1];12 // symlink.hash.should.equal(mkhash('soft-link', 'content'));13 symlink.hash.should.equal('BQv/kSJnDNedkXlw/tpcXpf+Mzc=');14 const target = result.children[0].children[0];15 const msg =16 'The symlink name is part of the hash, the symlink and its target must have different hashes';17 symlink.hash.should.not.equal(target.hash, msg);18 });19 });20 it('can skip symbolic links', function () {21 const fs = Volume.fromJSON({ file: 'a' }, 'folder');22 fs.symlinkSync('non-existing', 'l1');23 fs.symlinkSync('folder/file', 'l2');24 const hash = prep(fs);25 const options = { symbolicLinks: { include: false } };26 return Promise.all([27 hash('l1', options).should.eventually.be.undefined,28 hash('l2', options).should.eventually.be.undefined,29 hash('.', options)30 .then(result => result.children.length)31 .should.eventually.become(1),32 ]);33 });34 it('can ignore the target content', async function () {35 const fs = Volume.fromJSON({ file: 'a' }, 'folder');36 fs.symlinkSync('non-existing', 'l1');37 fs.symlinkSync('folder/file', 'l2');38 const hash = prep(fs);39 const options = { symbolicLinks: { ignoreTargetContent: true } };40 const expected = {41 l1: toHash(['l1']),42 l2: toHash(['l2']),43 };44 const l1 = await hash('l1', options);45 l1.hash.should.equal(expected.l1);46 const l2 = await hash('l2', options);47 l2.hash.should.equal(expected.l2);48 });49});50describe('Hashing the symlink to a folder and the folder should return the same hash when', function () {51 it('they have the same basename', async function () {52 const fs = Volume.fromJSON({ a1: 'a', b2: 'bb' }, 'folder');53 fs.mkdirSync('horst');54 fs.symlinkSync('folder', 'horst/folder');55 const hash = prep(fs);56 const options = {57 symbolicLinks: {58 include: true,59 ignoreTargetPath: true,60 },61 };62 const expected = await hash('folder', options);63 const actual = await hash('horst/folder', options);64 actual.should.deep.equal(expected);65 });66 it('the basename is ignored', async function () {67 const fs = Volume.fromJSON({ a1: 'a', b2: 'bb' }, 'folder');68 fs.symlinkSync('folder', 'folder-link');69 const hash = prep(fs);70 const options = {71 folders: { ignoreBasename: true },72 symbolicLinks: {73 ignoreTargetPath: true,74 ignoreBasename: true,75 },76 };77 const expected = await hash('folder', options);78 const actual = await hash('folder-link', options);79 // the names will be different80 delete expected.name;81 delete actual.name;82 actual.should.deep.equal(expected);83 });84});85describe('When symbolicLinks.ignoreTargetContent is true', function () {86 const fs = Volume.fromJSON({ file: 'a' }, 'folder');87 fs.symlinkSync('non-existing', 'l1');88 fs.symlinkSync('folder/file', 'l2');89 fs.symlinkSync('folder', 'l3');90 const hash = prep(fs);91 it('hashes the name and target path', async function () {92 const options = {93 symbolicLinks: {94 include: true,95 ignoreTargetContent: true,96 ignoreTargetPath: false,97 },98 };99 let result = await hash('l2', options);100 const expected = toHash(['l2', path.resolve('folder/file')]);101 return result.hash.should.equal(expected);102 });103 it('hashes the target path', async function () {104 const options = {105 symbolicLinks: {106 include: true,107 ignoreTargetContent: true,108 ignoreTargetPath: false,109 ignoreBasename: true,110 },111 };112 let result = await hash('l2', options);113 const expected = toHash([path.resolve('folder/file')]);114 return result.hash.should.equal(expected);115 });116 it('will not fail if the target is missing', async function () {117 const options = {118 symbolicLinks: {119 include: true,120 ignoreTargetContent: true,121 ignoreTargetPath: false,122 },123 };124 let result = await hash('l1', options);125 const expected = toHash(['l1', path.resolve('non-existing')]);126 return result.hash.should.equal(expected);127 });128});129describe('When symbolicLinks.include equals "resolve"', function () {130 const fs = Volume.fromJSON({ file: 'a' }, 'folder');131 fs.symlinkSync('non-existing', 'l1');132 fs.symlinkSync('folder/file', 'l2');133 fs.symlinkSync('folder', 'l3');134 const hash = prep(fs);135 function hashWithResolvedTargetPath(first, targetPath) {136 const withoutTargetPath = toHash(first);137 return toHash([withoutTargetPath, path.resolve(targetPath)]);138 }139 it('can create a hash over basename file content and target path', async function () {140 const options = {141 symbolicLinks: {142 include: true,143 ignoreTargetPath: false,144 ignoreBasename: false,145 },146 };147 const expected = hashWithResolvedTargetPath(['l2', 'a'], 'folder/file');148 let result = await hash('l2', options);149 return result.hash.should.equal(expected);150 });151 it('can create a hash over target path and file content', async function () {152 const options1 = {153 // this will ignore all file basenames154 files: { ignoreBasename: true },155 symbolicLinks: {156 include: true,157 ignoreTargetPath: false,158 },159 };160 const expected = hashWithResolvedTargetPath(['a'], 'folder/file');161 const result1 = await hash('l2', options1);162 result1.hash.should.equal(expected);163 const options2 = {164 // this will only ignore symbolic link basenames165 files: { ignoreBasename: false },166 symbolicLinks: {167 include: true,168 ignoreTargetPath: false,169 ignoreBasename: true,170 },171 };172 const result2 = await hash('l2', options2);173 return result2.hash.should.equal(result1.hash);174 });175 describe('Issue 41: Ignore missing symbolic link targets', async function () {176 // Note: The different link types are only relevant on windows177 await ['file', 'dir', 'junction'].map(linkType);178 });179});180function linkType(type) {181 describe(`If a "${type}" symlink target does not exist`, function () {182 it('should throw an ENOENT error with default options', function () {183 const fs = new Volume.fromJSON({ file: 'content' });184 fs.symlinkSync('non-existing-file', 'soft-link', type);185 const hash = prep(fs);186 const expected = /ENOENT/;187 return hash('.').should.eventually.be.rejectedWith(expected);188 });189 it('should hash only the name if ignoreTargetContentAfterError is true', function () {190 const fs = Volume.fromJSON({ file: 'content' });191 fs.symlinkSync('non-existing-file', 'soft-link', type);192 const hash = prep(fs);193 const options = { symbolicLinks: { ignoreTargetContentAfterError: true } };194 return hash('.', options).then(result => {195 result.children[1].hash.should.equal('2rAbS3Cr1VJjcXABKQhmBD2SS3s=');196 result.hash.should.equal('EYegpWpT309Zil1L80VZMTy6UZc=');197 });198 });199 it('should hash the name and target path if configured', function () {200 const fs = Volume.fromJSON({ file: 'content' });201 fs.symlinkSync('non-existing-file', 'soft-link', type);202 const hash = prep(fs);203 const options = {204 symbolicLinks: {205 ignoreTargetContentAfterError: true,206 ignoreTargetPath: false,207 },208 };209 return hash('soft-link', options).then(result => {210 const expected = toHash(['soft-link', path.resolve('non-existing-file')]);211 result.hash.should.equal(expected);212 });213 });214 it('should hash the name if all symlink errors are ignored', function () {215 const fs = Volume.fromJSON({ file: 'content' });216 fs.symlinkSync('non-existing-file', 'soft-link', type);217 const hash = prep(fs);218 const options = { symbolicLinks: { ignoreTargetContentAfterError: true } };219 return hash('soft-link', options).then(result => {220 const expected = toHash(['soft-link']);221 result.hash.should.equal(expected);222 });223 });224 });225}226/* helpers */227function toHash(strings) {228 const hash = crypto.createHash(defaultOptions().algo);229 for (const str of strings) {230 hash.update(str);231 }232 return hash.digest(defaultOptions().encoding);...
test-fs-null-bytes.js
Source:test-fs-null-bytes.js
1// Copyright Joyent, Inc. and other Node contributors.2//3// Permission is hereby granted, free of charge, to any person obtaining a4// copy of this software and associated documentation files (the5// "Software"), to deal in the Software without restriction, including6// without limitation the rights to use, copy, modify, merge, publish,7// distribute, sublicense, and/or sell copies of the Software, and to permit8// persons to whom the Software is furnished to do so, subject to the9// following conditions:10//11// The above copyright notice and this permission notice shall be included12// in all copies or substantial portions of the Software.13//14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS15// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF16// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN17// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,18// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR19// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE20// USE OR OTHER DEALINGS IN THE SOFTWARE.21'use strict';22const common = require('../common');23const assert = require('assert');24const fs = require('fs');25const URL = require('url').URL;26function check(async, sync) {27 const expected = /Path must be a string without null bytes/;28 const argsSync = Array.prototype.slice.call(arguments, 2);29 const argsAsync = argsSync.concat((er) => {30 assert(er && expected.test(er.message));31 assert.strictEqual(er.code, 'ENOENT');32 });33 if (sync) {34 assert.throws(() => {35 sync.apply(null, argsSync);36 }, expected);37 }38 if (async) {39 async.apply(null, argsAsync);40 }41}42check(fs.access, fs.accessSync, 'foo\u0000bar');43check(fs.access, fs.accessSync, 'foo\u0000bar', fs.F_OK);44check(fs.appendFile, fs.appendFileSync, 'foo\u0000bar', 'abc');45check(fs.chmod, fs.chmodSync, 'foo\u0000bar', '0644');46check(fs.chown, fs.chownSync, 'foo\u0000bar', 12, 34);47check(fs.link, fs.linkSync, 'foo\u0000bar', 'foobar');48check(fs.link, fs.linkSync, 'foobar', 'foo\u0000bar');49check(fs.lstat, fs.lstatSync, 'foo\u0000bar');50check(fs.mkdir, fs.mkdirSync, 'foo\u0000bar', '0755');51check(fs.open, fs.openSync, 'foo\u0000bar', 'r');52check(fs.readFile, fs.readFileSync, 'foo\u0000bar');53check(fs.readdir, fs.readdirSync, 'foo\u0000bar');54check(fs.readlink, fs.readlinkSync, 'foo\u0000bar');55check(fs.realpath, fs.realpathSync, 'foo\u0000bar');56check(fs.rename, fs.renameSync, 'foo\u0000bar', 'foobar');57check(fs.rename, fs.renameSync, 'foobar', 'foo\u0000bar');58check(fs.rmdir, fs.rmdirSync, 'foo\u0000bar');59check(fs.stat, fs.statSync, 'foo\u0000bar');60check(fs.symlink, fs.symlinkSync, 'foo\u0000bar', 'foobar');61check(fs.symlink, fs.symlinkSync, 'foobar', 'foo\u0000bar');62check(fs.truncate, fs.truncateSync, 'foo\u0000bar');63check(fs.unlink, fs.unlinkSync, 'foo\u0000bar');64check(null, fs.unwatchFile, 'foo\u0000bar', common.mustNotCall());65check(fs.utimes, fs.utimesSync, 'foo\u0000bar', 0, 0);66check(null, fs.watch, 'foo\u0000bar', common.mustNotCall());67check(null, fs.watchFile, 'foo\u0000bar', common.mustNotCall());68check(fs.writeFile, fs.writeFileSync, 'foo\u0000bar', 'abc');69const fileUrl = new URL('file:///C:/foo\u0000bar');70const fileUrl2 = new URL('file:///C:/foo%00bar');71check(fs.access, fs.accessSync, fileUrl);72check(fs.access, fs.accessSync, fileUrl, fs.F_OK);73check(fs.appendFile, fs.appendFileSync, fileUrl, 'abc');74check(fs.chmod, fs.chmodSync, fileUrl, '0644');75check(fs.chown, fs.chownSync, fileUrl, 12, 34);76check(fs.link, fs.linkSync, fileUrl, 'foobar');77check(fs.link, fs.linkSync, 'foobar', fileUrl);78check(fs.lstat, fs.lstatSync, fileUrl);79check(fs.mkdir, fs.mkdirSync, fileUrl, '0755');80check(fs.open, fs.openSync, fileUrl, 'r');81check(fs.readFile, fs.readFileSync, fileUrl);82check(fs.readdir, fs.readdirSync, fileUrl);83check(fs.readlink, fs.readlinkSync, fileUrl);84check(fs.realpath, fs.realpathSync, fileUrl);85check(fs.rename, fs.renameSync, fileUrl, 'foobar');86check(fs.rename, fs.renameSync, 'foobar', fileUrl);87check(fs.rmdir, fs.rmdirSync, fileUrl);88check(fs.stat, fs.statSync, fileUrl);89check(fs.symlink, fs.symlinkSync, fileUrl, 'foobar');90check(fs.symlink, fs.symlinkSync, 'foobar', fileUrl);91check(fs.truncate, fs.truncateSync, fileUrl);92check(fs.unlink, fs.unlinkSync, fileUrl);93check(null, fs.unwatchFile, fileUrl, assert.fail);94check(fs.utimes, fs.utimesSync, fileUrl, 0, 0);95check(null, fs.watch, fileUrl, assert.fail);96check(null, fs.watchFile, fileUrl, assert.fail);97check(fs.writeFile, fs.writeFileSync, fileUrl, 'abc');98check(fs.access, fs.accessSync, fileUrl2);99check(fs.access, fs.accessSync, fileUrl2, fs.F_OK);100check(fs.appendFile, fs.appendFileSync, fileUrl2, 'abc');101check(fs.chmod, fs.chmodSync, fileUrl2, '0644');102check(fs.chown, fs.chownSync, fileUrl2, 12, 34);103check(fs.link, fs.linkSync, fileUrl2, 'foobar');104check(fs.link, fs.linkSync, 'foobar', fileUrl2);105check(fs.lstat, fs.lstatSync, fileUrl2);106check(fs.mkdir, fs.mkdirSync, fileUrl2, '0755');107check(fs.open, fs.openSync, fileUrl2, 'r');108check(fs.readFile, fs.readFileSync, fileUrl2);109check(fs.readdir, fs.readdirSync, fileUrl2);110check(fs.readlink, fs.readlinkSync, fileUrl2);111check(fs.realpath, fs.realpathSync, fileUrl2);112check(fs.rename, fs.renameSync, fileUrl2, 'foobar');113check(fs.rename, fs.renameSync, 'foobar', fileUrl2);114check(fs.rmdir, fs.rmdirSync, fileUrl2);115check(fs.stat, fs.statSync, fileUrl2);116check(fs.symlink, fs.symlinkSync, fileUrl2, 'foobar');117check(fs.symlink, fs.symlinkSync, 'foobar', fileUrl2);118check(fs.truncate, fs.truncateSync, fileUrl2);119check(fs.unlink, fs.unlinkSync, fileUrl2);120check(null, fs.unwatchFile, fileUrl2, assert.fail);121check(fs.utimes, fs.utimesSync, fileUrl2, 0, 0);122check(null, fs.watch, fileUrl2, assert.fail);123check(null, fs.watchFile, fileUrl2, assert.fail);124check(fs.writeFile, fs.writeFileSync, fileUrl2, 'abc');125// an 'error' for exists means that it doesn't exist.126// one of many reasons why this file is the absolute worst.127fs.exists('foo\u0000bar', common.mustCall((exists) => {128 assert(!exists);129}));...
symlinkPackageDependencies.test.js
Source:symlinkPackageDependencies.test.js
1// @flow2import path from 'path';3import symlinkPackageDependencies from '../symlinkPackageDependencies';4import * as fs from '../fs';5import * as yarn from '../yarn';6import Project from '../../Project';7import fixtures from 'fixturez';8const f = fixtures(__dirname);9jest.mock('../yarn');10const unsafeFs: any & typeof fs = fs;11const unsafeYarn: any & typeof yarn = yarn;12async function initProject(fixture) {13 return await Project.init(f.copy(fixture));14}15async function getPackage(project, pkgName) {16 let packages = await project.getPackages();17 let pkg = project.getPackageByName(packages, pkgName);18 if (!pkg) throw new Error(`Missing package ${pkgName}`);19 return pkg;20}21const FIXTURE_NAME = 'nested-workspaces-with-root-dependencies-installed';22describe('utils/symlinkPackageDependencies()', () => {23 test('creates node_modules and node_modules/.bin', async () => {24 let project = await initProject(FIXTURE_NAME);25 let pkg = await getPackage(project, 'foo');26 expect(await fs.dirExists(pkg.nodeModules)).toBe(false);27 expect(await fs.dirExists(pkg.nodeModulesBin)).toBe(false);28 await symlinkPackageDependencies(project, pkg, ['bar']);29 expect(await fs.dirExists(pkg.nodeModules)).toBe(true);30 expect(await fs.dirExists(pkg.nodeModulesBin)).toBe(true);31 });32 test('symlinks external dependencies', async () => {33 let project = await initProject(FIXTURE_NAME);34 let pkg = await getPackage(project, 'foo');35 let depPath = path.join(pkg.nodeModules, 'external-dep');36 expect(await fs.dirExists(depPath)).toBe(false);37 await symlinkPackageDependencies(project, pkg, ['external-dep']);38 expect(await fs.dirExists(depPath)).toBe(true);39 });40 test('symlinks internal dependencies', async () => {41 let project = await initProject(FIXTURE_NAME);42 let pkg = await getPackage(project, 'foo');43 let depPath = path.join(pkg.nodeModules, 'bar');44 expect(await fs.dirExists(depPath)).toEqual(false);45 await symlinkPackageDependencies(project, pkg, ['bar']);46 expect(await fs.dirExists(depPath)).toEqual(true);47 expect(await fs.symlinkExists(depPath)).toEqual(true);48 });49 test('runs correct lifecycle scripts', async () => {50 let project = await initProject(FIXTURE_NAME);51 let pkg = await getPackage(project, 'foo');52 await symlinkPackageDependencies(project, pkg, ['bar']);53 expect(yarn.runIfExists).toHaveBeenCalledTimes(4);54 expect(unsafeYarn.runIfExists.mock.calls[0][1]).toEqual('preinstall');55 expect(unsafeYarn.runIfExists.mock.calls[1][1]).toEqual('postinstall');56 expect(unsafeYarn.runIfExists.mock.calls[2][1]).toEqual('prepublish');57 expect(unsafeYarn.runIfExists.mock.calls[3][1]).toEqual('prepare');58 });59 test('symlinks external deps bins (string)', async () => {60 let project = await initProject(FIXTURE_NAME);61 let pkg = await getPackage(project, 'zee');62 let symPath = path.join(pkg.nodeModulesBin, 'external-dep-with-bin');63 expect(await fs.symlinkExists(symPath)).toEqual(false);64 await symlinkPackageDependencies(project, pkg, ['external-dep-with-bin']);65 expect(await fs.symlinkExists(symPath)).toEqual(true);66 });67 test('symlinks external deps bins (object)', async () => {68 let project = await initProject(FIXTURE_NAME);69 let pkg = await getPackage(project, 'zee');70 let symPath = path.join(pkg.nodeModulesBin, 'external-dep-two-bins-1');71 expect(await fs.symlinkExists(symPath)).toEqual(false);72 await symlinkPackageDependencies(project, pkg, [73 'external-dep-with-two-bins'74 ]);75 expect(await fs.symlinkExists(symPath)).toEqual(true);76 });77 test('symlinks internal deps bins (string)', async () => {78 let project = await initProject(FIXTURE_NAME);79 let pkg = await getPackage(project, 'zee');80 let symPath = path.join(pkg.nodeModulesBin, 'bar');81 expect(await fs.symlinkExists(symPath)).toEqual(false);82 await symlinkPackageDependencies(project, pkg, ['bar']);83 expect(await fs.symlinkExists(symPath)).toEqual(true);84 });85 test('symlinks internal deps bins (when declared using object)', async () => {86 let project = await initProject(FIXTURE_NAME);87 let pkg = await getPackage(project, 'zee');88 let baz1Path = path.join(pkg.nodeModulesBin, 'baz-1');89 let baz2Path = path.join(pkg.nodeModulesBin, 'baz-2');90 expect(await fs.symlinkExists(baz1Path)).toEqual(false);91 expect(await fs.symlinkExists(baz2Path)).toEqual(false);92 await symlinkPackageDependencies(project, pkg, ['baz']);93 expect(await fs.symlinkExists(baz1Path)).toEqual(true);94 expect(await fs.symlinkExists(baz2Path)).toEqual(true);95 });...
test-fs-symlink.js
Source:test-fs-symlink.js
...32tmpdir.refresh();33// Test creating and reading symbolic link34const linkData = fixtures.path('/cycles/root.js');35const linkPath = path.join(tmpdir.path, 'symlink1.js');36fs.symlink(linkData, linkPath, common.mustSucceed(() => {37 fs.lstat(linkPath, common.mustSucceed((stats) => {38 linkTime = stats.mtime.getTime();39 }));40 fs.stat(linkPath, common.mustSucceed((stats) => {41 fileTime = stats.mtime.getTime();42 }));43 fs.readlink(linkPath, common.mustSucceed((destination) => {44 assert.strictEqual(destination, linkData);45 }));46}));47// Test invalid symlink48{49 const linkData = fixtures.path('/not/exists/file');50 const linkPath = path.join(tmpdir.path, 'symlink2.js');51 fs.symlink(linkData, linkPath, common.mustSucceed(() => {52 assert(!fs.existsSync(linkPath));53 }));54}55[false, 1, {}, [], null, undefined].forEach((input) => {56 const errObj = {57 code: 'ERR_INVALID_ARG_TYPE',58 name: 'TypeError',59 message: /target|path/60 };61 assert.throws(() => fs.symlink(input, '', common.mustNotCall()), errObj);62 assert.throws(() => fs.symlinkSync(input, ''), errObj);63 assert.throws(() => fs.symlink('', input, common.mustNotCall()), errObj);64 assert.throws(() => fs.symlinkSync('', input), errObj);65});66const errObj = {67 code: 'ERR_FS_INVALID_SYMLINK_TYPE',68 name: 'Error',69 message:70 'Symlink type must be one of "dir", "file", or "junction". Received "ð"'71};72assert.throws(() => fs.symlink('', '', 'ð', common.mustNotCall()), errObj);73assert.throws(() => fs.symlinkSync('', '', 'ð'), errObj);74process.on('exit', () => {75 assert.notStrictEqual(linkTime, fileTime);...
index.js
Source:index.js
1import test from 'ava'2import fs from 'fs-extra'3import path from 'path'4import dereference from '../'5test('objects to missing directory argument', t => {6 t.throws(() => dereference(), /Please specify a directory/)7})8const tmpDirPath = path.join(process.cwd(), 'tmp')9const dirPath = path.join(tmpDirPath, 'test')10const subDirPath = path.join(dirPath, 'sub')11const otherDirPath = path.join(tmpDirPath, 'other')12const symlinkedOtherDirPath = path.join(dirPath, 'link')13const binPath = path.join(tmpDirPath, '.bin')14const otherBinPath = path.join(otherDirPath, '.bin')15const files = {16 a: path.join(dirPath, 'a.txt'),17 b: path.join(dirPath, 'b.txt'),18 c: path.join(subDirPath, 'c.txt'),19 d: path.join(dirPath, 'd.txt'),20 e: path.join(subDirPath, 'e.txt'),21 f: path.join(dirPath, 'f.txt'),22 g: path.join(otherDirPath, 'g.txt'),23 h: path.join(otherDirPath, 'h.txt'),24 i: path.join(binPath, 'i.txt'),25 j: path.join(otherBinPath, 'j.txt')26}27test.before(() => {28 if (fs.existsSync(tmpDirPath)) {29 fs.removeSync(tmpDirPath)30 }31 fs.mkdirSync(tmpDirPath)32 fs.mkdirSync(dirPath)33 fs.mkdirSync(subDirPath)34 fs.mkdirSync(otherDirPath)35 fs.mkdirSync(binPath)36 fs.mkdirSync(otherBinPath)37 fs.writeFileSync(files.a, 'a')38 fs.writeFileSync(files.b, 'b')39 fs.writeFileSync(files.c, 'c')40 fs.writeFileSync(files.g, 'g')41 fs.symlinkSync(files.a, files.d)42 fs.symlinkSync(files.b, files.e)43 fs.symlinkSync(files.c, files.f)44 fs.symlinkSync(files.a, files.h)45 fs.symlinkSync(files.a, files.i)46 fs.symlinkSync(files.g, files.j)47 fs.symlinkSync(otherDirPath, symlinkedOtherDirPath)48})49test.after.always(() => {50 fs.removeSync(tmpDirPath)51})52test('should defereference symlinks', t => {53 t.truthy(fs.lstatSync(files.d).isSymbolicLink())54 t.truthy(fs.lstatSync(files.e).isSymbolicLink())55 t.truthy(fs.lstatSync(files.f).isSymbolicLink())56 t.truthy(fs.lstatSync(symlinkedOtherDirPath).isSymbolicLink())57 t.truthy(fs.lstatSync(files.h).isSymbolicLink())58 dereference(dirPath)59 t.is('a', fs.readFileSync(files.d, 'utf8'))60 t.is('b', fs.readFileSync(files.e, 'utf8'))61 t.is('c', fs.readFileSync(files.f, 'utf8'))62 t.is('g', fs.readFileSync(files.g, 'utf8'))63 t.is('a', fs.readFileSync(files.h, 'utf8'))64 t.falsy(fs.lstatSync(files.d).isSymbolicLink())65 t.falsy(fs.lstatSync(files.e).isSymbolicLink())66 t.falsy(fs.lstatSync(files.f).isSymbolicLink())67 t.falsy(fs.lstatSync(files.g).isSymbolicLink())68 t.falsy(fs.lstatSync(files.h).isSymbolicLink())69 t.falsy(fs.lstatSync(symlinkedOtherDirPath).isSymbolicLink())70 t.truthy(fs.lstatSync(files.i).isSymbolicLink())71 t.truthy(fs.lstatSync(files.j).isSymbolicLink())...
test.js
Source:test.js
1'use strict';2var fs = require('fs-extra');3var path = require('path');4var expect = require('chai').expect;5var exists = require('./');6var root = process.cwd();7var tmpdir = path.join(root, 'tmp');8describe('exists-sync', function() {9 var tmp;10 beforeEach(function() {11 fs.mkdirsSync('./tmp');12 fs.writeFileSync('./tmp/taco.js', 'TACO!');13 fs.symlinkSync('./tmp/taco.js', './tmp/link-to-taco.js');14 });15 16 afterEach(function() {17 fs.deleteSync('./tmp');18 });19 it('verifies files exist', function() {20 expect(exists('./tmp/taco.js')).to.be.true;21 expect(exists('./taco.js')).to.be.false;22 });23 24 it('works with symlinks', function() {25 expect(exists('./tmp/link-to-taco.js'), 'symlink').to.be.true;26 });27 28});29describe('exists-sync symlinks', function(){ 30 var tmp;31 beforeEach(function() {32 fs.mkdirsSync('./tmp');33 fs.writeFileSync('./tmp/taco.js', 'TACO!');34 fs.writeFileSync('./tmp/burrito.js', 'BURRITO!');35 fs.symlinkSync('./tmp/taco.js', './tmp/link-to-taco.js');36 fs.symlinkSync('./tmp/burrito.js', './tmp/link-to-burrito.js');37 });38 39 afterEach(function() {40 fs.deleteSync('./tmp');41 });42 43 it('verifies symlink targets', function() {44 expect(exists('./tmp/link-to-burrito.js'), 'symlink').to.be.true;45 fs.deleteSync('./tmp/burrito.js');46 expect(exists('./tmp/link-to-burrito.js'), 'dead symlink').to.be.false;47 });48 49 it('verifies symlinked symlinks', function() {50 fs.symlinkSync('./tmp/link-to-taco.js', './tmp/link-to-taco-link.js');51 process.chdir(tmpdir);52 fs.symlinkSync('../link-to-taco.js', '../tmp/rel-link-to-taco.js');53 process.chdir(root);54 fs.mkdirSync('./tmp/symlinks');55 fs.symlinkSync('./tmp/link-to-taco-link.js', './tmp/symlinks/link-to-taco-link.js');56 57 expect(exists('./tmp/link-to-taco-link.js'), 'symlinked symlink').to.be.true;58 expect(exists('./tmp/rel-link-to-taco.js'), 'I heard you like relative symlinks').to.be.true;59 // symlink made from dir other than root60 expect(exists('./tmp/symlinks/link-to-taco-link.js'), 'I heard you like bad symlinks').to.be.true;61 });62 63 it('guards against cyclic symlinks', function() {64 fs.symlinkSync('./tmp/link-to-taco.js', './tmp/link-to-taco-back.js');65 fs.unlinkSync('./tmp/link-to-taco.js');66 fs.symlinkSync('./tmp/link-to-taco-back.js', './tmp/link-to-taco.js');67 expect(exists.bind(this,'./tmp/link-to-taco.js'), 'cyclic hell').to.throw(Error);//(/Circular symlink detected/);68 });...
copy-symlink.test.js
Source:copy-symlink.test.js
1'use strict';2const fs = require('fs');3const path = require('path');4const test = require('ava');5const mockFs = require('mock-fs');6const copySymlink = require('../../lib/fs').copySymlink;7test.afterEach(() => mockFs.restore());8test('should throw error if file is not found', t => {9 mockFs({});10 t.throws(copySymlink('file.txt', 'symlink2.txt'));11});12test('should throw error if file is not symlink', async t => {13 mockFs({14 'file.txt': ''15 });16 t.throws(copySymlink('file.txt', 'symlink2.txt'));17});18test('should create symlink', async t => {19 mockFs({20 'file.txt': '',21 'symlink.txt': mockFs.symlink({22 path: 'file.txt'23 })24 });25 await copySymlink('symlink.txt', 'symlink2.txt');26 t.is(fs.readlinkSync('symlink2.txt'), 'file.txt');27});28test('should create dir', async t => {29 mockFs({30 'file.txt': '',31 'symlink.txt': mockFs.symlink({32 path: 'file.txt'33 })34 });35 await copySymlink('symlink.txt', path.join('dir', 'symlink2.txt'));36 t.deepEqual(fs.readdirSync('dir'), ['symlink2.txt']);37});38test('should not create dir if already exists', async t => {39 mockFs({40 'file.txt': '',41 'symlink.txt': mockFs.symlink({42 path: 'file.txt'43 }),44 'dir': {}45 });46 await copySymlink('symlink.txt', path.join('dir', 'symlink2.txt'));47 t.deepEqual(fs.readdirSync('dir'), ['symlink2.txt']);48});49test('should not change target path', async t => {50 mockFs({51 'file.txt': '',52 'symlink.txt': mockFs.symlink({53 path: 'file.txt'54 })55 });56 await copySymlink('symlink.txt', path.join('dir', 'symlink2.txt'));57 t.is(fs.readlinkSync(path.join('dir','symlink2.txt')), 'file.txt');58});59test('should use specified fs', async t => {60 mockFs({61 'file.txt': '',62 'symlink.txt': mockFs.symlink({63 path: 'file.txt'64 })65 });66 const userFs = {67 readlink: (file, cb) => cb(null, 'fake_target'),68 symlink: fs.symlink,69 mkdir: fs.mkdir,70 stat: fs.stat71 };72 await copySymlink('symlink.txt', 'symlink2.txt', { fs: userFs });73 t.is(fs.readlinkSync('symlink2.txt'), 'fake_target');...
test-fs-symlink-dir-junction-relative.js
Source:test-fs-symlink-dir-junction-relative.js
...10var linkPath2 = path.join(common.tmpDir, 'junction2');11var linkTarget = path.join(common.fixturesDir);12var linkData = path.join(common.fixturesDir);13common.refreshTmpDir();14// Test fs.symlink()15fs.symlink(linkData, linkPath1, 'junction', function(err) {16 if (err) throw err;17 verifyLink(linkPath1);18});19// Test fs.symlinkSync()20fs.symlinkSync(linkData, linkPath2, 'junction');21verifyLink(linkPath2);22function verifyLink(linkPath) {23 var stats = fs.lstatSync(linkPath);24 assert.ok(stats.isSymbolicLink());25 var data1 = fs.readFileSync(linkPath + '/x.txt', 'ascii');26 var data2 = fs.readFileSync(linkTarget + '/x.txt', 'ascii');27 assert.strictEqual(data1, data2);28 // Clean up.29 fs.unlinkSync(linkPath);...
Using AI Code Generation
1cy.readFile('cypress/fixtures/test.json').then((fileContent) => {2 cy.writeFile('cypress/fixtures/test2.json', fileContent)3 cy.writeFile('cypress/fixtures/test3.json', fileContent)4 cy.writeFile('cypress/fixtures/test4.json', fileContent)5 cy.writeFile('cypress/fixtures/test5.json', fileContent)6 cy.writeFile('cypress/fixtures/test6.json', fileContent)7 cy.writeFile('cypress/fixtures/test7.json', fileContent)8 cy.writeFile('cypress/fixtures/test8.json', fileContent)9 cy.writeFile('cypress/fixtures/test9.json', fileContent)10 cy.writeFile('cypress/fixtures/test10.json', fileContent)11 cy.writeFile('cypress/fixtures/test11.json', fileContent)12 cy.writeFile('cypress/fixtures/test12.json', fileContent)13 cy.writeFile('cypress/fixtures/test13.json', fileContent)14 cy.writeFile('cypress/fixtures/test14.json', fileContent)15 cy.writeFile('cypress/fixtures/test15.json', fileContent)16 cy.writeFile('cypress/fixtures/test16.json', fileContent)17 cy.writeFile('cypress/fixtures/test17.json', fileContent)18 cy.writeFile('cypress/fixtures/test18.json', fileContent)19 cy.writeFile('cypress/fixtures/test19.json', fileContent)20 cy.writeFile('cypress/fixtures/test20.json', fileContent)21 cy.writeFile('cypress/fixtures/test21.json', fileContent)22 cy.writeFile('cypress/fixtures/test22.json', fileContent)23 cy.writeFile('cypress/fixtures/test23.json', fileContent)24 cy.writeFile('cypress/fixtures/test24.json', fileContent)25 cy.writeFile('cypress/fixtures/test25.json', fileContent)26 cy.writeFile('cypress/fixtures/test26.json', fileContent)27 cy.writeFile('cypress/fixtures/test27.json', fileContent)28 cy.writeFile('cypress/fixtures/test28.json', fileContent)29 cy.writeFile('cypress/fixtures/test29.json', fileContent)30 cy.writeFile('cypress/fixtures/test30.json', fileContent)31 cy.writeFile('cypress/fixtures/test31.json', fileContent)32 cy.writeFile('cypress/fixtures/test32.json', fileContent)33 cy.writeFile('cypress/fixtures/test33.json', fileContent)34 cy.writeFile('cypress/fixtures/test34.json', fileContent)35 cy.writeFile('cypress/fixtures/test35.json', fileContent)36 cy.writeFile('cypress/fixtures
Using AI Code Generation
1const fs = require('fs');2const path = require('path');3const rootPath = path.resolve(__dirname, '..');4fs.symlink(path.join(rootPath, 'cypress'), path.join(rootPath, 'node_modules', 'cypress'), 'junction', err => {5 if (err) {6 throw err;7 }8});9"scripts": {10}
Using AI Code Generation
1const fs = require("fs");2const path = require("path");3const target = path.join(__dirname, "fixtures", "some-file.txt");4const link = path.join(__dirname, "fixtures", "link-to-file.txt");5fs.symlinkSync(target, link);6describe("Test", () => {7it("Test", () => {8cy.visit("/");9cy.get("input").type("some text");10cy.get("button").click();11});12});13{14"env": {15},
Using AI Code Generation
1const fs = require("fs");2fs.symlink("test.js", "cypress/fixtures/test.js", (err) => {3 if (err) throw err;4 console.log("Symbolic link created successfully");5});6describe("Symbolic Link Test", () => {7 it("Should open the test.js file", () => {8 cy.get("#cy-fixture-test-js").click();9 cy.get(".language-javascript").contains("describe");10 });11});12describe("Symbolic Link Test", () => {13 it("Should open the test.js file", () => {14 cy.get("#cy-fixture-test-js").click();15 cy.get(".language-javascript").contains("describe");16 });17});18{19}20describe("Symbolic Link Test", () => {21 it("Should open the test.js file", () => {22 cy.get("#cy-fixture-test-js").click();23 cy.get(".language-javascript").contains("describe");24 });25});26describe("Symbolic Link Test", () => {27 it("Should open the test.js file", () => {28 cy.get("#cy-fixture-test-js").click();29 cy.get(".language-javascript").contains("describe");30 });31});32{33}
Using AI Code Generation
1Cypress.Commands.add("createSymLink", () => {2 cy.exec("cd fixtures && ln -s test.txt test.txt", {3 });4});5Cypress.Commands.add("removeSymLink", () => {6 cy.exec("cd fixtures && unlink test.txt", {7 });8});9Cypress.Commands.add("removeFile", () => {10 cy.exec("cd fixtures && rm test.txt", {11 });12});13Cypress.Commands.add("removeFile", () => {14 cy.exec("cd fixtures && rm test.txt", {15 });16});17Cypress.Commands.add("removeFile", () => {18 cy.exec("cd fixtures && rm test.txt", {19 });20});21Cypress.Commands.add("removeFile", () => {22 cy.exec("cd fixtures && rm test.txt", {23 });24});25Cypress.Commands.add("removeFile", () => {26 cy.exec("cd fixtures && rm test.txt", {27 });28});29Cypress.Commands.add("removeFile", () => {30 cy.exec("cd fixtures && rm test.txt", {31 });32});33Cypress.Commands.add("removeFile", () => {
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.
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.
Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.
Get 100 minutes of automation test minutes FREE!!