]> git.ardis.lu - csvio/commitdiff
Add tests for `instanceof` behavior
authorArdis Lu <ardisglu@gmail.com>
Tue, 29 Jul 2025 06:35:40 +0000 (23:35 -0700)
committerArdis Lu <ardisglu@gmail.com>
Tue, 29 Jul 2025 06:35:40 +0000 (23:35 -0700)
In preparation for possible future refactoring for these classes to return a `Proxy` object (this pattern is required to simulate dynamic superclasses, e.g., `CSVReader` returning either `ReadableStream` OR `TransformStream` depending on constructor argument). If such refactoring takes place, these tests will check that `Proxy` was implemented correctly and maintain backwards compatibility.

test/core.test.js
test/normalization.test.js

index 4445bcf207741be7c0ce137f70e47fb44ab1ecc6..7cde8e557d637d8ee2eb4a2af2dbf705b1c6ec9d 100644 (file)
@@ -293,6 +293,12 @@ suite('CSVReader', { concurrency: true }, () => {
     const c = await s.getReader().read().then(({ value }) => value);
     deepStrictEqual(c, undefined);
   });
+  test('works with instanceof', { concurrency: true }, async () => {
+    const path = new URL('./data/simple.csv', import.meta.url);
+    const s = new CSVReader(path);
+    deepStrictEqual(s instanceof CSVReader, true);
+    await s.cancel();
+  });
 });
 
 suite('CSVTransformer', { concurrency: true }, () => {
@@ -547,6 +553,10 @@ suite('CSVTransformer', { concurrency: true }, () => {
       ]));
     deepStrictEqual(fn.mock.callCount(), 2);
   });
+  test('works with instanceof', { concurrency: true }, async () => {
+    const s = new CSVTransformer(r => r);
+    deepStrictEqual(s instanceof CSVTransformer, true);
+  });
 });
 
 suite('CSVWriter', { concurrency: true }, () => {
@@ -708,6 +718,13 @@ suite('CSVWriter', { concurrency: true }, () => {
     await rejects(writer.write('b'));
     await new CSVReader(temp).pipeTo(csvStreamEqualWritable([['a']]));
   });
+  test('works with instanceof', { concurrency: true }, async (t) => {
+    const temp = await createTempFile();
+    t.after(async () => await unlink(temp));
+    const s = new CSVWriter(temp);
+    deepStrictEqual(s instanceof CSVWriter, true);
+    await s.abort();
+  });
 });
 
 suite('CSVWriter status', { concurrency: true }, () => {
index 620b4cf8106c9701dd5a5658c1d8ed2a94fe2412..bef63dd48cc7ee614bbb3f75e0dd2d9244e20e53 100644 (file)
@@ -461,6 +461,10 @@ suite('CSVNormalizer', { concurrency: true }, () => {
         ['a', 'b']
       ]));
   });
+  test('works with instanceof', { concurrency: true }, async () => {
+    const s = new CSVNormalizer([]);
+    deepStrictEqual(s instanceof CSVNormalizer, true);
+  });
 });
 
 suite('CSVDenormalizer', { concurrency: true }, () => {
@@ -488,6 +492,10 @@ suite('CSVDenormalizer', { concurrency: true }, () => {
         ['a2', 'b2']
       ]));
   });
+  test('works with instanceof', { concurrency: true }, async () => {
+    const s = new CSVDenormalizer();
+    deepStrictEqual(s instanceof CSVDenormalizer, true);
+  });
 });
 
 suite('CSVNormalizer and CSVDenormalizer end-to-end', { concurrency: true }, () => {
This page took 0.042292 seconds and 4 git commands to generate.