Skip to content
This repository was archived by the owner on Aug 20, 2020. It is now read-only.

Commit e41ab40

Browse files
author
Matt Bernier
authored
Merge pull request #58 from mptap/assert-file-exists
Refactored unittest to check for specific repo files to use assert
2 parents acf86ff + 1aba889 commit e41ab40

File tree

1 file changed

+65
-77
lines changed

1 file changed

+65
-77
lines changed

test/test.js

Lines changed: 65 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,11 @@ describe('Client', function () {
216216
it('should limit maxSockets', function (done) {
217217
var expectedSockets = 10
218218
var maxSocketsClient = new Client(globalRequest, expectedSockets)
219-
219+
220220
nock(TEST_HOST)
221221
.get('/testMax')
222222
.reply(200)
223-
223+
224224
// monkey patch the http.request
225225
var http = require('http')
226226
var originalRequest = http.request
@@ -241,94 +241,82 @@ describe('Client', function () {
241241
})
242242
})
243243
})
244+
})
244245

245-
describe('Project files', function () {
246-
it('should have ./Docker file', function (done) {
247-
checkFileOrDirectory('Docker')
248-
done()
249-
})
246+
describe('nodejs-http-client repo', function() {
247+
it('should have ./Dockerfile or docker/Dockerfile', function() {
248+
assert(fileExists('Dockerfile') || fileExists('docker/Dockerfile'));
249+
});
250250

251-
it('should have ./docker-compose.yml file', function (done) {
252-
checkFileOrDirectory('docker-compose.yml')
253-
done()
254-
})
251+
it('should have ./docker-compose.yml or ./docker/docker-compose.yml file', function() {
252+
assert(fileExists('docker-compose.yml') || fileExists('docker/docker-compose.yml'));
253+
});
255254

256-
it('should have ./.env_sample file', function (done) {
257-
checkFileOrDirectory('.env_sample')
258-
done()
259-
})
255+
it('should have ./.env_sample file', function() {
256+
assert(fileExists('.env_sample'));
257+
});
260258

261-
it('should have ./.gitignore file', function (done) {
262-
checkFileOrDirectory('.gitignore')
263-
done()
264-
})
259+
it('should have ./.gitignore file', function() {
260+
assert(fileExists('.gitignore'));
261+
});
265262

266-
it('should have ./.travis.yml file', function (done) {
267-
checkFileOrDirectory('.travis.yml')
268-
done()
269-
})
263+
it('should have ./.travis.yml file', function() {
264+
assert(fileExists('.travis.yml'));
265+
});
270266

271-
it('should have ./.codeclimate.yml file', function (done) {
272-
checkFileOrDirectory('.codeclimate.yml')
273-
done()
274-
})
267+
it('should have ./.codeclimate.yml file', function() {
268+
assert(fileExists('.codeclimate.yml'));
269+
});
275270

276-
it('should have ./CHANGELOG.md file', function (done) {
277-
checkFileOrDirectory('CHANGELOG.md')
278-
done()
279-
})
271+
it('should have ./CHANGELOG.md file', function() {
272+
assert(fileExists('CHANGELOG.md'));
273+
});
280274

281-
it('should have ./CODE_OF_CONDUCT.md file', function (done) {
282-
checkFileOrDirectory('CODE_OF_CONDUCT.md')
283-
done()
284-
})
275+
it('should have ./CODE_OF_CONDUCT.md file', function() {
276+
assert(fileExists('CODE_OF_CONDUCT.md'));
277+
});
285278

286-
it('should have ./CONTRIBUTING.md file', function (done) {
287-
checkFileOrDirectory('CONTRIBUTING.md')
288-
done()
289-
})
279+
it('should have ./CONTRIBUTING.md file', function() {
280+
assert(fileExists('CONTRIBUTING.md'));
281+
});
290282

291-
it('should have ./.github/ISSUE_TEMPLATE file', function (done) {
292-
checkFileOrDirectory('.github/ISSUE_TEMPLATE')
293-
done()
294-
})
283+
it('should have ./.github/ISSUE_TEMPLATE file', function() {
284+
assert(fileExists('.github/ISSUE_TEMPLATE'));
285+
});
295286

296-
it('should have ./LICENSE.md file', function (done) {
297-
checkFileOrDirectory('LICENSE.md')
298-
done()
299-
})
287+
it('should have ./LICENSE.md file', function() {
288+
assert(fileExists('LICENSE.md'));
289+
});
300290

301-
it('should have ./.github/PULL_REQUEST_TEMPLATE file', function (done) {
302-
checkFileOrDirectory('.github/PULL_REQUEST_TEMPLATE')
303-
done()
304-
})
291+
it('should have ./.github/PULL_REQUEST_TEMPLATE file', function() {
292+
assert(fileExists('.github/PULL_REQUEST_TEMPLATE'));
293+
});
305294

306-
it('should have ./README.md file', function (done) {
307-
checkFileOrDirectory('README.md')
308-
done()
309-
})
310-
311-
it('should have ./TROUBLESHOOTING.md file', function (done) {
312-
checkFileOrDirectory('TROUBLESHOOTING.md')
313-
done()
314-
})
315-
316-
it('should have ./USAGE.md file', function (done) {
317-
checkFileOrDirectory('USAGE.md')
318-
done()
319-
})
320-
321-
it('should have ./USE_CASES.md file', function (done) {
322-
checkFileOrDirectory('USE_CASES.md')
323-
done()
324-
})
295+
it('should have ./README.md file', function() {
296+
assert(fileExists('README.md'));
297+
});
325298

326-
function checkFileOrDirectory(fileOrDirectory) {
327-
try {
328-
fs.statSync(fileOrDirectory);
329-
} catch(e) {
330-
assert.isNull(e, 'file or folder doesn\'t exist. '+e);
299+
it('should have ./TROUBLESHOOTING.md file', function() {
300+
assert(fileExists('TROUBLESHOOTING.md'));
301+
});
302+
303+
it('should have ./USAGE.md file', function() {
304+
assert(fileExists('USAGE.md'));
305+
});
306+
307+
it('should have ./USE_CASES.md file', function() {
308+
assert(fileExists('USE_CASES.md'));
309+
});
310+
311+
function fileExists(filepath) {
312+
try {
313+
return fs.statSync(filepath).isFile();
314+
} catch(e) {
315+
if (e.code === 'ENOENT') {
316+
console.log('' + filepath + ' doesn\'t exist.');
317+
return false;
331318
}
319+
throw e;
332320
}
333-
})
334-
})
321+
}
322+
});

0 commit comments

Comments
 (0)