From 4e0eaf3cf75fb6ea5f459ad767a6629891f33114 Mon Sep 17 00:00:00 2001 From: Mert Can Altin Date: Sun, 18 Feb 2024 18:46:43 +0300 Subject: [PATCH 01/12] test: test surrogate pair filenames on windows --- ...ile-ops-with-surrogate-pairs-on-windows.js | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 test/common/file-ops-with-surrogate-pairs-on-windows.js diff --git a/test/common/file-ops-with-surrogate-pairs-on-windows.js b/test/common/file-ops-with-surrogate-pairs-on-windows.js new file mode 100644 index 00000000000000..31b596147c893c --- /dev/null +++ b/test/common/file-ops-with-surrogate-pairs-on-windows.js @@ -0,0 +1,49 @@ +'use strict'; + +const fs = require('fs'); +const { describe, it } = require('node:test'); +const assert = require('assert').strict; +const os = require('os'); +const path = require('path'); + +describe('File operations with filenames containing surrogate pairs on Windows', () => { + it('should write, read, and delete a file with surrogate pairs in the filename', () => { + // Create a temporary directory + const tempdir = fs.mkdtempSync(path.join(os.tmpdir(), 'emoji-fruit-🍇 🍈 🍉 🍊 🍋')); + assert.strictEqual(fs.existsSync(tempdir), true); + + const filename = '🚀🔥🛸.txt'; + const content = 'Test content'; + + // Write content to a file + fs.writeFileSync(path.join(tempdir, filename), content); + + // Read content from the file + const readContent = fs.readFileSync(path.join(tempdir, filename), 'utf8'); + + // Check if the content matches + assert.strictEqual(readContent, content); + + // Get directory contents + const dirs = fs.readdirSync(tempdir); + assert.strictEqual(dirs.length > 0, true); + + // Check if the file is in the directory contents + let match = false; + for (let i = 0; i < dirs.length; i++) { + if (dirs[i].endsWith(filename)) { + match = true; + break; + } + } + assert.strictEqual(match, true); + + // Delete the file + fs.unlinkSync(path.join(tempdir, filename)); + assert.strictEqual(fs.existsSync(path.join(tempdir, filename)), false); + + // Remove the temporary directory + fs.rmdirSync(tempdir); + assert.strictEqual(fs.existsSync(tempdir), false); + }); +}); From 9c2b48fc62c3cfaee4936ae017ad217344ef4aff Mon Sep 17 00:00:00 2001 From: Mert Can Altin Date: Sun, 18 Feb 2024 21:03:50 +0300 Subject: [PATCH 02/12] lint --- test/common/file-ops-with-surrogate-pairs-on-windows.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/common/file-ops-with-surrogate-pairs-on-windows.js b/test/common/file-ops-with-surrogate-pairs-on-windows.js index 31b596147c893c..2b5d85ad1dcc8d 100644 --- a/test/common/file-ops-with-surrogate-pairs-on-windows.js +++ b/test/common/file-ops-with-surrogate-pairs-on-windows.js @@ -1,10 +1,10 @@ 'use strict'; const fs = require('fs'); -const { describe, it } = require('node:test'); -const assert = require('assert').strict; const os = require('os'); const path = require('path'); +const assert = require('assert').strict; +const { describe, it } = require('node:test'); describe('File operations with filenames containing surrogate pairs on Windows', () => { it('should write, read, and delete a file with surrogate pairs in the filename', () => { From 6c7c777868bbfc0ba67df531259895bcd5a0ab62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mert=20Can=20Alt=C4=B1n?= Date: Mon, 19 Feb 2024 09:14:11 +0300 Subject: [PATCH 03/12] Update test/common/file-ops-with-surrogate-pairs-on-windows.js Co-authored-by: Yagiz Nizipli --- test/common/file-ops-with-surrogate-pairs-on-windows.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/common/file-ops-with-surrogate-pairs-on-windows.js b/test/common/file-ops-with-surrogate-pairs-on-windows.js index 2b5d85ad1dcc8d..67634fe0cd3ded 100644 --- a/test/common/file-ops-with-surrogate-pairs-on-windows.js +++ b/test/common/file-ops-with-surrogate-pairs-on-windows.js @@ -1,6 +1,6 @@ 'use strict'; -const fs = require('fs'); +const fs = require('node:fs'); const os = require('os'); const path = require('path'); const assert = require('assert').strict; From cdacdd2db00fb812d635caeb3168364e9dfd87d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mert=20Can=20Alt=C4=B1n?= Date: Mon, 19 Feb 2024 09:14:16 +0300 Subject: [PATCH 04/12] Update test/common/file-ops-with-surrogate-pairs-on-windows.js Co-authored-by: Yagiz Nizipli --- test/common/file-ops-with-surrogate-pairs-on-windows.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/common/file-ops-with-surrogate-pairs-on-windows.js b/test/common/file-ops-with-surrogate-pairs-on-windows.js index 67634fe0cd3ded..e950dc092ba39f 100644 --- a/test/common/file-ops-with-surrogate-pairs-on-windows.js +++ b/test/common/file-ops-with-surrogate-pairs-on-windows.js @@ -6,7 +6,7 @@ const path = require('path'); const assert = require('assert').strict; const { describe, it } = require('node:test'); -describe('File operations with filenames containing surrogate pairs on Windows', () => { +describe('File operations with filenames containing surrogate pairs', () => { it('should write, read, and delete a file with surrogate pairs in the filename', () => { // Create a temporary directory const tempdir = fs.mkdtempSync(path.join(os.tmpdir(), 'emoji-fruit-🍇 🍈 🍉 🍊 🍋')); From 130b9edb95f6542b8083e25b17c3305efb692dc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mert=20Can=20Alt=C4=B1n?= Date: Mon, 19 Feb 2024 09:14:36 +0300 Subject: [PATCH 05/12] Update test/common/file-ops-with-surrogate-pairs-on-windows.js Co-authored-by: Yagiz Nizipli --- test/common/file-ops-with-surrogate-pairs-on-windows.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/common/file-ops-with-surrogate-pairs-on-windows.js b/test/common/file-ops-with-surrogate-pairs-on-windows.js index e950dc092ba39f..776d27f3a2ae92 100644 --- a/test/common/file-ops-with-surrogate-pairs-on-windows.js +++ b/test/common/file-ops-with-surrogate-pairs-on-windows.js @@ -3,7 +3,7 @@ const fs = require('node:fs'); const os = require('os'); const path = require('path'); -const assert = require('assert').strict; +const assert = require('assert/strict'); const { describe, it } = require('node:test'); describe('File operations with filenames containing surrogate pairs', () => { From 7653f16051c1cc9fa13ba2b171d5d7090292cd06 Mon Sep 17 00:00:00 2001 From: Mert Can Altin Date: Mon, 19 Feb 2024 09:24:11 +0300 Subject: [PATCH 06/12] fix: test rename & repair --- ...ws.js => file-operations-with-surrogate-pairs.js} | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) rename test/common/{file-ops-with-surrogate-pairs-on-windows.js => file-operations-with-surrogate-pairs.js} (78%) diff --git a/test/common/file-ops-with-surrogate-pairs-on-windows.js b/test/common/file-operations-with-surrogate-pairs.js similarity index 78% rename from test/common/file-ops-with-surrogate-pairs-on-windows.js rename to test/common/file-operations-with-surrogate-pairs.js index 776d27f3a2ae92..b976f56634de43 100644 --- a/test/common/file-ops-with-surrogate-pairs-on-windows.js +++ b/test/common/file-operations-with-surrogate-pairs.js @@ -1,17 +1,15 @@ 'use strict'; const fs = require('node:fs'); -const os = require('os'); const path = require('path'); const assert = require('assert/strict'); const { describe, it } = require('node:test'); describe('File operations with filenames containing surrogate pairs', () => { it('should write, read, and delete a file with surrogate pairs in the filename', () => { - // Create a temporary directory - const tempdir = fs.mkdtempSync(path.join(os.tmpdir(), 'emoji-fruit-🍇 🍈 🍉 🍊 🍋')); - assert.strictEqual(fs.existsSync(tempdir), true); - + // Use a common temporary directory + const tempdir = '/tmp/emoji-fruit'; + const filename = '🚀🔥🛸.txt'; const content = 'Test content'; @@ -41,9 +39,5 @@ describe('File operations with filenames containing surrogate pairs', () => { // Delete the file fs.unlinkSync(path.join(tempdir, filename)); assert.strictEqual(fs.existsSync(path.join(tempdir, filename)), false); - - // Remove the temporary directory - fs.rmdirSync(tempdir); - assert.strictEqual(fs.existsSync(tempdir), false); }); }); From b097320ccc771ac6de54db1e2e021a6f38ad8054 Mon Sep 17 00:00:00 2001 From: Mert Can Altin Date: Mon, 19 Feb 2024 09:29:51 +0300 Subject: [PATCH 07/12] fix: un used os --- test/common/file-operations-with-surrogate-pairs.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/common/file-operations-with-surrogate-pairs.js b/test/common/file-operations-with-surrogate-pairs.js index b976f56634de43..39d1ac06c4cbef 100644 --- a/test/common/file-operations-with-surrogate-pairs.js +++ b/test/common/file-operations-with-surrogate-pairs.js @@ -7,9 +7,10 @@ const { describe, it } = require('node:test'); describe('File operations with filenames containing surrogate pairs', () => { it('should write, read, and delete a file with surrogate pairs in the filename', () => { - // Use a common temporary directory - const tempdir = '/tmp/emoji-fruit'; - + // Create a temporary directory + const tempdir = fs.mkdtempSync('emoji-fruit-🍇 🍈 🍉 🍊 🍋'); + assert.strictEqual(fs.existsSync(tempdir), true); + const filename = '🚀🔥🛸.txt'; const content = 'Test content'; @@ -39,5 +40,9 @@ describe('File operations with filenames containing surrogate pairs', () => { // Delete the file fs.unlinkSync(path.join(tempdir, filename)); assert.strictEqual(fs.existsSync(path.join(tempdir, filename)), false); + + // Remove the temporary directory + fs.rmdirSync(tempdir); + assert.strictEqual(fs.existsSync(tempdir), false); }); }); From b5b804534d061df0cac4d71fced87ecc8e93955f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mert=20Can=20Alt=C4=B1n?= Date: Mon, 19 Feb 2024 15:26:41 +0300 Subject: [PATCH 08/12] Update file-operations-with-surrogate-pairs.js Co-authored-by: Antoine du Hamel --- test/common/file-operations-with-surrogate-pairs.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/common/file-operations-with-surrogate-pairs.js b/test/common/file-operations-with-surrogate-pairs.js index 39d1ac06c4cbef..dad8c4c4fb4e3a 100644 --- a/test/common/file-operations-with-surrogate-pairs.js +++ b/test/common/file-operations-with-surrogate-pairs.js @@ -1,8 +1,8 @@ 'use strict'; const fs = require('node:fs'); -const path = require('path'); -const assert = require('assert/strict'); +const path = require('node:path'); +const assert = require('node:assert'); const { describe, it } = require('node:test'); describe('File operations with filenames containing surrogate pairs', () => { From 3bb203fb499436f645ddbf861936c4022189e106 Mon Sep 17 00:00:00 2001 From: Mert Can Altin Date: Mon, 19 Feb 2024 16:16:52 +0300 Subject: [PATCH 09/12] feat: moved test file to parallel path --- .../fs-operations-with-surrogate-pairs.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/{common/file-operations-with-surrogate-pairs.js => parallel/fs-operations-with-surrogate-pairs.js} (100%) diff --git a/test/common/file-operations-with-surrogate-pairs.js b/test/parallel/fs-operations-with-surrogate-pairs.js similarity index 100% rename from test/common/file-operations-with-surrogate-pairs.js rename to test/parallel/fs-operations-with-surrogate-pairs.js From 085c4c40d26886a51124516982e333e8343166ea Mon Sep 17 00:00:00 2001 From: Mert Can Altin Date: Mon, 19 Feb 2024 16:54:11 +0300 Subject: [PATCH 10/12] fix: used tmpdir --- test/parallel/fs-operations-with-surrogate-pairs.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/parallel/fs-operations-with-surrogate-pairs.js b/test/parallel/fs-operations-with-surrogate-pairs.js index dad8c4c4fb4e3a..0a3cf7b91627a3 100644 --- a/test/parallel/fs-operations-with-surrogate-pairs.js +++ b/test/parallel/fs-operations-with-surrogate-pairs.js @@ -1,9 +1,13 @@ 'use strict'; +require('../common'); const fs = require('node:fs'); const path = require('node:path'); const assert = require('node:assert'); const { describe, it } = require('node:test'); +const tmpdir = require('../common/tmpdir'); + +tmpdir.refresh(); describe('File operations with filenames containing surrogate pairs', () => { it('should write, read, and delete a file with surrogate pairs in the filename', () => { From 1f2671ab6a6b24c0133a820eaf8507ddcecf9b3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mert=20Can=20Alt=C4=B1n?= Date: Mon, 19 Feb 2024 19:17:17 +0300 Subject: [PATCH 11/12] Update fs-operations-with-surrogate-pairs.js Co-authored-by: Antoine du Hamel --- .../fs-operations-with-surrogate-pairs.js | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/test/parallel/fs-operations-with-surrogate-pairs.js b/test/parallel/fs-operations-with-surrogate-pairs.js index 0a3cf7b91627a3..39cd03d78247a2 100644 --- a/test/parallel/fs-operations-with-surrogate-pairs.js +++ b/test/parallel/fs-operations-with-surrogate-pairs.js @@ -27,26 +27,5 @@ describe('File operations with filenames containing surrogate pairs', () => { // Check if the content matches assert.strictEqual(readContent, content); - // Get directory contents - const dirs = fs.readdirSync(tempdir); - assert.strictEqual(dirs.length > 0, true); - - // Check if the file is in the directory contents - let match = false; - for (let i = 0; i < dirs.length; i++) { - if (dirs[i].endsWith(filename)) { - match = true; - break; - } - } - assert.strictEqual(match, true); - - // Delete the file - fs.unlinkSync(path.join(tempdir, filename)); - assert.strictEqual(fs.existsSync(path.join(tempdir, filename)), false); - - // Remove the temporary directory - fs.rmdirSync(tempdir); - assert.strictEqual(fs.existsSync(tempdir), false); }); }); From b91c291fd769ea2b01073fa01c3582246a4624ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mert=20Can=20Alt=C4=B1n?= Date: Mon, 19 Feb 2024 19:17:28 +0300 Subject: [PATCH 12/12] Update fs-operations-with-surrogate-pairs.js Co-authored-by: Antoine du Hamel --- test/parallel/fs-operations-with-surrogate-pairs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/fs-operations-with-surrogate-pairs.js b/test/parallel/fs-operations-with-surrogate-pairs.js index 39cd03d78247a2..d46623e8c208ae 100644 --- a/test/parallel/fs-operations-with-surrogate-pairs.js +++ b/test/parallel/fs-operations-with-surrogate-pairs.js @@ -12,7 +12,7 @@ tmpdir.refresh(); describe('File operations with filenames containing surrogate pairs', () => { it('should write, read, and delete a file with surrogate pairs in the filename', () => { // Create a temporary directory - const tempdir = fs.mkdtempSync('emoji-fruit-🍇 🍈 🍉 🍊 🍋'); + const tempdir = fs.mkdtempSync(tmpdir.resolve('emoji-fruit-🍇 🍈 🍉 🍊 🍋')); assert.strictEqual(fs.existsSync(tempdir), true); const filename = '🚀🔥🛸.txt';