Skip to content

Commit

Permalink
Use string.prototype.trim instead of relying on String#trim, for …
Browse files Browse the repository at this point in the history
…ES3.
  • Loading branch information
ljharb committed Oct 2, 2015
1 parent 1e22819 commit 77e1848
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 13 deletions.
3 changes: 2 additions & 1 deletion lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var path = require('path');
var inherits = require('inherits');
var EventEmitter = require('events').EventEmitter;
var has = require('has');
var trim = require('string.prototype.trim');

module.exports = Test;

Expand Down Expand Up @@ -101,7 +102,7 @@ Test.prototype.test = function (name, opts, cb) {
};

Test.prototype.comment = function (msg) {
this.emit('result', msg.trim().replace(/^#\s*/, ''));
this.emit('result', trim(msg).replace(/^#\s*/, ''));
};

Test.prototype.plan = function (n) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"inherits": "~2.0.1",
"object-inspect": "~1.0.0",
"resumer": "~0.0.0",
"string.prototype.trim": "^1.1.1",
"through": "~2.3.4"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion test/array.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var falafel = require('falafel');
var tape = require('../');
var tap = require('tap');
var trim = require('string.prototype.trim');

tap.test('array test', function (tt) {
tt.plan(1);
Expand All @@ -13,7 +14,7 @@ tap.test('array test', function (tt) {
tc.on('end', function () {
var rs = rows.map(function (r) {
if (r && typeof r === 'object') {
return { id : r.id, ok : r.ok, name : r.name.trim() };
return { id : r.id, ok : r.ok, name : trim(r.name) };
}
else return r;
});
Expand Down
3 changes: 2 additions & 1 deletion test/end-as-callback.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var tap = require("tap");
var tape = require("../");
var trim = require('string.prototype.trim');

tap.test("tape assert.end as callback", function (tt) {
var test = tape.createHarness({ exit: false })
Expand All @@ -10,7 +11,7 @@ tap.test("tape assert.end as callback", function (tt) {
tc.on("end", function () {
var rs = rows.map(function (r) {
return r && typeof r === "object" ?
{ id: r.id, ok: r.ok, name: r.name.trim() } :
{ id: r.id, ok: r.ok, name: trim(r.name) } :
r
})

Expand Down
9 changes: 5 additions & 4 deletions test/exit.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var tap = require('tap');
var spawn = require('child_process').spawn;
var trim = require('string.prototype.trim');

tap.test('exit ok', function (t) {
t.plan(2);
Expand All @@ -11,7 +12,7 @@ tap.test('exit ok', function (t) {
tc.on('end', function () {
var rs = rows.map(function (r) {
if (r && typeof r === 'object') {
return { id : r.id, ok : r.ok, name : r.name.trim() };
return { id : r.id, ok : r.ok, name : trim(r.name) };
}
else return r;
});
Expand Down Expand Up @@ -47,7 +48,7 @@ tap.test('exit fail', function (t) {
tc.on('end', function () {
var rs = rows.map(function (r) {
if (r && typeof r === 'object') {
return { id : r.id, ok : r.ok, name : r.name.trim() };
return { id : r.id, ok : r.ok, name : trim(r.name) };
}
else return r;
});
Expand Down Expand Up @@ -82,7 +83,7 @@ tap.test('too few exit', function (t) {
tc.on('end', function () {
var rs = rows.map(function (r) {
if (r && typeof r === 'object') {
return { id : r.id, ok : r.ok, name : r.name.trim() };
return { id : r.id, ok : r.ok, name : trim(r.name) };
}
else return r;
});
Expand Down Expand Up @@ -118,7 +119,7 @@ tap.test('more planned in a second test', function (t) {
tc.on('end', function () {
var rs = rows.map(function (r) {
if (r && typeof r === 'object') {
return { id : r.id, ok : r.ok, name : r.name.trim() };
return { id : r.id, ok : r.ok, name : trim(r.name) };
}
else return r;
});
Expand Down
3 changes: 2 additions & 1 deletion test/fail.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var falafel = require('falafel');
var tape = require('../');
var tap = require('tap');
var trim = require('string.prototype.trim');

tap.test('array test', function (tt) {
tt.plan(1);
Expand All @@ -13,7 +14,7 @@ tap.test('array test', function (tt) {
tc.on('end', function () {
var rs = rows.map(function (r) {
if (r && typeof r === 'object') {
return { id : r.id, ok : r.ok, name : r.name.trim() };
return { id : r.id, ok : r.ok, name : trim(r.name) };
}
else return r;
});
Expand Down
3 changes: 2 additions & 1 deletion test/nested-sync-noplan-noend.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var tape = require('../');
var tap = require('tap');
var trim = require('string.prototype.trim');

tap.test('nested sync test without plan or end', function (tt) {
tt.plan(1);
Expand All @@ -12,7 +13,7 @@ tap.test('nested sync test without plan or end', function (tt) {
tc.on('end', function () {
var rs = rows.map(function (r) {
if (r && typeof r === 'object') {
return { id : r.id, ok : r.ok, name : r.name.trim() };
return { id : r.id, ok : r.ok, name : trim(r.name) };
}
else return r;
});
Expand Down
3 changes: 2 additions & 1 deletion test/nested.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var falafel = require('falafel');
var tape = require('../');
var tap = require('tap');
var trim = require('string.prototype.trim');

tap.test('array test', function (tt) {
tt.plan(1);
Expand All @@ -13,7 +14,7 @@ tap.test('array test', function (tt) {
tc.on('end', function () {
var rs = rows.map(function (r) {
if (r && typeof r === 'object') {
return { id : r.id, ok : r.ok, name : r.name.trim() };
return { id : r.id, ok : r.ok, name : trim(r.name) };
}
else return r;
});
Expand Down
3 changes: 2 additions & 1 deletion test/only.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var tap = require('tap');
var tape = require('../');
var trim = require('string.prototype.trim');

tap.test('tape only test', function (tt) {
var test = tape.createHarness({ exit: false });
Expand All @@ -11,7 +12,7 @@ tap.test('tape only test', function (tt) {
tc.on('end', function () {
var rs = rows.map(function (r) {
if (r && typeof r === 'object') {
return { id: r.id, ok: r.ok, name: r.name.trim() };
return { id: r.id, ok: r.ok, name: trim(r.name) };
}
else {
return r;
Expand Down
3 changes: 2 additions & 1 deletion test/timeoutAfter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var tape = require('../');
var tap = require('tap');
var trim = require('string.prototype.trim');

tap.test('timeoutAfter test', function (tt) {
tt.plan(1);
Expand All @@ -12,7 +13,7 @@ tap.test('timeoutAfter test', function (tt) {
tc.on('end', function () {
var rs = rows.map(function (r) {
if (r && typeof r === 'object') {
return { id : r.id, ok : r.ok, name : r.name.trim() };
return { id : r.id, ok : r.ok, name : trim(r.name) };
}
else return r;
});
Expand Down
3 changes: 2 additions & 1 deletion test/too_many.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var falafel = require('falafel');
var tape = require('../');
var tap = require('tap');
var trim = require('string.prototype.trim');

tap.test('array test', function (tt) {
tt.plan(1);
Expand All @@ -13,7 +14,7 @@ tap.test('array test', function (tt) {
tc.on('end', function () {
var rs = rows.map(function (r) {
if (r && typeof r === 'object') {
return { id : r.id, ok : r.ok, name : r.name.trim() };
return { id : r.id, ok : r.ok, name : trim(r.name) };
}
else return r;
});
Expand Down

0 comments on commit 77e1848

Please sign in to comment.