-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: convert tests to to tape harness
- Loading branch information
1 parent
95f17a5
commit a751c5a
Showing
9 changed files
with
362 additions
and
402 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,5 +13,3 @@ matrix: | |
script: npm run lint | ||
script: | ||
- npm run test | ||
after_success: | ||
- npm run coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |
Oops, something went wrong.