]> git.ardis.lu - csvio/commitdiff
Add tests for `cancel`, `close`, and `abort`
authorArdis Lu <ardisglu@gmail.com>
Tue, 29 Apr 2025 04:50:32 +0000 (21:50 -0700)
committerArdis Lu <ardisglu@gmail.com>
Tue, 29 Apr 2025 04:50:32 +0000 (21:50 -0700)
test/core.test.js

index 02e92259a7e82b0e3771a6eec1313fed53356f6c..94f5e8fa55857fa77e776b51761619531066d35e 100644 (file)
@@ -268,6 +268,13 @@ suite('CSVReader', { concurrency: true }, () => {
       }
     });
   }
+  test('can cancel', { concurrency: true }, async () => {
+    const path = new URL('./data/simple.csv', import.meta.url);
+    const s = new CSVReader(path);
+    await s.cancel();
+    const c = await s.getReader().read().then(({ value }) => value);
+    deepStrictEqual(c, undefined);
+  });
 });
 
 suite('CSVTransformer', { concurrency: true }, () => {
@@ -616,6 +623,28 @@ suite('CSVWriter', { concurrency: true }, () => {
         ['1', '1'],
       ]));
   });
+  test('can close', { concurrency: true }, async (t) => {
+    const temp = await createTempFile();
+    t.after(async () => await unlink(temp));
+    const stream = new CSVWriter(temp);
+    const writer = stream.getWriter();
+    await writer.write('a');
+    writer.releaseLock();
+    await stream.close();
+    await rejects(writer.write('b'));
+    await new CSVReader(temp).pipeTo(csvStreamEqualWritable([['a']]));
+  });
+  test('can abort', { concurrency: true }, async (t) => {
+    const temp = await createTempFile();
+    t.after(async () => await unlink(temp));
+    const stream = new CSVWriter(temp);
+    const writer = stream.getWriter();
+    await writer.write('a');
+    writer.releaseLock();
+    await stream.abort();
+    await rejects(writer.write('b'));
+    await new CSVReader(temp).pipeTo(csvStreamEqualWritable([['a']]));
+  });
 });
 
 suite('CSVWriter status', { concurrency: true }, () => {
This page took 0.039315 seconds and 4 git commands to generate.