From a2a3c87666defe787ae3b9e5c9fbe5ec5ddf62c5 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Sat, 8 Feb 2025 01:47:24 -0800 Subject: [PATCH] Fix temp files not being deleted 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 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/large.test.js b/test/large.test.js index e959939..cb35b66 100644 --- a/test/large.test.js +++ b/test/large.test.js @@ -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 () => { -- 2.47.3