Skip to content

Commit

Permalink
Jest
Browse files Browse the repository at this point in the history
  • Loading branch information
pepa65 committed Apr 30, 2021
1 parent 4f3f067 commit 40bb6a0
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 79 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"browser": true,
"node": true,
"es6": true,
"jest": true,
"commonjs": true,
},
"extends": "eslint:recommended",
Expand Down
137 changes: 62 additions & 75 deletions test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,80 +6,67 @@ import spawnRcv from './lib/spawn-receive'
import cleanTmp from './lib/clean-tmp'

describe('Integration', function() {

function getOutFiles(filepath = '') {
const items = fs.readdirSync(path.join('test', 'tmp', filepath))
return items.filter(x => x !== '.gitignore')
}

afterEach(async function() {
await cleanTmp()
})

it('should send/receive single file', async function () {
this.timeout(10000)

const key = await spawnSend('test/fixtures/simple/hello.txt')
await spawnRcv(`${key} --no-prompt`)

expect(getOutFiles()).to.deep.equal(['hello.txt'])
})

it('should fail with non-existing key', function (done) {
(async () => {
this.timeout(20000)

try {
await spawnRcv('62528020ce8814fd5f87c5a7d0402f78ee5f19fd6815c138152f43b306b8f8ef')
}
function getOutFiles(filepath = '') {
const items = fs.readdirSync(path.join('test', 'tmp', filepath))
return items.filter(x => x !== '.gitignore')
}

afterEach(async function() {
await cleanTmp()
})

it('should send/receive single file', async function () {
this.timeout(10000)
const key = await spawnSend('test/fixtures/simple/hello.txt')
await spawnRcv(`${key} --no-prompt`)
expect(getOutFiles()).to.deep.equal(['hello.txt'])
})

it('should fail with non-existing key', function (done) {
(async () => {
this.timeout(20000)
try {
await spawnRcv('62528020ce8814fd5f87c5a7d0402f78ee5f19fd6815c138152f43b306b8f8ef')
}
catch (err) {
done()
}
})()
})

it('should send/receive dirs', async function () {
this.timeout(10000)

const key = await spawnSend('test/fixtures/dirs')
await spawnRcv(`${key} --no-prompt`)

expect(getOutFiles()).to.deep.equal(['dirs'])
expect(getOutFiles('dirs')).to.deep.equal(['dir1', 'dir2'])
expect(getOutFiles('dirs/dir1')).to.deep.equal(['hello.txt'])
expect(getOutFiles('dirs/dir2')).to.deep.equal(['dir3', 'foo.txt'])
expect(getOutFiles('dirs/dir2/dir3')).to.deep.equal(['fizz.txt'])
})

it('should not error when redownloading same files', async function () {
this.timeout(10000)

const key = await spawnSend('test/fixtures/dirs')
await spawnRcv(`${key} --no-prompt`)

expect(getOutFiles()).to.deep.equal(['dirs'])
expect(getOutFiles('dirs')).to.deep.equal(['dir1', 'dir2'])
expect(getOutFiles('dirs/dir1')).to.deep.equal(['hello.txt'])
expect(getOutFiles('dirs/dir2')).to.deep.equal(['dir3', 'foo.txt'])
expect(getOutFiles('dirs/dir2/dir3')).to.deep.equal(['fizz.txt'])

await spawnRcv(`${key} --no-prompt`)

expect(getOutFiles()).to.deep.equal(['dirs'])
expect(getOutFiles('dirs')).to.deep.equal(['dir1', 'dir2'])
expect(getOutFiles('dirs/dir1')).to.deep.equal(['hello.txt'])
expect(getOutFiles('dirs/dir2')).to.deep.equal(['dir3', 'foo.txt'])
expect(getOutFiles('dirs/dir2/dir3')).to.deep.equal(['fizz.txt'])
})

it('should skip non files/dirs', async function () {
this.timeout(10000)

const key = await spawnSend('test/fixtures/complex')
await spawnRcv(`${key} --no-prompt`)

expect(getOutFiles()).to.deep.equal(['complex'])
expect(getOutFiles('complex')).to.deep.equal(['hello.txt'])
})

done()
}
})()
})

it('should send/receive dirs', async function () {
this.timeout(10000)
const key = await spawnSend('test/fixtures/dirs')
await spawnRcv(`${key} --no-prompt`)
expect(getOutFiles()).to.deep.equal(['dirs'])
expect(getOutFiles('dirs')).to.deep.equal(['dir1', 'dir2'])
expect(getOutFiles('dirs/dir1')).to.deep.equal(['hello.txt'])
expect(getOutFiles('dirs/dir2')).to.deep.equal(['dir3', 'foo.txt'])
expect(getOutFiles('dirs/dir2/dir3')).to.deep.equal(['fizz.txt'])
})

it('should not error when redownloading same files', async function () {
this.timeout(10000)
const key = await spawnSend('test/fixtures/dirs')
await spawnRcv(`${key} --no-prompt`)
expect(getOutFiles()).to.deep.equal(['dirs'])
expect(getOutFiles('dirs')).to.deep.equal(['dir1', 'dir2'])
expect(getOutFiles('dirs/dir1')).to.deep.equal(['hello.txt'])
expect(getOutFiles('dirs/dir2')).to.deep.equal(['dir3', 'foo.txt'])
expect(getOutFiles('dirs/dir2/dir3')).to.deep.equal(['fizz.txt'])
await spawnRcv(`${key} --no-prompt`)
expect(getOutFiles()).to.deep.equal(['dirs'])
expect(getOutFiles('dirs')).to.deep.equal(['dir1', 'dir2'])
expect(getOutFiles('dirs/dir1')).to.deep.equal(['hello.txt'])
expect(getOutFiles('dirs/dir2')).to.deep.equal(['dir3', 'foo.txt'])
expect(getOutFiles('dirs/dir2/dir3')).to.deep.equal(['fizz.txt'])
})

it('should skip non files/dirs', async function () {
this.timeout(10000)
const key = await spawnSend('test/fixtures/complex')
await spawnRcv(`${key} --no-prompt`)
expect(getOutFiles()).to.deep.equal(['complex'])
expect(getOutFiles('complex')).to.deep.equal(['hello.txt'])
})
})
8 changes: 4 additions & 4 deletions test/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('Send', function() {
expect(this.infoSpy.firstCall.args[0].includes('Total: 1 files')).to.be.true
expect(this.exitSpy.called).to.be.false
})
/*
/*
it('should dry-run upload single file', (done) => {
(async () => {
const dat = await Dat()
Expand All @@ -72,7 +72,7 @@ describe('Send', function() {
}
})()
})
*/
*/
it('should upload dir with recursive', async () => {
const dat = await Dat()
const sendDatCp = new DatCp(dat, {})
Expand All @@ -99,7 +99,7 @@ describe('Send', function() {
expect(this.infoSpy.firstCall.args[0].includes('Total: 6 files')).to.be.true
expect(this.exitSpy.called).to.be.false
})
/*
/*
it('should dry-run upload directories with recursive', (done) => {
(async () => {
const dat = await Dat()
Expand All @@ -116,7 +116,7 @@ describe('Send', function() {
}
})()
})
*/
*/
it('should skip non files/dirs', async () => {
const dat = await Dat()
const sendDatCp = new DatCp(dat, {})
Expand Down

0 comments on commit 40bb6a0

Please sign in to comment.