]> git.ardis.lu - csvio/commitdiff
Fix temp files not being deleted
authorArdis Lu <ardisglu@gmail.com>
Sat, 8 Feb 2025 09:47:24 +0000 (01:47 -0800)
committerArdis Lu <ardisglu@gmail.com>
Sat, 8 Feb 2025 09:47:24 +0000 (01:47 -0800)
The test runner will run code inside a test suite block even if the tests inside are skipped, which means the temp file was created but the cleanup `after()` call is skipped. Putting the creation within `before()` makes the temp file creation skipped it the tests are skipped.

test/large.test.js

index e959939356e45f3c51736374eacbc29908233538..cb35b667ea5617f3dac2c1836c07ff7bd1b79805 100644 (file)
@@ -1,4 +1,4 @@
-import { suite, test, after } from 'node:test';
+import { suite, test, before, after } from 'node:test';
 import { ok, deepStrictEqual } from 'node:assert/strict';
 import { unlink, stat } from 'node:fs/promises';
 
@@ -6,7 +6,8 @@ import { createRandomCSV, createTempFile } from './utils.js';
 import { CSVReader, CSVTransformer, CSVWriter } from '../src/core.js';
 
 suite('large: 100000 row x 100 column CSV (~100 MB)', { concurrency: 1 }, async () => {
-  const temp = await createTempFile();
+  let temp;
+  before(async () => { temp = await createTempFile() });
   after(async () => await unlink(temp));
 
   test('CSVWriter writes file', async () => {
@@ -66,7 +67,8 @@ suite('large: 100000 row x 100 column CSV (~100 MB)', { concurrency: 1 }, async
 });
 
 suite('large: 100 row x 100000 column CSV (~100 MB)', { concurrency: 1 }, async () => {
-  const temp = await createTempFile();
+  let temp;
+  before(async () => { temp = await createTempFile() });
   after(async () => await unlink(temp));
 
   test('CSVWriter writes file', async () => {
This page took 0.046801 seconds and 4 git commands to generate.