Skip to content

Commit

Permalink
Use await in mocha tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alinex committed May 28, 2017
1 parent 71d0496 commit 745ffce
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 25 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"lib": "./lib"
},
"dependencies": {
"async": "^2.2.0",
"chalk": "^1.1.3",
"debug": "^2.6.3"
},
Expand Down
15 changes: 6 additions & 9 deletions src/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,14 @@ class Compiler {
}

// get list of schema definitions
schema() {
return new Promise((cb) => {
async schema() {
return new Promise((resolve, reject) => {
// get files from
fs.readdir(this.schemaPath, (err, files) => {
if (err) {
return cb(err)
}
files.forEach((file) => {
console.log(file)
})
return cb()
if (err) return reject(err)
const jsFiles = files.filter(file => file.match(/\.js$/))
.map(file => path.join(this.schemaPath, file))
return resolve(jsFiles)
})
})
}
Expand Down
18 changes: 3 additions & 15 deletions test/mocha/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,10 @@ describe('environment', () => {
})
})

it('async await', () => {
function timeout(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

const wait = async () => {
console.log(await timeout(5))
return "done"
}
wait()
})

describe('compiling', () => {
it('have default folders', (cb) => {
it('have default folders', async () => {
const compiler = new Compiler({schemaPath: 'test/data/config'})
compiler.schema()
.then(cb)
const files = await compiler.schema()
console.log(files)
})
})

0 comments on commit 745ffce

Please sign in to comment.