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

test: refactor tests for mocha #141

Merged
merged 2 commits into from
Nov 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ node_js:
- "4"
- "0.12"
- "0.10"
- "0.8"
sudo: false
cache:
directories:
Expand Down
278 changes: 278 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@
"url": "http://github.com/raszi/node-tmp/issues"
},
"engines": {
"node": ">=0.8.0"
"node": ">=0.10.0"
},
"dependencies": {
"os-tmpdir": "~1.0.2"
},
"devDependencies": {
"vows": "~0.7.0"
"mocha": "~3.4.2"
},
"main": "lib/tmp.js",
"files": [
"lib/"
],
"scripts": {
"test": "vows test/*-test.js",
"test": "mocha test/*-test.js",
"doc": "jsdoc -c .jsdoc.json"
}
}
68 changes: 68 additions & 0 deletions test/assertions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* eslint-disable no-octal */

var
assert = require('assert'),
fs = require('fs'),
path = require('path'),
existsSync = fs.existsSync || path.existsSync;


module.exports.assertName = function assertName(name, expected) {
assert.ok(typeof name == 'string');
assert.ok(name.length > 0, 'an empty string is not a valid name');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be put in the else branch of the following if condition, since that will be a stricter match and it would not add any value in the true case.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant this:

if (expected) {
  assert.equal(path.basename(name), expected, 'should be the expected name');
} else {
  assert.ok(name.length > 0, 'an empty string is not a valid name');
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

if (expected) {
assert.equal(path.basename(name), expected, 'should be the expected name');
}
};


module.exports.assertMode = function assertMode(name, mode) {
var stat = fs.statSync(name);

// mode values do not work properly on Windows. Ignore “group” and
// “other” bits then. Ignore execute bit on that platform because it
// doesn’t exist—even for directories.
if (process.platform == 'win32') {
assert.equal(stat.mode & 000600, mode & 000600);
} else {
assert.equal(stat.mode & 000777, mode);
}
};


module.exports.assertDir = function assertDir(name, dir) {
assert.equal(name.slice(0, dir.length), dir, 'should have the expected dir as the leading path');
};


module.exports.assertPrefix = function assertPrefix(name, prefix) {
assert.equal(path.basename(name).slice(0, prefix.length), prefix, 'should have the provided prefix');
};


module.exports.assertPostfix = function assertPostfix(name, postfix) {
assert.equal(name.slice(name.length - postfix.length, name.length), postfix, 'should have the provided postfix');
};


module.exports.assertProperResult = function assertProperResult(result, withfd) {
assert.ok(result);
assert.ok(result.name, 'should have a name');
if (withfd) assert.ok(result.fd, 'should have an fd');
else assert.strictEqual(result.fd, undefined, 'should not have a file descriptor (fd)');
assert.ok(typeof result.removeCallback == 'function', 'should have a removeCallback');
};


module.exports.assertExists = function assertExists(name, isfile) {
assert.ok(existsSync(name), name + ' should exist');
var stat = fs.statSync(name);
if (isfile) assert.ok(stat.isFile(), name + ' should be a file');
else assert.ok(stat.isDirectory(), name + ' should be a directory');
};


module.exports.assertDoesNotExist = function assertDoesNotExist(name) {
assert.ok(!existsSync(name), name + ' should not exist');
};

Loading