From 4210e442a3739969ff32075a72a49c6d95730adf Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 3 Jan 2021 11:49:08 -0800 Subject: [PATCH] [Tests] add `npm run test:example` to test non-failing examples. - Note: does not work with `nyc` due to falafel usage. --- example/nested.js | 14 +++++++------- example/{not_enough.js => not_enough_fail.js} | 18 +++++++++--------- example/stream/test/{x.js => x_fail.js} | 0 example/stream/test/y.js | 2 +- example/timing.js | 4 ++-- example/{too_many.js => too_many_fail.js} | 0 package.json | 3 ++- 7 files changed, 21 insertions(+), 20 deletions(-) rename example/{not_enough.js => not_enough_fail.js} (64%) rename example/stream/test/{x.js => x_fail.js} (100%) rename example/{too_many.js => too_many_fail.js} (100%) diff --git a/example/nested.js b/example/nested.js index 3be43662..a465bd42 100644 --- a/example/nested.js +++ b/example/nested.js @@ -4,7 +4,7 @@ var falafel = require('falafel'); var test = require('../'); test('nested array test', function (t) { - t.plan(5); + t.plan(6); var src = '(' + function () { var xs = [ 1, 2, [ 3, 4 ] ]; @@ -28,19 +28,19 @@ test('nested array test', function (t) { }); var arrays = [ - [ 3, 4 ], - [ 1, 2, [ 3, 4 ] ], - [ 5, 6 ], - [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ], + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[1, 2, [3, 4]], [5, 6]], ]; - Function(['fn','g'], output)( + Function(['fn', 'g'], output)( function (xs) { t.same(arrays.shift(), xs); return xs; }, function (xs) { - t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]); + t.same(xs, [[1, 2, [3, 4]], [5, 6]]); } ); }); diff --git a/example/not_enough.js b/example/not_enough_fail.js similarity index 64% rename from example/not_enough.js rename to example/not_enough_fail.js index 15ee2412..ce7961f5 100644 --- a/example/not_enough.js +++ b/example/not_enough_fail.js @@ -7,9 +7,9 @@ test('array', function (t) { t.plan(8); var src = '(' + function () { - var xs = [ 1, 2, [ 3, 4 ] ]; - var ys = [ 5, 6 ]; - g([ xs, ys ]); + var xs = [1, 2, [3, 4]]; + var ys = [5, 6]; + g([xs, ys]); } + ')()'; var output = falafel(src, function (node) { @@ -19,19 +19,19 @@ test('array', function (t) { }); var arrays = [ - [ 3, 4 ], - [ 1, 2, [ 3, 4 ] ], - [ 5, 6 ], - [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ], + [3, 4], + [1, 2, [3, 4]], + [5, 6], + [[1, 2, [3, 4]], [5, 6]], ]; - Function(['fn','g'], output)( + Function(['fn', 'g'], output)( function (xs) { t.same(arrays.shift(), xs); return xs; }, function (xs) { - t.same(xs, [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]); + t.same(xs, [[1, 2, [3, 4]], [5, 6]]); } ); }); diff --git a/example/stream/test/x.js b/example/stream/test/x_fail.js similarity index 100% rename from example/stream/test/x.js rename to example/stream/test/x_fail.js diff --git a/example/stream/test/y.js b/example/stream/test/y.js index 998bd153..0a0928f2 100644 --- a/example/stream/test/y.js +++ b/example/stream/test/y.js @@ -3,7 +3,7 @@ var test = require('../../../'); test(function (t) { t.plan(2); - t.equal(1+1, 2); + t.equal(1 + 1, 2); t.ok(true); }); diff --git a/example/timing.js b/example/timing.js index f9d4db70..ba97963a 100644 --- a/example/timing.js +++ b/example/timing.js @@ -6,9 +6,9 @@ test('timing test', function (t) { t.plan(2); t.equal(typeof Date.now, 'function'); - var start = new Date; + var start = Date.now(); setTimeout(function () { - t.equal(new Date - start, 100); + t.ok(Date.now() - start > 100); }, 100); }); diff --git a/example/too_many.js b/example/too_many_fail.js similarity index 100% rename from example/too_many.js rename to example/too_many_fail.js diff --git a/package.json b/package.json index 8501d652..215c61c9 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,8 @@ "pretest": "npm run lint", "test": "npm run tests-only", "posttest": "aud --production", - "tests-only": "nyc tap test/*.js" + "tests-only": "nyc tap test/*.js", + "test:example": "find example -name '*.js' | grep -v fail | grep -v static | xargs tap" }, "testling": { "files": "test/browser/*.js",