Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor tests to ES6 #367

Merged
merged 6 commits into from Feb 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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