Skip to content

Commit

Permalink
Create test for creating/reading symlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
KSXGitHub committed May 27, 2018
1 parent e3f59e3 commit 7ec2e2d
Show file tree
Hide file tree
Showing 2 changed files with 289 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,249 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`create function create symlinks with fsx.lstat as options.stat 1`] = `
Object {
"topA": Object {
"toBBB": Symlink {
"linkTarget": "../topB/middleB/bottomB",
},
"toCBA": Symlink {
"linkTarget": "../topC/middleB/bottomA",
},
},
"topB": Object {
"middleA": Object {
"toBCA": Symlink {
"linkTarget": "../../topB/middleC/bottomA",
},
},
"middleB": Object {
"bottomA": Object {},
"bottomB": "B.B.B",
},
"middleC": Object {
"bottomA": "B.C.A",
"bottomB": "B.C.B",
},
},
"topC": Object {
"middleA": Object {
"bottomA": "C.A.A",
"bottomB": "C.A.B",
},
"middleB": Object {
"bottomA": "C.B.A",
"bottomB": "C.B.B",
},
"middleC": Object {
"bottomA": "C.C.A",
"bottomB": "C.C.B",
},
},
"topD": Object {
"toA": Symlink {
"linkTarget": "../topA",
},
"toB": Symlink {
"linkTarget": "../topB",
},
"toC": Symlink {
"linkTarget": "../topC",
},
},
}
`;

exports[`create function create symlinks with fsx.lstatSync as options.stat 1`] = `
Object {
"topA": Object {
"toBBB": Symlink {
"linkTarget": "../topB/middleB/bottomB",
},
"toCBA": Symlink {
"linkTarget": "../topC/middleB/bottomA",
},
},
"topB": Object {
"middleA": Object {
"toBCA": Symlink {
"linkTarget": "../../topB/middleC/bottomA",
},
},
"middleB": Object {
"bottomA": Object {},
"bottomB": "B.B.B",
},
"middleC": Object {
"bottomA": "B.C.A",
"bottomB": "B.C.B",
},
},
"topC": Object {
"middleA": Object {
"bottomA": "C.A.A",
"bottomB": "C.A.B",
},
"middleB": Object {
"bottomA": "C.B.A",
"bottomB": "C.B.B",
},
"middleC": Object {
"bottomA": "C.C.A",
"bottomB": "C.C.B",
},
},
"topD": Object {
"toA": Symlink {
"linkTarget": "../topA",
},
"toB": Symlink {
"linkTarget": "../topB",
},
"toC": Symlink {
"linkTarget": "../topC",
},
},
}
`;

exports[`create function create symlinks with fsx.stat as options.stat 1`] = `
Object {
"topA": Object {
"toBBB": "B.B.B",
"toCBA": "C.B.A",
},
"topB": Object {
"middleA": Object {
"toBCA": "B.C.A",
},
"middleB": Object {
"bottomA": Object {},
"bottomB": "B.B.B",
},
"middleC": Object {
"bottomA": "B.C.A",
"bottomB": "B.C.B",
},
},
"topC": Object {
"middleA": Object {
"bottomA": "C.A.A",
"bottomB": "C.A.B",
},
"middleB": Object {
"bottomA": "C.B.A",
"bottomB": "C.B.B",
},
"middleC": Object {
"bottomA": "C.C.A",
"bottomB": "C.C.B",
},
},
"topD": Object {
"toA": Object {
"toBBB": "B.B.B",
"toCBA": "C.B.A",
},
"toB": Object {
"middleA": Object {
"toBCA": "B.C.A",
},
"middleB": Object {
"bottomA": Object {},
"bottomB": "B.B.B",
},
"middleC": Object {
"bottomA": "B.C.A",
"bottomB": "B.C.B",
},
},
"toC": Object {
"middleA": Object {
"bottomA": "C.A.A",
"bottomB": "C.A.B",
},
"middleB": Object {
"bottomA": "C.B.A",
"bottomB": "C.B.B",
},
"middleC": Object {
"bottomA": "C.C.A",
"bottomB": "C.C.B",
},
},
},
}
`;

exports[`create function create symlinks with fsx.statSync as options.stat 1`] = `
Object {
"topA": Object {
"toBBB": "B.B.B",
"toCBA": "C.B.A",
},
"topB": Object {
"middleA": Object {
"toBCA": "B.C.A",
},
"middleB": Object {
"bottomA": Object {},
"bottomB": "B.B.B",
},
"middleC": Object {
"bottomA": "B.C.A",
"bottomB": "B.C.B",
},
},
"topC": Object {
"middleA": Object {
"bottomA": "C.A.A",
"bottomB": "C.A.B",
},
"middleB": Object {
"bottomA": "C.B.A",
"bottomB": "C.B.B",
},
"middleC": Object {
"bottomA": "C.C.A",
"bottomB": "C.C.B",
},
},
"topD": Object {
"toA": Object {
"toBBB": "B.B.B",
"toCBA": "C.B.A",
},
"toB": Object {
"middleA": Object {
"toBCA": "B.C.A",
},
"middleB": Object {
"bottomA": Object {},
"bottomB": "B.B.B",
},
"middleC": Object {
"bottomA": "B.C.A",
"bottomB": "B.C.B",
},
},
"toC": Object {
"middleA": Object {
"bottomA": "C.A.A",
"bottomB": "C.A.B",
},
"middleB": Object {
"bottomA": "C.B.A",
"bottomB": "C.B.B",
},
"middleC": Object {
"bottomA": "C.C.A",
"bottomB": "C.C.B",
},
},
},
}
`;

exports[`create function creates files/directories that yet to exist 1`] = `
Object {
"flat": Object {
Expand Down
46 changes: 45 additions & 1 deletion packages/typescript/fs-tree-utils/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const oldCwd = cwd()
const tmpContainer = tempPath('fs-tree-utils.')
const tmp = 'tmp'
const {FileSystemRepresentation} = subject
const {File, Directory} = FileSystemRepresentation
const {File, Directory, Symlink} = FileSystemRepresentation

const createTreeGetter = (container: string) => () => Promise.all([
subject.read.nested(container),
Expand Down Expand Up @@ -147,6 +147,50 @@ describe('create function', () => {
await expect(subject.create(expectedTree, container)).rejects.toMatchSnapshot()
})
})

describe('create symlinks', () => {
const mkcreate = (container: string) =>
(tree: any) => subject.create(tree, container)

const createTest = (
basename: string,
stat: subject.NestedReadOptions.StatFunc
) => async () => {
const container = await prepare(basename)
expect(await subject.read.nested(container, {stat})).toMatchSnapshot()
}

it('with fsx.lstat as options.stat', createTest('create.3.0.0', fsx.lstat))
it('with fsx.lstatSync as options.stat', createTest('create.3.0.0', fsx.lstatSync))
it('with fsx.stat as options.stat', createTest('create.3.0.0', fsx.stat))
it('with fsx.statSync as options.stat', createTest('create.3.0.0', fsx.statSync))

async function prepare (basename: string) {
const container = path.join(tmp, basename)
const create = mkcreate(container)
await fsx.remove(container)
await create(tree)

await create({
topA: {
toBBB: new Symlink('../topB/middleB/bottomB'),
toCBA: new Symlink('../topC/middleB/bottomA')
},
topB: {
middleA: {
toBCA: new Symlink('../../topB/middleC/bottomA')
}
},
topD: {
toA: new Symlink('../topA'),
toB: new Symlink('../topB'),
toC: new Symlink('../topC')
}
})

return container
}
})
})

describe('traverse function', () => {
Expand Down

0 comments on commit 7ec2e2d

Please sign in to comment.