aboutsummaryrefslogtreecommitdiff
path: root/test/detectLocalGit.js
diff options
context:
space:
mode:
authorNick Merwin <[email protected]>2019-11-20 17:05:48 -0800
committerGitHub <[email protected]>2019-11-20 17:05:48 -0800
commit336123fe05e7f80d79fc8522b4ff21a60fffe77c (patch)
tree97e5b9343471fc73ddf4ffb20cd71ca58367d6c6 /test/detectLocalGit.js
parenteba01a29c69f28ffd7f50556492a43b5ba2486d7 (diff)
downloadnode-coveralls-336123fe05e7f80d79fc8522b4ff21a60fffe77c.tar.xz
node-coveralls-336123fe05e7f80d79fc8522b4ff21a60fffe77c.zip
ES6
* remove unused variables * move `require`s at the top * check for prototype built-ins * run in strict mode * always check for error values in tests * make style consistent * mark Node.js 6 as the minimum supported version in package.json * Use the arrow return syntax * logger.js: use `Boolean` to make the intention clearer. * Use the rest params instead of arguments. * test/getOptions.js: beautify git data. * Update logger.js Remove `hasDebugEnvVariable` function; it's just a `process.env` check * Create .jshintrc
Diffstat (limited to 'test/detectLocalGit.js')
-rw-r--r--test/detectLocalGit.js90
1 files changed, 43 insertions, 47 deletions
diff --git a/test/detectLocalGit.js b/test/detectLocalGit.js
index bc3158c..5a6fc7d 100644
--- a/test/detectLocalGit.js
+++ b/test/detectLocalGit.js
@@ -1,71 +1,67 @@
-var should = require('should');
-var fs = require('fs');
-var path = require('path');
+'use strict';
-var detectLocalGit = require('../lib/detectLocalGit');
+const fs = require('fs');
+const path = require('path');
+const should = require('should');
-var ORIGINAL_CWD = process.cwd();
-var TEST_DIR = path.resolve(__dirname);
-var TEMP_GIT_DIR = path.join(TEST_DIR, '.git');
+const detectLocalGit = require('../lib/detectLocalGit');
-describe("detectLocalGit", function() {
+const ORIGINAL_CWD = process.cwd();
+const TEST_DIR = path.resolve(__dirname);
+const TEMP_GIT_DIR = path.join(TEST_DIR, '.git');
- before(function() {
- _makeTempGitDir();
- process.chdir(TEST_DIR);
- });
-
- after(function() {
- _cleanTempGitDir();
- process.chdir(ORIGINAL_CWD);
- });
+describe('detectLocalGit', () => {
+ before(() => {
+ _makeTempGitDir();
+ process.chdir(TEST_DIR);
+ });
- it('should get commit hash from packed-refs when refs/heads/master does not exist', function() {
- var results = detectLocalGit();
- should.exist(results);
- (results).should.deepEqual({
- git_commit: '0000000000000000ffffffffffffffffffffffff',
- git_branch: 'master'
- });
+ after(() => {
+ _cleanTempGitDir();
+ process.chdir(ORIGINAL_CWD);
+ });
+
+ it('should get commit hash from packed-refs when refs/heads/master does not exist', () => {
+ const results = detectLocalGit();
+ should.exist(results);
+ (results).should.deepEqual({
+ git_commit: '0000000000000000ffffffffffffffffffffffff',
+ git_branch: 'master'
});
-
+ });
});
function _makeTempGitDir() {
+ _cleanTempGitDir();
- _cleanTempGitDir();
-
- var dir = TEMP_GIT_DIR;
-
- fs.mkdirSync(dir);
+ const dir = TEMP_GIT_DIR;
- var HEAD = path.join(dir, 'HEAD');
- var packedRefs = path.join(dir, 'packed-refs');
+ fs.mkdirSync(dir);
- fs.writeFileSync(HEAD, 'ref: refs/heads/master');
- fs.writeFileSync(packedRefs, "" +
-"# pack-refs with: peeled fully-peeled\n" +
-"0000000000000000000000000000000000000000 refs/heads/other/ref\n" +
-"0000000000000000ffffffffffffffffffffffff refs/heads/master\n" +
-"ffffffffffffffffffffffffffffffffffffffff refs/remotes/origin/other\n");
+ const HEAD = path.join(dir, 'HEAD');
+ const packedRefs = path.join(dir, 'packed-refs');
+ fs.writeFileSync(HEAD, 'ref: refs/heads/master');
+ fs.writeFileSync(packedRefs, '' +
+'# pack-refs with: peeled fully-peeled\n' +
+'0000000000000000000000000000000000000000 refs/heads/other/ref\n' +
+'0000000000000000ffffffffffffffffffffffff refs/heads/master\n' +
+'ffffffffffffffffffffffffffffffffffffffff refs/remotes/origin/other\n');
}
function _cleanTempGitDir() {
- _deleteFolderRecursive(TEMP_GIT_DIR);
+ _deleteFolderRecursive(TEMP_GIT_DIR);
}
function _deleteFolderRecursive(dir) {
-
- if (!dir.includes(path.normalize('node-coveralls/test'))) {
- throw new Error('Tried to clean a temp git directory that did not match path: ' + path.normalize('node-coveralls/test'));
+ if (!dir.match('node-coveralls/test')) {
+ throw new Error('Tried to clean a temp git directory that did not match path: node-coveralls/test');
}
- if(fs.existsSync(dir)) {
-
- fs.readdirSync(dir).forEach(function(file,index){
- var curPath = path.join(dir, file);
- if(fs.lstatSync(curPath).isDirectory()) { // recurse
+ if (fs.existsSync(dir)) {
+ fs.readdirSync(dir).forEach(file => {
+ const curPath = path.join(dir, file);
+ if (fs.lstatSync(curPath).isDirectory()) { // recurse
_deleteFolderRecursive(curPath);
} else { // delete file
fs.unlinkSync(curPath);