forked from cypress-io/cypress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrash_spec.js
66 lines (50 loc) · 1.95 KB
/
trash_spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require('../spec_helper')
const fs = require('fs')
const os = require('os')
const path = require('path')
const trash = require(`${root}lib/util/trash`)
const populateDirectories = function (basePath) {
fs.mkdirSync(basePath)
fs.mkdirSync(path.resolve(basePath, 'bar'))
fs.mkdirSync(path.resolve(basePath, 'bar', 'baz'))
fs.writeFileSync(path.resolve(basePath, 'a.txt'), '')
fs.writeFileSync(path.resolve(basePath, 'bar', 'b.txt'), '')
fs.writeFileSync(path.resolve(basePath, 'bar', 'baz', 'c.txt'), '')
expect(fs.existsSync(path.resolve(basePath, 'a.txt'))).to.be.true
expect(fs.existsSync(path.resolve(basePath, 'bar', 'b.txt'))).to.be.true
expect(fs.existsSync(path.resolve(basePath, 'bar', 'baz', 'c.txt'))).to.be.true
}
const expectDirectoriesExist = function (basePath) {
expect(fs.existsSync(basePath)).to.be.true
expect(fs.existsSync(path.resolve(basePath, 'a.txt'))).to.be.false
expect(fs.existsSync(path.resolve(basePath, 'bar', 'b.txt'))).to.be.false
expect(fs.existsSync(path.resolve(basePath, 'bar', 'baz', 'c.txt'))).to.be.false
}
describe('lib/util/trash', () => {
context('.folder', () => {
it('trashes contents of directory in non-Linux', () => {
sinon.stub(os, 'platform').returns('darwin')
const basePath = path.join('foo')
populateDirectories(basePath)
return trash.folder(basePath).then(() => {
expectDirectoriesExist(basePath)
return fs.rmdirSync(basePath)
})
})
it('doesn\'t fail if directory is non-existent', () => {
return trash.folder('bar')
.tapCatch(() => {
throw new Error('should not have errored')
})
})
it('completely removes directory on Linux', () => {
sinon.stub(os, 'platform').returns('linux')
const basePath = path.join('foo')
populateDirectories(basePath)
return trash.folder(basePath).then(() => {
expectDirectoriesExist(basePath)
return fs.rmdirSync(basePath)
})
})
})
})