Mani Maghsoudlou 0bc36ffd5e v8 release (#667)
* Remove secure-random from dev-deps (#610)

* fix ensureDir() doc

* moveSync: refactor to use renameSync

* copy*(): fix copying bind-mounted directories (#618)

* copy*(): fix copying bind-mounted dirs

* copy*(): fix case-insensitive-paths tests

* copy*(): refactor to check paths more efficiently

* destructure stats object after checking err

* move*(): check paths before moving

* move*(): add case-insensitive paths test

* remove unnecessary done callback from test

* copy*(): add new option checkPathsBeforeCopying

* update copy*() docs to include checkPathsBeforeCopying

* some reformatting

* copy*(): use fs.stat with bigint option

* move*(): refactor to use the internal stat functions

* move*(): add test for prevent moving identical

* disable graceful-fs in copy and move tests

* fix parsing node version

* tiny reformat

* update copy*() docs

* refactor parsing node version

* use semver to parse node version in tests
2019-05-11 10:08:57 -04:00

124 lines
3.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict'
const assert = require('assert')
const fs = require('fs')
const os = require('os')
const path = require('path')
const randomBytes = require('crypto').randomBytes
const fse = require(process.cwd())
/* global afterEach, beforeEach, describe, it */
let TEST_DIR
function buildFixtureDir () {
const buf = randomBytes(5)
const baseDir = path.join(TEST_DIR, `TEST_fs-extra_remove-${Date.now()}`)
fs.mkdirSync(baseDir)
fs.writeFileSync(path.join(baseDir, Math.random() + ''), buf)
fs.writeFileSync(path.join(baseDir, Math.random() + ''), buf)
const subDir = path.join(TEST_DIR, Math.random() + '')
fs.mkdirSync(subDir)
fs.writeFileSync(path.join(subDir, Math.random() + ''))
return baseDir
}
describe('remove', () => {
beforeEach(done => {
TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'remove')
fse.emptyDir(TEST_DIR, done)
})
afterEach(done => fse.remove(TEST_DIR, done))
describe('+ remove()', () => {
it('should delete an empty directory', done => {
assert(fs.existsSync(TEST_DIR))
fse.remove(TEST_DIR, err => {
assert.ifError(err)
assert(!fs.existsSync(TEST_DIR))
done()
})
})
it('should delete a directory full of directories and files', done => {
buildFixtureDir()
assert(fs.existsSync(TEST_DIR))
fse.remove(TEST_DIR, err => {
assert.ifError(err)
assert(!fs.existsSync(TEST_DIR))
done()
})
})
it('should delete a file', done => {
const file = path.join(TEST_DIR, 'file')
fs.writeFileSync(file, 'hello')
assert(fs.existsSync(file))
fse.remove(file, err => {
assert.ifError(err)
assert(!fs.existsSync(file))
done()
})
})
it('should delete without a callback', done => {
const file = path.join(TEST_DIR, 'file')
fs.writeFileSync(file, 'hello')
assert(fs.existsSync(file))
const existsChecker = setInterval(() => {
fse.pathExists(file, (err, itDoes) => {
assert.ifError(err)
if (!itDoes) {
clearInterval(existsChecker)
done()
}
})
}, 25)
fse.remove(file)
})
it('shouldnt delete glob matches', function (done) {
const file = path.join(TEST_DIR, 'file?')
try {
fs.writeFileSync(file, 'hello')
} catch (ex) {
if (ex.code === 'ENOENT') return this.skip('Windows does not support filenames with ? or * in them.')
throw ex
}
const wrongFile = path.join(TEST_DIR, 'file1')
fs.writeFileSync(wrongFile, 'yo')
assert(fs.existsSync(file))
assert(fs.existsSync(wrongFile))
fse.remove(file, err => {
assert.ifError(err)
assert(!fs.existsSync(file))
assert(fs.existsSync(wrongFile))
done()
})
})
it('shouldnt delete glob matches when file doesnt exist', done => {
const nonexistentFile = path.join(TEST_DIR, 'file?')
const wrongFile = path.join(TEST_DIR, 'file1')
fs.writeFileSync(wrongFile, 'yo')
assert(!fs.existsSync(nonexistentFile))
assert(fs.existsSync(wrongFile))
fse.remove(nonexistentFile, err => {
assert.ifError(err)
assert(!fs.existsSync(nonexistentFile))
assert(fs.existsSync(wrongFile))
done()
})
})
})
})