From 29e44ceeaa4f95b9fcbff4b4fd3143838c16b980 Mon Sep 17 00:00:00 2001 From: Sebastian Riedel Date: Sat, 23 Dec 2023 16:55:50 +0100 Subject: [PATCH] Add tests for `using` keyword support --- test/path.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 test/path.ts diff --git a/test/path.ts b/test/path.ts new file mode 100644 index 0000000..829ab4a --- /dev/null +++ b/test/path.ts @@ -0,0 +1,32 @@ +import Path from '../lib/path.js'; +import t from 'tap'; + +t.test('Path', async t => { + t.test('using keyword for temporary files', async t => { + let check = Path.currentFile(); + + t.test('dispose', t => { + { + using dir = Path.tempDirSync(); + check = new Path(dir.toString()); + const file = dir.child('foo.txt'); + t.equal(file.writeFileSync('works').readFileSync('utf-8'), 'works'); + t.same(check.existsSync(), true); + } + t.same(check.existsSync(), false); + t.end(); + }); + + await t.test('asyncDispose', async t => { + let check = Path.currentFile(); + { + await using dir = await Path.tempDir(); + check = new Path(dir.toString()); + const file = dir.child('foo.txt'); + t.equal(file.writeFileSync('works too').readFileSync('utf-8'), 'works too'); + t.same(await check.exists(), true); + } + t.same(await check.exists(), false); + }); + }); +});