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 3 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
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
86 changes: 43 additions & 43 deletions lib/ensure/__tests__/ensure.test.js
@@ -1,44 +1,44 @@
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', 'ensure')
fse.emptyDir(TEST_DIR, done)
})

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

describe('+ ensureFile()', function () {
describe('> when file exists', function () {
it('should not do anything', function (done) {
var file = path.join(TEST_DIR, 'file.txt')
describe('+ ensureFile()', () => {
describe('> when file exists', () => {
it('should not do anything', done => {
const file = path.join(TEST_DIR, 'file.txt')
fs.writeFileSync(file, 'blah')

assert(fs.existsSync(file))
fse.ensureFile(file, function (err) {
fse.ensureFile(file, err => {
assert.ifError(err)
assert(fs.existsSync(file))
done()
})
})
})

describe('> when file does not exist', function () {
it('should create the file', function (done) {
var file = path.join(TEST_DIR, 'dir/that/does/not/exist', 'file.txt')
describe('> when file does not exist', () => {
it('should create the file', done => {
const file = path.join(TEST_DIR, 'dir/that/does/not/exist', 'file.txt')

assert(!fs.existsSync(file))
fse.ensureFile(file, function (err) {
fse.ensureFile(file, err => {
assert.ifError(err)
assert(fs.existsSync(file))
done()
Expand All @@ -47,10 +47,10 @@ describe('fs-extra', function () {
})
})

describe('+ ensureFileSync()', function () {
describe('> when file exists', function () {
it('should not do anything', function () {
var file = path.join(TEST_DIR, 'file.txt')
describe('+ ensureFileSync()', () => {
describe('> when file exists', () => {
it('should not do anything', () => {
const file = path.join(TEST_DIR, 'file.txt')
fs.writeFileSync(file, 'blah')

assert(fs.existsSync(file))
Expand All @@ -59,9 +59,9 @@ describe('fs-extra', function () {
})
})

describe('> when file does not exist', function () {
it('should create the file', function () {
var file = path.join(TEST_DIR, 'dir/that/does/not/exist', 'file.txt')
describe('> when file does not exist', () => {
it('should create the file', () => {
const file = path.join(TEST_DIR, 'dir/that/does/not/exist', 'file.txt')

assert(!fs.existsSync(file))
fse.ensureFileSync(file)
Expand All @@ -70,27 +70,27 @@ describe('fs-extra', function () {
})
})

describe('+ ensureDir()', function () {
describe('> when dir exists', function () {
it('should not do anything', function (done) {
var dir = path.join(TEST_DIR, 'dir/does/not/exist')
describe('+ ensureDir()', () => {
describe('> when dir exists', () => {
it('should not do anything', done => {
const dir = path.join(TEST_DIR, 'dir/does/not/exist')
fse.mkdirpSync(dir)

assert(fs.existsSync(dir))
fse.ensureDir(dir, function (err) {
fse.ensureDir(dir, err => {
assert.ifError(err)
assert(fs.existsSync(dir))
done()
})
})
})

describe('> when dir does not exist', function () {
it('should create the dir', function (done) {
var dir = path.join(TEST_DIR, 'dir/that/does/not/exist')
describe('> when dir does not exist', () => {
it('should create the dir', done => {
const dir = path.join(TEST_DIR, 'dir/that/does/not/exist')

assert(!fs.existsSync(dir))
fse.ensureDir(dir, function (err) {
fse.ensureDir(dir, err => {
assert.ifError(err)
assert(fs.existsSync(dir))
done()
Expand All @@ -99,10 +99,10 @@ describe('fs-extra', function () {
})
})

describe('+ ensureDirSync()', function () {
describe('> when dir exists', function () {
it('should not do anything', function () {
var dir = path.join(TEST_DIR, 'dir/does/not/exist')
describe('+ ensureDirSync()', () => {
describe('> when dir exists', () => {
it('should not do anything', () => {
const dir = path.join(TEST_DIR, 'dir/does/not/exist')
fse.mkdirpSync(dir)

assert(fs.existsSync(dir))
Expand All @@ -111,9 +111,9 @@ describe('fs-extra', function () {
})
})

describe('> when dir does not exist', function () {
it('should create the dir', function () {
var dir = path.join(TEST_DIR, 'dir/that/does/not/exist')
describe('> when dir does not exist', () => {
it('should create the dir', () => {
const dir = path.join(TEST_DIR, 'dir/that/does/not/exist')

assert(!fs.existsSync(dir))
fse.ensureDirSync(dir)
Expand Down