Skip to content

Commit

Permalink
refactor tests according to review on #141
Browse files Browse the repository at this point in the history
  • Loading branch information
silkentrance committed Nov 28, 2017
1 parent 26146ef commit 7b3c2be
Show file tree
Hide file tree
Showing 25 changed files with 54 additions and 52 deletions.
3 changes: 2 additions & 1 deletion test/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ var

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');
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');
}
};

Expand Down
2 changes: 1 addition & 1 deletion test/child-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var
module.exports = function spawnChildProcess(configFile, cb) {
var
node_path = process.argv[0],
command_args = [ path.join(__dirname, 'spawn.js') ].concat(configFile),
command_args = [path.join(__dirname, 'spawn.js')].concat(configFile),
stdoutBufs = [],
stderrBufs = [],
child,
Expand Down
6 changes: 4 additions & 2 deletions test/dir-sync-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,24 @@ describe('tmp', function () {
});

describe('with invalid tries', function () {

it('should result in an error on negative tries', function () {
try {
tmp.dirSync({tries: -1});
tmp.dirSync({ tries: -1 });
assert.fail('should have failed');
} catch (err) {
assert.ok(err instanceof Error);
}
});
it('should result in an error on non numeric tries', function () {
try {
tmp.dirSync({tries: 'nan'});
tmp.dirSync({ tries: 'nan' });
assert.fail('should have failed');
} catch (err) {
assert.ok(err instanceof Error);
}
});

});
});

Expand Down
6 changes: 3 additions & 3 deletions test/dir-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ describe('tmp', function () {
tmp.dir(this.opts, function (err, name, removeCallback) {
if (err) done(err);
else {
that.topic = {name: name, removeCallback: removeCallback};
that.topic = { name: name, removeCallback: removeCallback };
done();
}
});
});

describe('with invalid tries', function () {
it('should result in an error on negative tries', function (done) {
tmp.dir({tries: -1}, function (err) {
tmp.dir({ tries: -1 }, function (err) {
assert.ok(err instanceof Error, 'should have failed');
done();
});
});
it('should result in an error on non numeric tries', function (done) {
tmp.dir({tries: 'nan'}, function (err) {
tmp.dir({ tries: 'nan' }, function (err) {
assert.ok(err instanceof Error, 'should have failed');
done();
});
Expand Down
6 changes: 3 additions & 3 deletions test/file-sync-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ describe('tmp', function () {
describe('when running inband standard tests', function () {

inbandStandardTests(true, function before() {
this.topic = tmp.fileSync(this.opts);
this.topic = tmp.fileSync(this.opts);
});

describe('with invalid tries', function () {
it('should result in an error on negative tries', function () {
try {
tmp.fileSync({tries: -1});
tmp.fileSync({ tries: -1 });
assert.fail('should have failed');
} catch (err) {
assert.ok(err instanceof Error);
}
});
it('should result in an error on non numeric tries', function () {
try {
tmp.fileSync({tries: 'nan'});
tmp.fileSync({ tries: 'nan' });
assert.fail('should have failed');
} catch (err) {
assert.ok(err instanceof Error);
Expand Down
6 changes: 3 additions & 3 deletions test/file-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ describe('tmp', function () {
tmp.file(this.opts, function (err, name, fd, removeCallback) {
if (err) done(err);
else {
that.topic = {name: name, fd: fd, removeCallback: removeCallback};
that.topic = { name: name, fd: fd, removeCallback: removeCallback };
done();
}
});
});

describe('with invalid tries', function () {
it('should result in an error on negative tries', function (done) {
tmp.file({tries: -1}, function (err) {
tmp.file({ tries: -1 }, function (err) {
assert.ok(err instanceof Error, 'should have failed');
done();
});
});
it('should result in an error on non numeric tries', function (done) {
tmp.file({tries: 'nan'}, function (err) {
tmp.file({ tries: 'nan' }, function (err) {
assert.ok(err instanceof Error, 'should have failed');
done();
});
Expand Down
22 changes: 11 additions & 11 deletions test/inband-standard.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ var

module.exports = function inbandStandard(isFile, beforeHook) {
var testMode = isFile ? 0600 : 0700;
describe('without any parameters', inbandStandardTests({mode: testMode, prefix: 'tmp-'}, null, isFile, beforeHook));
describe('with prefix', inbandStandardTests({mode: testMode}, {prefix: 'something'}, isFile, beforeHook));
describe('with postfix', inbandStandardTests({mode: testMode}, {postfix: '.txt'}, isFile, beforeHook));
describe('with template and no leading path', inbandStandardTests({mode: testMode, prefix: 'clike-', postfix: '-postfix'}, {template: 'clike-XXXXXX-postfix'}, isFile, beforeHook));
describe('with template and leading path', inbandStandardTests({mode: testMode, prefix: 'clike-', postfix: '-postfix'}, {template: path.join(tmp.tmpdir, 'clike-XXXXXX-postfix')}, isFile, beforeHook));
describe('with name', inbandStandardTests({mode: testMode}, {name: 'using-name'}, isFile, beforeHook));
describe('with mode', inbandStandardTests(null, {mode: 0755}, isFile, beforeHook));
describe('with multiple options', inbandStandardTests(null, {prefix: 'foo', postfix: 'bar', mode: 0750}, isFile, beforeHook));
describe('without any parameters', inbandStandardTests({ mode: testMode, prefix: 'tmp-' }, null, isFile, beforeHook));
describe('with prefix', inbandStandardTests({ mode: testMode }, { prefix: 'something' }, isFile, beforeHook));
describe('with postfix', inbandStandardTests({ mode: testMode }, { postfix: '.txt' }, isFile, beforeHook));
describe('with template and no leading path', inbandStandardTests({ mode: testMode, prefix: 'clike-', postfix: '-postfix' }, { template: 'clike-XXXXXX-postfix' }, isFile, beforeHook));
describe('with template and leading path', inbandStandardTests({ mode: testMode, prefix: 'clike-', postfix: '-postfix' }, { template: path.join(tmp.tmpdir, 'clike-XXXXXX-postfix')}, isFile, beforeHook));
describe('with name', inbandStandardTests({ mode: testMode }, { name: 'using-name' }, isFile, beforeHook));
describe('with mode', inbandStandardTests(null, { mode: 0755 }, isFile, beforeHook));
describe('with multiple options', inbandStandardTests(null, { prefix: 'foo', postfix: 'bar', mode: 0750 }, isFile, beforeHook));
if (isFile) {
describe('with discardDescriptor', inbandStandardTests(null, {mode: testMode, discardDescriptor: true}, isFile, beforeHook));
describe('with detachDescriptor', inbandStandardTests(null, {mode: testMode, detachDescriptor: true}, isFile, beforeHook));
describe('with discardDescriptor', inbandStandardTests(null, { mode: testMode, discardDescriptor: true }, isFile, beforeHook));
describe('with detachDescriptor', inbandStandardTests(null, { mode: testMode, detachDescriptor: true }, isFile, beforeHook));
}
};

Expand All @@ -33,7 +33,7 @@ function inbandStandardTests(testOpts, opts, isFile, beforeHook) {
testOpts = testOpts || {};

// topic reference will be created by the beforeHook
topic = {topic: null, opts: opts};
topic = { topic: null, opts: opts };

// bind everything to topic so we avoid global
before(beforeHook.bind(topic));
Expand Down
14 changes: 7 additions & 7 deletions test/name-inband-standard.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ var


module.exports = function inbandStandard(beforeHook) {
describe('without any parameters', inbandStandardTests({prefix: 'tmp-'}, null, beforeHook));
describe('with prefix', inbandStandardTests(null, {prefix: 'something'}, beforeHook));
describe('with postfix', inbandStandardTests(null, {postfix: '.txt'}, beforeHook));
describe('with template and no leading path', inbandStandardTests({prefix: 'clike-', postfix: '-postfix'}, {template: 'clike-XXXXXX-postfix'}, beforeHook));
describe('with template and leading path', inbandStandardTests({prefix: 'clike-', postfix: '-postfix'}, {template: path.join(tmp.tmpdir, 'clike-XXXXXX-postfix')}, beforeHook));
describe('with multiple options', inbandStandardTests(null, {prefix: 'foo', postfix: 'bar', tries: 5}, beforeHook));
describe('without any parameters', inbandStandardTests({ prefix: 'tmp-' }, null, beforeHook));
describe('with prefix', inbandStandardTests(null, { prefix: 'something' }, beforeHook));
describe('with postfix', inbandStandardTests(null, { postfix: '.txt' }, beforeHook));
describe('with template and no leading path', inbandStandardTests({ prefix: 'clike-', postfix: '-postfix' }, { template: 'clike-XXXXXX-postfix' }, beforeHook));
describe('with template and leading path', inbandStandardTests({ prefix: 'clike-', postfix: '-postfix' }, { template: path.join(tmp.tmpdir, 'clike-XXXXXX-postfix')}, beforeHook));
describe('with multiple options', inbandStandardTests(null, { prefix: 'foo', postfix: 'bar', tries: 5 }, beforeHook));
};


function inbandStandardTests(testOpts, opts, beforeHook) {
return function () {
opts = opts || {};
testOpts = testOpts || {};
topic = {topic: null, opts: opts};
topic = { topic: null, opts: opts };

// bind everything to topic so we avoid global
before(beforeHook.bind(topic));
Expand Down
4 changes: 2 additions & 2 deletions test/name-sync-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ describe('tmp', function () {
describe('with invalid tries', function () {
it('should result in an error on negative tries', function () {
try {
tmp.tmpNameSync({tries: -1});
tmp.tmpNameSync({ tries: -1 });
assert.fail('should have failed');
} catch (err) {
assert.ok(err instanceof Error);
}
});
it('should result in an error on non numeric tries', function () {
try {
tmp.tmpNameSync({tries: 'nan'});
tmp.tmpNameSync({ tries: 'nan' });
assert.fail('should have failed');
} catch (err) {
assert.ok(err instanceof Error);
Expand Down
4 changes: 2 additions & 2 deletions test/name-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ describe('tmp', function () {

describe('with invalid tries', function () {
it('should result in an error on negative tries', function (done) {
tmp.tmpName({tries: -1}, function (err) {
tmp.tmpName({ tries: -1 }, function (err) {
assert.ok(err instanceof Error, 'should have failed');
done();
});
});
it('should result in an error on non numeric tries', function (done) {
tmp.tmpName({tries: 'nan'}, function (err) {
tmp.tmpName({ tries: 'nan' }, function (err) {
assert.ok(err instanceof Error, 'should have failed');
done();
});
Expand Down
2 changes: 1 addition & 1 deletion test/outband/issue62-sync.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"tc": "issue62",
"async": false,
"file": false,
"options": {"unsafeCleanup":true},
"options": { "unsafeCleanup":true },
"graceful": false
}
2 changes: 1 addition & 1 deletion test/outband/issue62.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"tc": "issue62",
"async": true,
"file": false,
"options": {"unsafeCleanup":true},
"options": { "unsafeCleanup":true },
"graceful": false
}
2 changes: 1 addition & 1 deletion test/outband/keep-dir-sync.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"tc": "keep",
"async": false,
"file": false,
"options": {"keep":true},
"options": { "keep":true },
"graceful": false
}
2 changes: 1 addition & 1 deletion test/outband/keep-dir.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"tc": "keep",
"async": true,
"file": false,
"options": {"keep":true},
"options": { "keep":true },
"graceful": false
}
2 changes: 1 addition & 1 deletion test/outband/keep-file-sync.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"tc": "keep",
"async": false,
"file": true,
"options": {"keep":true},
"options": { "keep":true },
"graceful": false
}
2 changes: 1 addition & 1 deletion test/outband/keep-file.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"tc": "keep",
"async": true,
"file": true,
"options": {"keep":true},
"options": { "keep":true },
"graceful": false
}
2 changes: 1 addition & 1 deletion test/outband/non-unsafe-sync.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"tc": "unsafe",
"async": false,
"file": false,
"options": {"unsafeCleanup":false},
"options": { "unsafeCleanup":false },
"graceful": false
}
2 changes: 1 addition & 1 deletion test/outband/non-unsafe.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"tc": "unsafe",
"async": true,
"file": false,
"options": {"unsafeCleanup":false},
"options": { "unsafeCleanup":false },
"graceful": false
}
2 changes: 1 addition & 1 deletion test/outband/unlink-dir-sync.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"tc": "keep",
"async": false,
"file": false,
"options": {"keep":false},
"options": { "keep":false },
"graceful": false
}
2 changes: 1 addition & 1 deletion test/outband/unlink-dir.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"tc": "keep",
"async": true,
"file": false,
"options": {"keep":false},
"options": { "keep":false },
"graceful": false
}
2 changes: 1 addition & 1 deletion test/outband/unlink-file-sync.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"tc": "keep",
"async": false,
"file": true,
"options": {"keep":false},
"options": { "keep":false },
"graceful": false
}
2 changes: 1 addition & 1 deletion test/outband/unlink-file.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"tc": "keep",
"async": true,
"file": true,
"options": {"keep":false},
"options": { "keep":false },
"graceful": false
}
2 changes: 1 addition & 1 deletion test/outband/unsafe-sync.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"tc": "unsafe",
"async": false,
"file": false,
"options": {"unsafeCleanup":true},
"options": { "unsafeCleanup":true },
"graceful": false
}
2 changes: 1 addition & 1 deletion test/outband/unsafe.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"tc": "unsafe",
"async": true,
"file": false,
"options": {"unsafeCleanup":true},
"options": { "unsafeCleanup":true },
"graceful": false
}
5 changes: 2 additions & 3 deletions test/spawn.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ function _writeSync(stream, str, cb) {
}

stream.once('drain', function _flushed() {
console.log('draining');
cb(null);
});
}
Expand Down Expand Up @@ -59,8 +58,8 @@ if (config.async)
if (err) spawn.err(err);
else {
var result = null;
if (config.file) result = {name: name, fd: fdOrCallback, removeCallback: cb};
else result = {name: name, removeCallback: fdOrCallback};
if (config.file) result = { name: name, fd: fdOrCallback, removeCallback: cb };
else result = { name: name, removeCallback: fdOrCallback };
fn.apply(spawn, [result, tmp]);
}
});
Expand Down

0 comments on commit 7b3c2be

Please sign in to comment.