Skip to content

Commit

Permalink
Merge pull request #372 from JPeer264/feature/refactor-es6
Browse files Browse the repository at this point in the history
Refactor tests to ES6
  • Loading branch information
jprichardson authored Feb 25, 2017
2 parents 0f6d959 + 7bddeb5 commit 42656df
Show file tree
Hide file tree
Showing 21 changed files with 510 additions and 496 deletions.
62 changes: 31 additions & 31 deletions lib/mkdirs/__tests__/chmod.test.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
var assert = require('assert')
var fs = require('fs')
var path = require('path')
var os = require('os')
var fse = require('../../')
'use strict'

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

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

var o755 = parseInt('755', 8)
var o744 = parseInt('744', 8)
var o777 = parseInt('777', 8)
var o666 = parseInt('666', 8)
const o755 = parseInt('755', 8)
const o744 = parseInt('744', 8)
const o777 = parseInt('777', 8)
const o666 = parseInt('666', 8)

describe('mkdirp / chmod', function () {
var TEST_DIR
var TEST_SUBDIR
describe('mkdirp / chmod', () => {
let TEST_DIR
let TEST_SUBDIR

beforeEach(function (done) {
var ps = []
for (var i = 0; i < 15; i++) {
var dir = Math.floor(Math.random() * Math.pow(16, 4)).toString(16)
beforeEach(done => {
const ps = []
for (let i = 0; i < 15; i++) {
const dir = Math.floor(Math.random() * Math.pow(16, 4)).toString(16)
ps.push(dir)
}

Expand All @@ -30,16 +32,14 @@ describe('mkdirp / chmod', function () {
fse.emptyDir(TEST_DIR, done)
})

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

it('chmod-pre', function (done) {
var mode = o744
fse.mkdirp(TEST_SUBDIR, mode, function (er) {
assert.ifError(er, 'should not error')
fs.stat(TEST_SUBDIR, function (er, stat) {
assert.ifError(er, 'should exist')
it('chmod-pre', done => {
const mode = o744
fse.mkdirp(TEST_SUBDIR, mode, err => {
assert.ifError(err, 'should not error')
fs.stat(TEST_SUBDIR, (err, stat) => {
assert.ifError(err, 'should exist')
assert.ok(stat && stat.isDirectory(), 'should be directory')

if (os.platform().indexOf('win') === 0) {
Expand All @@ -53,12 +53,12 @@ describe('mkdirp / chmod', function () {
})
})

it('chmod', function (done) {
var mode = o755
fse.mkdirp(TEST_SUBDIR, mode, function (er) {
assert.ifError(er, 'should not error')
fs.stat(TEST_SUBDIR, function (er, stat) {
assert.ifError(er, 'should exist')
it('chmod', done => {
const mode = o755
fse.mkdirp(TEST_SUBDIR, mode, err => {
assert.ifError(err, 'should not error')
fs.stat(TEST_SUBDIR, (err, stat) => {
assert.ifError(err, 'should exist')
assert.ok(stat && stat.isDirectory(), 'should be directory')
done()
})
Expand Down
40 changes: 21 additions & 19 deletions lib/mkdirs/__tests__/clobber.test.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,48 @@
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 before, describe, it */

var o755 = parseInt('755', 8)
const o755 = parseInt('755', 8)

describe('mkdirp / clobber', function () {
var TEST_DIR
var file
describe('mkdirp / clobber', () => {
let TEST_DIR
let file

before(function (done) {
before(done => {
TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'mkdirp-clobber')
fse.emptyDir(TEST_DIR, function (err) {
fse.emptyDir(TEST_DIR, err => {
assert.ifError(err)

var ps = [TEST_DIR]
const ps = [ TEST_DIR ]

for (var i = 0; i < 15; i++) {
var dir = Math.floor(Math.random() * Math.pow(16, 4)).toString(16)
for (let i = 0; i < 15; i++) {
const dir = Math.floor(Math.random() * Math.pow(16, 4)).toString(16)
ps.push(dir)
}

file = ps.join(path.sep)

// a file in the way
var itw = ps.slice(0, 2).join(path.sep)
const itw = ps.slice(0, 2).join(path.sep)

fs.writeFileSync(itw, 'I AM IN THE WAY, THE TRUTH, AND THE LIGHT.')

fs.stat(itw, function (er, stat) {
assert.ifError(er)
fs.stat(itw, (err, stat) => {
assert.ifError(err)
assert.ok(stat && stat.isFile(), 'should be file')
done()
})
})
})

it('should clobber', function (done) {
fse.mkdirp(file, o755, function (err) {
it('should clobber', done => {
fse.mkdirp(file, o755, err => {
assert.ok(err)
if (os.platform().indexOf('win') === 0) {
assert.equal(err.code, 'EEXIST')
Expand Down
26 changes: 14 additions & 12 deletions lib/mkdirs/__tests__/issue-209.test.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
var assert = require('assert')
var fse = require(process.cwd())
'use strict'

const assert = require('assert')
const fse = require(process.cwd())

/* global describe, it */

describe('mkdirp: issue-209, win32, when bad path, should return a cleaner error', function () {
describe('mkdirp: issue-209, win32, when bad path, should return a cleaner error', () => {
// only seems to be an issue on Windows.
if (process.platform !== 'win32') return

it('should return a callback', function (done) {
var file = './bad?dir'
fse.mkdirp(file, function (err) {
it('should return a callback', done => {
const file = './bad?dir'
fse.mkdirp(file, err => {
assert(err, 'error is present')
assert.strictEqual(err.code, 'EINVAL')

var file2 = 'c:\\tmp\foo:moo'
fse.mkdirp(file2, function (err) {
const file2 = 'c:\\tmp\foo:moo'
fse.mkdirp(file2, err => {
assert(err, 'error is present')
assert.strictEqual(err.code, 'EINVAL')
done()
})
})
})

describe('> sync', function () {
it('should throw an error', function () {
var didErr
describe('> sync', () => {
it('should throw an error', () => {
let didErr
try {
var file = 'c:\\tmp\foo:moo'
const file = 'c:\\tmp\foo:moo'
fse.mkdirpSync(file)
} catch (err) {
// console.error(err)
Expand Down
24 changes: 13 additions & 11 deletions lib/mkdirs/__tests__/issue-93.test.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
var assert = require('assert')
var path = require('path')
var os = require('os')
var fse = require(process.cwd())
'use strict'

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

/* global before, describe, it */

describe('mkdirp: issue-93, win32, when drive does not exist, it should return a cleaner error', function () {
var TEST_DIR
describe('mkdirp: issue-93, win32, when drive does not exist, it should return a cleaner error', () => {
let TEST_DIR

// only seems to be an issue on Windows.
if (process.platform !== 'win32') return

before(function (done) {
before(done => {
TEST_DIR = path.join(os.tmpdir(), 'tests', 'fs-extra', 'mkdirp-issue-93')
fse.emptyDir(TEST_DIR, function (err) {
fse.emptyDir(TEST_DIR, err => {
assert.ifError(err)
done()
})
})

it('should return a cleaner error than inifinite loop, stack crash', function (done) {
var file = 'R:\\afasd\\afaff\\fdfd' // hopefully drive 'r' does not exist on appveyor
fse.mkdirp(file, function (err) {
it('should return a cleaner error than inifinite loop, stack crash', done => {
const file = 'R:\\afasd\\afaff\\fdfd' // hopefully drive 'r' does not exist on appveyor
fse.mkdirp(file, err => {
assert.strictEqual(err.code, 'ENOENT')

try {
Expand Down
50 changes: 25 additions & 25 deletions lib/mkdirs/__tests__/mkdir.test.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
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', 'mkdir')
fse.emptyDir(TEST_DIR, done)
})

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

describe('+ mkdirs()', function () {
it('should make the directory', function (done) {
var dir = path.join(TEST_DIR, 'tmp-' + Date.now() + Math.random())
describe('+ mkdirs()', () => {
it('should make the directory', done => {
const dir = path.join(TEST_DIR, 'tmp-' + Date.now() + Math.random())

assert(!fs.existsSync(dir))

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

it('should make the entire directory path', function (done) {
var dir = path.join(TEST_DIR, 'tmp-' + Date.now() + Math.random())
var newDir = path.join(TEST_DIR, 'dfdf', 'ffff', 'aaa')
it('should make the entire directory path', done => {
const dir = path.join(TEST_DIR, 'tmp-' + Date.now() + Math.random())
const newDir = path.join(TEST_DIR, 'dfdf', 'ffff', 'aaa')

assert(!fs.existsSync(dir))

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

describe('+ mkdirsSync()', function () {
it('should make the directory', function (done) {
var dir = path.join(TEST_DIR, 'tmp-' + Date.now() + Math.random())
describe('+ mkdirsSync()', () => {
it('should make the directory', done => {
const dir = path.join(TEST_DIR, 'tmp-' + Date.now() + Math.random())

assert(!fs.existsSync(dir))
fse.mkdirsSync(dir)
Expand All @@ -56,9 +56,9 @@ describe('fs-extra', function () {
done()
})

it('should make the entire directory path', function (done) {
var dir = path.join(TEST_DIR, 'tmp-' + Date.now() + Math.random())
var newDir = path.join(dir, 'dfdf', 'ffff', 'aaa')
it('should make the entire directory path', done => {
const dir = path.join(TEST_DIR, 'tmp-' + Date.now() + Math.random())
const newDir = path.join(dir, 'dfdf', 'ffff', 'aaa')

assert(!fs.existsSync(newDir))
fse.mkdirsSync(newDir)
Expand Down
44 changes: 22 additions & 22 deletions lib/mkdirs/__tests__/mkdirp.test.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
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 */

var o755 = parseInt('755', 8)
var o777 = parseInt('777', 8)
var o666 = parseInt('666', 8)
const o755 = parseInt('755', 8)
const o777 = parseInt('777', 8)
const o666 = parseInt('666', 8)

describe('mkdirp / mkdirp', function () {
var TEST_DIR
describe('mkdirp / mkdirp', () => {
let TEST_DIR

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

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

it('should make the dir', function (done) {
var x = Math.floor(Math.random() * Math.pow(16, 4)).toString(16)
var y = Math.floor(Math.random() * Math.pow(16, 4)).toString(16)
var z = Math.floor(Math.random() * Math.pow(16, 4)).toString(16)
it('should make the dir', done => {
const x = Math.floor(Math.random() * Math.pow(16, 4)).toString(16)
const y = Math.floor(Math.random() * Math.pow(16, 4)).toString(16)
const z = Math.floor(Math.random() * Math.pow(16, 4)).toString(16)

var file = path.join(TEST_DIR, x, y, z)
const file = path.join(TEST_DIR, x, y, z)

fse.mkdirp(file, o755, function (err) {
fse.mkdirp(file, o755, err => {
assert.ifError(err)
fs.exists(file, function (ex) {
fs.exists(file, ex => {
assert.ok(ex, 'file created')
fs.stat(file, function (err, stat) {
fs.stat(file, (err, stat) => {
assert.ifError(err)

if (os.platform().indexOf('win') === 0) {
Expand Down
Loading

0 comments on commit 42656df

Please sign in to comment.