Prechádzať zdrojové kódy

Switched tests to delay() helper.

Eugene Lazutkin 7 rokov pred
rodič
commit
f363c12de6
2 zmenil súbory, kde vykonal 8 pridanie a 36 odobranie
  1. 6 29
      tests/test_comp.js
  2. 2 7
      tests/test_simple.js

+ 6 - 29
tests/test_comp.js

@@ -3,7 +3,7 @@
 const unit = require('heya-unit');
 
 const Chain = require('../index');
-const {streamFromArray} = require('./helpers');
+const {streamFromArray, delay} = require('./helpers');
 
 const comp = require('../utils/comp');
 
@@ -69,15 +69,7 @@ unit.add(module, [
   function test_compAsync(t) {
     const async = t.startAsync('test_compAsync');
 
-    const chain = new Chain([
-        comp(
-          async x =>
-            await new Promise(resolve => {
-              setTimeout(() => resolve(x * x), 20);
-            }),
-          x => 2 * x + 1
-        )
-      ]),
+    const chain = new Chain([comp(delay(x => x * x), x => 2 * x + 1)]),
       output = [];
 
     streamFromArray([1, 2, 3]).pipe(chain);
@@ -115,13 +107,7 @@ unit.add(module, [
   function test_compMany(t) {
     const async = t.startAsync('test_compMany');
 
-    const chain = new Chain([
-        comp(
-          x => x * x,
-          x => many([x, x + 1, x + 2]),
-          x => 2 * x + 1
-        )
-      ]),
+    const chain = new Chain([comp(x => x * x, x => many([x, x + 1, x + 2]), x => 2 * x + 1)]),
       output = [];
 
     streamFromArray([1, 2, 3]).pipe(chain);
@@ -137,10 +123,7 @@ unit.add(module, [
 
     const chain = new Chain([
         comp(
-          async x =>
-            await new Promise(resolve => {
-              setTimeout(() => resolve(-x), 20);
-            }),
+          delay(x => -x),
           x => many([x, x * 10]),
           function*(x) {
             yield x;
@@ -164,10 +147,7 @@ unit.add(module, [
 
     const chain = new Chain([
         comp(
-          async x =>
-            await new Promise(resolve => {
-              setTimeout(() => resolve(-x), 20);
-            }),
+          delay(x => -x),
           x => many([x, x * 10]),
           function*(x) {
             yield x;
@@ -191,10 +171,7 @@ unit.add(module, [
 
     const chain = new Chain([
         comp.asFun(
-          async x =>
-            await new Promise(resolve => {
-              setTimeout(() => resolve(-x), 20);
-            }),
+          delay(x => -x),
           x => many([x, x * 10]),
           function*(x) {
             yield x;

+ 2 - 7
tests/test_simple.js

@@ -3,7 +3,7 @@
 const unit = require('heya-unit');
 
 const Chain = require('../index');
-const {streamFromArray, streamToArray} = require('./helpers');
+const {streamFromArray, streamToArray, delay} = require('./helpers');
 const {Transform} = require('stream');
 
 unit.add(module, [
@@ -48,12 +48,7 @@ unit.add(module, [
   function test_simpleAsync(t) {
     const async = t.startAsync('test_simpleAsync');
 
-    const chain = new Chain([
-        async x =>
-          await new Promise(resolve => {
-            setTimeout(() => resolve(x + 1), 20);
-          })
-      ]),
+    const chain = new Chain([delay(x => x + 1)]),
       output = [];
 
     streamFromArray([1, 2, 3]).pipe(chain);