Skip to content

Commit

Permalink
Merge pull request #367 from JPeer264/feature/refactor-es6
Browse files Browse the repository at this point in the history
Refactor tests to ES6
  • Loading branch information
jprichardson committed Feb 22, 2017
2 parents 952794b + d24a98b commit 25475c7
Show file tree
Hide file tree
Showing 17 changed files with 593 additions and 637 deletions.
4 changes: 1 addition & 3 deletions lib/copy/__tests__/copy.test.js
Expand Up @@ -18,9 +18,7 @@ describe('fs-extra', () => {
fse.emptyDir(TEST_DIR, done)
})

afterEach(done => {
fse.remove(TEST_DIR, done)
})
afterEach(done => fse.remove(TEST_DIR, done))

describe('+ copy()', () => {
it('should return an error if src and dest are the same', done => {
Expand Down
34 changes: 17 additions & 17 deletions lib/empty/__tests__/empty-dir-sync.test.js
@@ -1,28 +1,28 @@
var assert = require('assert')
var fs = require('fs')
var path = require('path')
var os = require('os')
var fse = require(process.cwd())
'use strict'

const fs = require('fs')
const os = require('os')
const fse = require(process.cwd())
const path = require('path')
const assert = require('assert')

/* global afterEach, beforeEach, describe, it */

describe('+ emptyDir()', function () {
var TEST_DIR
describe('+ emptyDir()', () => {
let TEST_DIR

beforeEach(function () {
beforeEach(() => {
TEST_DIR = path.join(os.tmpdir(), 'test-fs-extra', 'empty-dir')
if (fs.existsSync(TEST_DIR)) {
fse.removeSync(TEST_DIR)
}
fse.ensureDirSync(TEST_DIR)
})

afterEach(function (done) {
fse.remove(TEST_DIR, done)
})
afterEach(done => fse.remove(TEST_DIR, done))

describe('> when directory exists and contains items', function () {
it('should delete all of the items', function () {
describe('> when directory exists and contains items', () => {
it('should delete all of the items', () => {
// verify nothing
assert.equal(fs.readdirSync(TEST_DIR).length, 0)
fse.ensureFileSync(path.join(TEST_DIR, 'some-file'))
Expand All @@ -35,16 +35,16 @@ describe('+ emptyDir()', function () {
})
})

describe('> when directory exists and contains no items', function () {
it('should do nothing', function () {
describe('> when directory exists and contains no items', () => {
it('should do nothing', () => {
assert.equal(fs.readdirSync(TEST_DIR).length, 0)
fse.emptyDirSync(TEST_DIR)
assert.equal(fs.readdirSync(TEST_DIR).length, 0)
})
})

describe('> when directory does not exist', function () {
it('should create it', function () {
describe('> when directory does not exist', () => {
it('should create it', () => {
fse.removeSync(TEST_DIR)
assert(!fs.existsSync(TEST_DIR))
fse.emptyDirSync(TEST_DIR)
Expand Down
40 changes: 20 additions & 20 deletions lib/empty/__tests__/empty-dir.test.js
@@ -1,59 +1,59 @@
var assert = require('assert')
var fs = require('fs')
var path = require('path')
var os = require('os')
var fse = require(process.cwd())
'use strict'

const fs = require('fs')
const os = require('os')
const fse = require(process.cwd())
const path = require('path')
const assert = require('assert')

/* global afterEach, beforeEach, describe, it */

describe('+ emptyDir()', function () {
var TEST_DIR
describe('+ emptyDir()', () => {
let TEST_DIR

beforeEach(function () {
beforeEach(() => {
TEST_DIR = path.join(os.tmpdir(), 'test-fs-extra', 'empty-dir')
if (fs.existsSync(TEST_DIR)) {
fse.removeSync(TEST_DIR)
}
fse.ensureDirSync(TEST_DIR)
})

afterEach(function (done) {
fse.remove(TEST_DIR, done)
})
afterEach(done => fse.remove(TEST_DIR, done))

describe('> when directory exists and contains items', function () {
it('should delete all of the items', function (done) {
describe('> when directory exists and contains items', () => {
it('should delete all of the items', done => {
// verify nothing
assert.equal(fs.readdirSync(TEST_DIR).length, 0)
fse.ensureFileSync(path.join(TEST_DIR, 'some-file'))
fse.ensureFileSync(path.join(TEST_DIR, 'some-file-2'))
fse.ensureDirSync(path.join(TEST_DIR, 'some-dir'))
assert.equal(fs.readdirSync(TEST_DIR).length, 3)

fse.emptyDir(TEST_DIR, function (err) {
fse.emptyDir(TEST_DIR, err => {
assert.ifError(err)
assert.equal(fs.readdirSync(TEST_DIR).length, 0)
done()
})
})
})

describe('> when directory exists and contains no items', function () {
it('should do nothing', function (done) {
describe('> when directory exists and contains no items', () => {
it('should do nothing', done => {
assert.equal(fs.readdirSync(TEST_DIR).length, 0)
fse.emptyDir(TEST_DIR, function (err) {
fse.emptyDir(TEST_DIR, err => {
assert.ifError(err)
assert.equal(fs.readdirSync(TEST_DIR).length, 0)
done()
})
})
})

describe('> when directory does not exist', function () {
it('should create it', function (done) {
describe('> when directory does not exist', () => {
it('should create it', done => {
fse.removeSync(TEST_DIR)
assert(!fs.existsSync(TEST_DIR))
fse.emptyDir(TEST_DIR, function (err) {
fse.emptyDir(TEST_DIR, err => {
assert.ifError(err)
assert.equal(fs.readdirSync(TEST_DIR).length, 0)
done()
Expand Down
54 changes: 27 additions & 27 deletions lib/ensure/__tests__/create.test.js
@@ -1,42 +1,42 @@
var assert = require('assert')
var fs = require('fs')
var path = require('path')
var os = require('os')
var fse = require(process.cwd())
'use strict'

const fs = require('fs')
const os = require('os')
const fse = require(process.cwd())
const path = require('path')
const assert = require('assert')

/* global afterEach, beforeEach, describe, it */

describe('fs-extra', function () {
var TEST_DIR
describe('fs-extra', () => {
let TEST_DIR

beforeEach(function (done) {
beforeEach(done => {
TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'create')
fse.emptyDir(TEST_DIR, done)
})

afterEach(function (done) {
fse.remove(TEST_DIR, done)
})
afterEach(done => fse.remove(TEST_DIR, done))

describe('+ createFile', function () {
describe('> when the file and directory does not exist', function () {
it('should create the file', function (done) {
var file = path.join(TEST_DIR, Math.random() + 't-ne', Math.random() + '.txt')
describe('+ createFile', () => {
describe('> when the file and directory does not exist', () => {
it('should create the file', done => {
const file = path.join(TEST_DIR, Math.random() + 't-ne', Math.random() + '.txt')
assert(!fs.existsSync(file))
fse.createFile(file, function (err) {
fse.createFile(file, err => {
assert.ifError(err)
assert(fs.existsSync(file))
done()
})
})
})

describe('> when the file does exist', function () {
it('should not modify the file', function (done) {
var file = path.join(TEST_DIR, Math.random() + 't-e', Math.random() + '.txt')
describe('> when the file does exist', () => {
it('should not modify the file', done => {
const file = path.join(TEST_DIR, Math.random() + 't-e', Math.random() + '.txt')
fse.mkdirsSync(path.dirname(file))
fs.writeFileSync(file, 'hello world')
fse.createFile(file, function (err) {
fse.createFile(file, err => {
assert.ifError(err)
assert.equal(fs.readFileSync(file, 'utf8'), 'hello world')
done()
Expand All @@ -45,19 +45,19 @@ describe('fs-extra', function () {
})
})

describe('+ createFileSync', function () {
describe('> when the file and directory does not exist', function () {
it('should create the file', function () {
var file = path.join(TEST_DIR, Math.random() + 'ts-ne', Math.random() + '.txt')
describe('+ createFileSync', () => {
describe('> when the file and directory does not exist', () => {
it('should create the file', () => {
const file = path.join(TEST_DIR, Math.random() + 'ts-ne', Math.random() + '.txt')
assert(!fs.existsSync(file))
fse.createFileSync(file)
assert(fs.existsSync(file))
})
})

describe('> when the file does exist', function () {
it('should not modify the file', function () {
var file = path.join(TEST_DIR, Math.random() + 'ts-e', Math.random() + '.txt')
describe('> when the file does exist', () => {
it('should not modify the file', () => {
const file = path.join(TEST_DIR, Math.random() + 'ts-e', Math.random() + '.txt')
fse.mkdirsSync(path.dirname(file))
fs.writeFileSync(file, 'hello world')
fse.createFileSync(file)
Expand Down

0 comments on commit 25475c7

Please sign in to comment.