Przeglądaj źródła

Added a test for a failure.

Eugene Lazutkin 3 lat temu
rodzic
commit
eb7ce79405
1 zmienionych plików z 16 dodań i 2 usunięć
  1. 16 2
      tests/test-jsonl-parser.mjs

+ 16 - 2
tests/test-jsonl-parser.mjs

@@ -49,7 +49,7 @@ const roundtrip = (t, resolve, len, quant) => {
 test.asPromise('jsonl parser: smoke test', (t, resolve) => roundtrip(t, resolve));
 
 test.asPromise('jsonl parser: roundtrip with 1 set of objects', (t, resolve) => {
-  roundtrip(t, resolve, 1)
+  roundtrip(t, resolve, 1);
 });
 
 test.asPromise('jsonl parser: roundtrip with 2 sets of objects', (t, resolve) => {
@@ -97,7 +97,7 @@ test.asPromise('jsonl parser: roundtrip with 12 sets of objects', (t, resolve) =
 });
 
 test.asPromise('jsonl parser: roundtrip with different window sizes', (t, resolve) => {
-  for (let i = 1; i <=12; ++i) {
+  for (let i = 1; i <= 12; ++i) {
     roundtrip(t, resolve, 10, i);
   }
 });
@@ -125,3 +125,17 @@ test.asPromise('jsonl parser: read file', (t, resolve) => {
       })
     );
 });
+
+test.asPromise('jsonl parser: bad json', (t, resolve) => {
+  const pipeline = readString(' not json ').pipe(parser());
+
+  pipeline.on('data', () => t.fail("We shouldn't be here."));
+  pipeline.on('error', e => {
+    t.ok(e);
+    resolve();
+  });
+  pipeline.on('end', value => {
+    t.fail("We shouldn't be here.");
+    resolve();
+  });
+});