Skip to content

Commit

Permalink
tests: convert tests to to tape harness
Browse files Browse the repository at this point in the history
  • Loading branch information
terinjokes committed Jul 10, 2018
1 parent 95f17a5 commit a751c5a
Show file tree
Hide file tree
Showing 9 changed files with 362 additions and 402 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,3 @@ matrix:
script: npm run lint
script:
- npm run test
after_success:
- npm run coverage
9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,18 @@
"vinyl-sourcemaps-apply": "^0.2.0"
},
"devDependencies": {
"coveralls": "^2.11.4",
"eslint": "^3.18.0",
"eslint-config-prettier": "^2.1.0",
"eslint-config-xo": "^0.18.1",
"eslint-plugin-no-use-extend-native": "^0.3.12",
"eslint-plugin-prettier": "^2.0.1",
"eslint-plugin-unicorn": "^2.1.0",
"intelli-espower-loader": "^1.0.1",
"mocha": "^3.0.1",
"nyc": "^10.3.2",
"power-assert": "^1.4.1",
"prettier": "^1.1.0",
"source-list-map": "^1.1.2",
"tape": "^4.0.0",
"tape": "^4.9.1",
"tape-catch": "^1.0.6",
"testdouble": "^2.1.2",
"vinyl": "^2.0.0"
},
Expand Down Expand Up @@ -71,8 +69,7 @@
],
"scripts": {
"lint": "eslint *.js lib test",
"test": "nyc --reporter=lcov --reporter=text mocha --require intelli-espower-loader",
"coverage": "cat ./coverage/lcov.info | coveralls"
"test": "tape --require intelli-espower-loader test/*.js"
},
"greenkeeper": {
"ignore": [
Expand Down
7 changes: 0 additions & 7 deletions test/_helper.js

This file was deleted.

81 changes: 40 additions & 41 deletions test/create-error.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,49 @@
'use strict';
var mocha = require('mocha');
var test = require('tape-catch');
var assert = require('assert');
var Vinyl = require('vinyl');
var createError = require('../lib/create-error');
var GulpUglifyError = require('../lib/gulp-uglify-error');

var describe = mocha.describe;
var it = mocha.it;
var beforeEach = mocha.beforeEach;

describe('createError', function() {
beforeEach(function() {
var testOkContentsInput =
'"use strict"; (function(console, first, second) { console.log(first + second) }(5, 10))';
this.testFile = new Vinyl({
cwd: '/home/terin/broken-promises/',
base: '/home/terin/broken-promises/test',
path: '/home/terin/broken-promises/test/test2.js',
contents: new Buffer(testOkContentsInput)
});
});
test('createError has error message', function(t) {
var e = createError(createTestFile(), 'error message text', null);

it('should have expected error message', function() {
var e = createError(this.testFile, 'error message text', null);

assert.ok(e instanceof Error, 'argument should be of type Error');
assert.ok(
e instanceof GulpUglifyError,
'argument should be of type GulpUglifyError'
);
assert.equal(e.plugin, 'gulp-uglify', 'error is from gulp-uglify');
assert.equal(e.message, 'error message text');
assert.ok(!e.cause, 'should not contain a cause');
});
assert.ok(e instanceof Error, 'argument should be of type Error');
assert.ok(
e instanceof GulpUglifyError,
'argument should be of type GulpUglifyError'
);
assert.equal(e.plugin, 'gulp-uglify', 'error is from gulp-uglify');
assert.equal(e.message, 'error message text');
assert.ok(!e.cause, 'should not contain a cause');

it('should wrap cause', function() {
var cause = new Error('boom!');
var e = createError(this.testFile, 'error message text', cause);

assert.ok(e instanceof Error, 'argument should be of type Error');
assert.ok(
e instanceof GulpUglifyError,
'argument should be of type GulpUglifyError'
);
assert.equal(e.plugin, 'gulp-uglify', 'error is from gulp-uglify');
assert.ok(e.message.match(/^error message text/));
assert.equal(e.cause, cause);
});
t.end();
});

test('createError wraps cause', function(t) {
var cause = new Error('boom!');
var e = createError(createTestFile(), 'error message text', cause);

assert.ok(e instanceof Error, 'argument should be of type Error');
assert.ok(
e instanceof GulpUglifyError,
'argument should be of type GulpUglifyError'
);
assert.equal(e.plugin, 'gulp-uglify', 'error is from gulp-uglify');
assert.ok(e.message.match(/^error message text/));
assert.equal(e.cause, cause);

t.end();
});

function createTestFile() {
var testOkContentsInput =
'"use strict"; (function(console, first, second) { console.log(first + second) }(5, 10))';

return new Vinyl({
cwd: '/home/terin/broken-promises/',
base: '/home/terin/broken-promises/test',
path: '/home/terin/broken-promises/test/test2.js',
contents: new Buffer(testOkContentsInput)
});
}
218 changes: 105 additions & 113 deletions test/err.js
Original file line number Diff line number Diff line change
@@ -1,133 +1,125 @@
'use strict';
var mocha = require('mocha');
var test = require('tape');
var assert = require('assert');
var Vinyl = require('vinyl');
var td = require('testdouble');
var GulpUglifyError = require('../lib/gulp-uglify-error');
var minify = require('../lib/minify');

var describe = mocha.describe;
var it = mocha.it;
test('errors should report files in error', function(t) {
var testFile = new Vinyl({
cwd: '/home/terin/broken-promises/',
base: '/home/terin/broken-promises/test',
path: '/home/terin/broken-promises/test/test1.js',
contents: new Buffer('function errorFunction(error)\n{')
});
var uglify = td.object(['minify']);
var logger = td.object(['warn']);
var expOptions = {
output: {}
};
var err = new Error();
err.line = 28889;

describe('errors', function() {
it('should report files in error', function() {
var testFile = new Vinyl({
cwd: '/home/terin/broken-promises/',
base: '/home/terin/broken-promises/test',
path: '/home/terin/broken-promises/test/test1.js',
contents: new Buffer('function errorFunction(error)\n{')
});
var uglify = td.object(['minify']);
var logger = td.object(['warn']);
var expOptions = {
output: {}
};
var err = new Error();
err.line = 28889;
td.when(
uglify.minify(
{
'test1.js': 'function errorFunction(error)\n{'
},
expOptions
)
).thenReturn({
error: err
});

td.when(
uglify.minify(
{
'test1.js': 'function errorFunction(error)\n{'
},
expOptions
)
).thenReturn({
error: err
});
var subject = minify(uglify, logger)({});

var subject = minify(uglify, logger)({});
assert.throws(
function() {
subject(testFile);
},
function(err) {
assert.ok(
err instanceof GulpUglifyError,
'argument should be of type GulpUglifyError'
);
assert.equal(err.plugin, 'gulp-uglify', 'error is from gulp-uglify');
assert.equal(
err.fileName,
testFile.path,
'error reports correct file name'
);
assert.equal(err.cause.line, 28889, 'error reports correct line number');
assert.ok(err.stack, 'error has a stack');
assert.ok(!err.showStack, 'error is configured to not print the stack');
assert.ok(err instanceof Error, 'argument should be of type Error');

assert.throws(
function() {
subject(testFile);
},
function(err) {
assert.ok(
err instanceof GulpUglifyError,
'argument should be of type GulpUglifyError'
);
assert.equal(err.plugin, 'gulp-uglify', 'error is from gulp-uglify');
assert.equal(
err.fileName,
testFile.path,
'error reports correct file name'
);
assert.equal(
err.cause.line,
28889,
'error reports correct line number'
);
assert.ok(err.stack, 'error has a stack');
assert.ok(!err.showStack, 'error is configured to not print the stack');
assert.ok(err instanceof Error, 'argument should be of type Error');
return true;
}
);

return true;
}
);
td.verify(logger.warn(), {times: 0, ignoreExtraArgs: true});
td.reset();
t.end();
});

td.verify(logger.warn(), {times: 0, ignoreExtraArgs: true});
test("errors shouldn't blow up", function(t) {
var testFile = new Vinyl({
cwd: '/home/terin/broken-promises/',
base: '/home/terin/broken-promises/test',
path: '/home/terin/broken-promises/test/test1.js',
contents: new Buffer('{}')
});
var uglify = td.object(['minify']);
var logger = td.object(['warn']);
var expOptions = {
output: {
exportAll: true
}
};
var err = new Error('`exportAll` is not a supported option');

it("shouldn't blow up when given output options", function() {
var testFile = new Vinyl({
cwd: '/home/terin/broken-promises/',
base: '/home/terin/broken-promises/test',
path: '/home/terin/broken-promises/test/test1.js',
contents: new Buffer('{}')
});
var uglify = td.object(['minify']);
var logger = td.object(['warn']);
var expOptions = {
output: {
exportAll: true
}
};
var err = new Error('`exportAll` is not a supported option');

td.when(
uglify.minify(
{
'test1.js': '{}'
},
expOptions
)
).thenReturn({
error: err
});
td.when(
uglify.minify(
{
'test1.js': '{}'
},
expOptions
)
).thenReturn({
error: err
});

var subject = minify(uglify, logger)({
output: {
exportAll: true
}
});
var subject = minify(uglify, logger)({
output: {
exportAll: true
}
});

assert.throws(
function() {
subject(testFile);
},
function(err) {
assert.ok(err instanceof Error, 'argument should be of type Error');
assert.ok(
err instanceof GulpUglifyError,
'argument should be of type GulpUglifyError'
);
assert.equal(
err.cause.message,
'`exportAll` is not a supported option'
);
assert.equal(err.plugin, 'gulp-uglify', 'error is from gulp-uglify');
assert.equal(
err.fileName,
testFile.path,
'error reports correct file name'
);
assert.ok(!err.showStack, 'error is configured to not print the stack');
assert.throws(
function() {
subject(testFile);
},
function(err) {
assert.ok(err instanceof Error, 'argument should be of type Error');
assert.ok(
err instanceof GulpUglifyError,
'argument should be of type GulpUglifyError'
);
assert.equal(err.cause.message, '`exportAll` is not a supported option');
assert.equal(err.plugin, 'gulp-uglify', 'error is from gulp-uglify');
assert.equal(
err.fileName,
testFile.path,
'error reports correct file name'
);
assert.ok(!err.showStack, 'error is configured to not print the stack');

return true;
}
);
return true;
}
);

td.verify(logger.warn(), {times: 0, ignoreExtraArgs: true});
});
td.verify(logger.warn(), {times: 0, ignoreExtraArgs: true});
td.reset();
t.end();
});
Loading

0 comments on commit a751c5a

Please sign in to comment.