GeezerVison is showing github.com — test: use `tmpdir.resolve()` in fs tests · nodejs/node@661b055
File treeExpand file treeCollapse file tree Open diff view settings Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-fs-access.js +3-4Lines changed: 3 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -13,15 +13,14 @@ if (common.isIBMi) | 13 | 13 |
| 14 | 14 | const assert = require('assert'); | 15 | 15 | const fs = require('fs'); | 16 | | -const path = require('path'); | 17 | 16 |
| 18 | 17 | const { internalBinding } = require('internal/test/binding'); | 19 | 18 | const { UV_ENOENT } = internalBinding('uv'); | 20 | 19 |
| 21 | 20 | const tmpdir = require('../common/tmpdir'); | 22 | | -const doesNotExist = path.join(tmpdir.path, '__this_should_not_exist'); | 23 | | -const readOnlyFile = path.join(tmpdir.path, 'read_only_file'); | 24 | | -const readWriteFile = path.join(tmpdir.path, 'read_write_file'); | | 21 | +const doesNotExist = tmpdir.resolve('__this_should_not_exist'); | | 22 | +const readOnlyFile = tmpdir.resolve('read_only_file'); | | 23 | +const readWriteFile = tmpdir.resolve('read_write_file'); | 25 | 24 |
| 26 | 25 | function createFileWithPerms(file, mode) { | 27 | 26 | fs.writeFileSync(file, ''); | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-fs-append-file-sync.js +5-6Lines changed: 5 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 22 | 22 | 'use strict'; | 23 | 23 | const common = require('../common'); | 24 | 24 | const assert = require('assert'); | 25 | | -const join = require('path').join; | 26 | 25 | const fs = require('fs'); | 27 | 26 |
| 28 | 27 | const currentFileData = 'ABCD'; | @@ -40,7 +39,7 @@ const tmpdir = require('../common/tmpdir'); | 40 | 39 | tmpdir.refresh(); | 41 | 40 |
| 42 | 41 | // Test that empty file will be created and have content added. | 43 | | -const filename = join(tmpdir.path, 'append-sync.txt'); | | 42 | +const filename = tmpdir.resolve('append-sync.txt'); | 44 | 43 |
| 45 | 44 | fs.appendFileSync(filename, data); | 46 | 45 |
| @@ -49,7 +48,7 @@ const fileData = fs.readFileSync(filename); | 49 | 48 | assert.strictEqual(Buffer.byteLength(data), fileData.length); | 50 | 49 |
| 51 | 50 | // Test that appends data to a non empty file. | 52 | | -const filename2 = join(tmpdir.path, 'append-sync2.txt'); | | 51 | +const filename2 = tmpdir.resolve('append-sync2.txt'); | 53 | 52 | fs.writeFileSync(filename2, currentFileData); | 54 | 53 |
| 55 | 54 | fs.appendFileSync(filename2, data); | @@ -60,7 +59,7 @@ assert.strictEqual(Buffer.byteLength(data) + currentFileData.length, | 60 | 59 | fileData2.length); | 61 | 60 |
| 62 | 61 | // Test that appendFileSync accepts buffers. | 63 | | -const filename3 = join(tmpdir.path, 'append-sync3.txt'); | | 62 | +const filename3 = tmpdir.resolve('append-sync3.txt'); | 64 | 63 | fs.writeFileSync(filename3, currentFileData); | 65 | 64 |
| 66 | 65 | const buf = Buffer.from(data, 'utf8'); | @@ -70,7 +69,7 @@ const fileData3 = fs.readFileSync(filename3); | 70 | 69 |
| 71 | 70 | assert.strictEqual(buf.length + currentFileData.length, fileData3.length); | 72 | 71 |
| 73 | | -const filename4 = join(tmpdir.path, 'append-sync4.txt'); | | 72 | +const filename4 = tmpdir.resolve('append-sync4.txt'); | 74 | 73 | fs.writeFileSync(filename4, currentFileData, common.mustNotMutateObjectDeep({ mode: m })); | 75 | 74 |
| 76 | 75 | [ | @@ -95,7 +94,7 @@ assert.strictEqual(Buffer.byteLength(String(num)) + currentFileData.length, | 95 | 94 | fileData4.length); | 96 | 95 |
| 97 | 96 | // Test that appendFile accepts file descriptors. | 98 | | -const filename5 = join(tmpdir.path, 'append-sync5.txt'); | | 97 | +const filename5 = tmpdir.resolve('append-sync5.txt'); | 99 | 98 | fs.writeFileSync(filename5, currentFileData); | 100 | 99 |
| 101 | 100 | const filename5fd = fs.openSync(filename5, 'a+', 0o600); | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-fs-append-file.js +10-11Lines changed: 10 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 23 | 23 | const common = require('../common'); | 24 | 24 | const assert = require('assert'); | 25 | 25 | const fs = require('fs'); | 26 | | -const join = require('path').join; | 27 | 26 |
| 28 | 27 | const tmpdir = require('../common/tmpdir'); | 29 | 28 |
| @@ -43,7 +42,7 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); }; | 43 | 42 |
| 44 | 43 | // Test that empty file will be created and have content added (callback API). | 45 | 44 | { | 46 | | - const filename = join(tmpdir.path, 'append.txt'); | | 45 | + const filename = tmpdir.resolve('append.txt'); | 47 | 46 |
| 48 | 47 | fs.appendFile(filename, s, common.mustSucceed(() => { | 49 | 48 | fs.readFile(filename, common.mustSucceed((buffer) => { | @@ -54,7 +53,7 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); }; | 54 | 53 |
| 55 | 54 | // Test that empty file will be created and have content added (promise API). | 56 | 55 | { | 57 | | - const filename = join(tmpdir.path, 'append-promise.txt'); | | 56 | + const filename = tmpdir.resolve('append-promise.txt'); | 58 | 57 |
| 59 | 58 | fs.promises.appendFile(filename, s) | 60 | 59 | .then(common.mustCall(() => fs.promises.readFile(filename))) | @@ -66,7 +65,7 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); }; | 66 | 65 |
| 67 | 66 | // Test that appends data to a non-empty file (callback API). | 68 | 67 | { | 69 | | - const filename = join(tmpdir.path, 'append-non-empty.txt'); | | 68 | + const filename = tmpdir.resolve('append-non-empty.txt'); | 70 | 69 | fs.writeFileSync(filename, currentFileData); | 71 | 70 |
| 72 | 71 | fs.appendFile(filename, s, common.mustSucceed(() => { | @@ -79,7 +78,7 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); }; | 79 | 78 |
| 80 | 79 | // Test that appends data to a non-empty file (promise API). | 81 | 80 | { | 82 | | - const filename = join(tmpdir.path, 'append-non-empty-promise.txt'); | | 81 | + const filename = tmpdir.resolve('append-non-empty-promise.txt'); | 83 | 82 | fs.writeFileSync(filename, currentFileData); | 84 | 83 |
| 85 | 84 | fs.promises.appendFile(filename, s) | @@ -93,7 +92,7 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); }; | 93 | 92 |
| 94 | 93 | // Test that appendFile accepts buffers (callback API). | 95 | 94 | { | 96 | | - const filename = join(tmpdir.path, 'append-buffer.txt'); | | 95 | + const filename = tmpdir.resolve('append-buffer.txt'); | 97 | 96 | fs.writeFileSync(filename, currentFileData); | 98 | 97 |
| 99 | 98 | const buf = Buffer.from(s, 'utf8'); | @@ -107,7 +106,7 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); }; | 107 | 106 |
| 108 | 107 | // Test that appendFile accepts buffers (promises API). | 109 | 108 | { | 110 | | - const filename = join(tmpdir.path, 'append-buffer-promises.txt'); | | 109 | + const filename = tmpdir.resolve('append-buffer-promises.txt'); | 111 | 110 | fs.writeFileSync(filename, currentFileData); | 112 | 111 |
| 113 | 112 | const buf = Buffer.from(s, 'utf8'); | @@ -126,7 +125,7 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); }; | 126 | 125 | code: 'ERR_INVALID_ARG_TYPE', | 127 | 126 | message: /"data"|"buffer"/ | 128 | 127 | }; | 129 | | - const filename = join(tmpdir.path, 'append-invalid-data.txt'); | | 128 | + const filename = tmpdir.resolve('append-invalid-data.txt'); | 130 | 129 |
| 131 | 130 | assert.throws( | 132 | 131 | () => fs.appendFile(filename, data, common.mustNotCall()), | @@ -154,7 +153,7 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); }; | 154 | 153 |
| 155 | 154 | // Test that appendFile accepts file descriptors (callback API). | 156 | 155 | { | 157 | | - const filename = join(tmpdir.path, 'append-descriptors.txt'); | | 156 | + const filename = tmpdir.resolve('append-descriptors.txt'); | 158 | 157 | fs.writeFileSync(filename, currentFileData); | 159 | 158 |
| 160 | 159 | fs.open(filename, 'a+', common.mustSucceed((fd) => { | @@ -171,7 +170,7 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); }; | 171 | 170 |
| 172 | 171 | // Test that appendFile accepts file descriptors (promises API). | 173 | 172 | { | 174 | | - const filename = join(tmpdir.path, 'append-descriptors-promises.txt'); | | 173 | + const filename = tmpdir.resolve('append-descriptors-promises.txt'); | 175 | 174 | fs.writeFileSync(filename, currentFileData); | 176 | 175 |
| 177 | 176 | let fd; | @@ -190,5 +189,5 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); }; | 190 | 189 | } | 191 | 190 |
| 192 | 191 | assert.throws( | 193 | | - () => fs.appendFile(join(tmpdir.path, 'append6.txt'), console.log), | | 192 | + () => fs.appendFile(tmpdir.resolve('append6.txt'), console.log), | 194 | 193 | { code: 'ERR_INVALID_ARG_TYPE' }); |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-fs-assert-encoding-error.js +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 | const common = require('../common'); | 3 | 3 | const assert = require('node:assert'); | 4 | 4 | const fs = require('node:fs'); | 5 | | -const path = require('node:path'); | 6 | 5 | const tmpdir = require('../common/tmpdir'); | 7 | 6 |
| 8 | | -const testPath = path.join(tmpdir.path, 'assert-encoding-error'); | | 7 | +const testPath = tmpdir.resolve('assert-encoding-error'); | 9 | 8 | const options = 'test'; | 10 | 9 | const expectedError = { | 11 | 10 | code: 'ERR_INVALID_ARG_VALUE', | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-fs-buffer.js +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,14 +4,13 @@ const common = require('../common'); | 4 | 4 | const fixtures = require('../common/fixtures'); | 5 | 5 | const assert = require('assert'); | 6 | 6 | const fs = require('fs'); | 7 | | -const path = require('path'); | 8 | 7 |
| 9 | 8 | const tmpdir = require('../common/tmpdir'); | 10 | 9 | tmpdir.refresh(); | 11 | 10 |
| 12 | 11 | fs.access(Buffer.from(tmpdir.path), common.mustSucceed()); | 13 | 12 |
| 14 | | -const buf = Buffer.from(path.join(tmpdir.path, 'a.txt')); | | 13 | +const buf = Buffer.from(tmpdir.resolve('a.txt')); | 15 | 14 | fs.open(buf, 'w+', common.mustSucceed((fd) => { | 16 | 15 | assert(fd); | 17 | 16 | fs.close(fd, common.mustSucceed()); | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-fs-chmod-mask.js +8-9Lines changed: 8 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 |
| 5 | 5 | const common = require('../common'); | 6 | 6 | const assert = require('assert'); | 7 | | -const path = require('path'); | 8 | 7 | const fs = require('fs'); | 9 | 8 |
| 10 | 9 | let mode; | @@ -26,7 +25,7 @@ function test(mode, asString) { | 26 | 25 | (mode | maskToIgnore).toString(8) : (mode | maskToIgnore); | 27 | 26 |
| 28 | 27 | { | 29 | | - const file = path.join(tmpdir.path, `chmod-async-${suffix}.txt`); | | 28 | + const file = tmpdir.resolve(`chmod-async-${suffix}.txt`); | 30 | 29 | fs.writeFileSync(file, 'test', 'utf-8'); | 31 | 30 |
| 32 | 31 | fs.chmod(file, input, common.mustSucceed(() => { | @@ -35,15 +34,15 @@ function test(mode, asString) { | 35 | 34 | } | 36 | 35 |
| 37 | 36 | { | 38 | | - const file = path.join(tmpdir.path, `chmodSync-${suffix}.txt`); | | 37 | + const file = tmpdir.resolve(`chmodSync-${suffix}.txt`); | 39 | 38 | fs.writeFileSync(file, 'test', 'utf-8'); | 40 | 39 |
| 41 | 40 | fs.chmodSync(file, input); | 42 | 41 | assert.strictEqual(fs.statSync(file).mode & 0o777, mode); | 43 | 42 | } | 44 | 43 |
| 45 | 44 | { | 46 | | - const file = path.join(tmpdir.path, `fchmod-async-${suffix}.txt`); | | 45 | + const file = tmpdir.resolve(`fchmod-async-${suffix}.txt`); | 47 | 46 | fs.writeFileSync(file, 'test', 'utf-8'); | 48 | 47 | fs.open(file, 'w', common.mustSucceed((fd) => { | 49 | 48 | fs.fchmod(fd, input, common.mustSucceed(() => { | @@ -54,7 +53,7 @@ function test(mode, asString) { | 54 | 53 | } | 55 | 54 |
| 56 | 55 | { | 57 | | - const file = path.join(tmpdir.path, `fchmodSync-${suffix}.txt`); | | 56 | + const file = tmpdir.resolve(`fchmodSync-${suffix}.txt`); | 58 | 57 | fs.writeFileSync(file, 'test', 'utf-8'); | 59 | 58 | const fd = fs.openSync(file, 'w'); | 60 | 59 |
| @@ -65,8 +64,8 @@ function test(mode, asString) { | 65 | 64 | } | 66 | 65 |
| 67 | 66 | if (fs.lchmod) { | 68 | | - const link = path.join(tmpdir.path, `lchmod-src-${suffix}`); | 69 | | - const file = path.join(tmpdir.path, `lchmod-dest-${suffix}`); | | 67 | + const link = tmpdir.resolve(`lchmod-src-${suffix}`); | | 68 | + const file = tmpdir.resolve(`lchmod-dest-${suffix}`); | 70 | 69 | fs.writeFileSync(file, 'test', 'utf-8'); | 71 | 70 | fs.symlinkSync(file, link); | 72 | 71 |
| @@ -76,8 +75,8 @@ function test(mode, asString) { | 76 | 75 | } | 77 | 76 |
| 78 | 77 | if (fs.lchmodSync) { | 79 | | - const link = path.join(tmpdir.path, `lchmodSync-src-${suffix}`); | 80 | | - const file = path.join(tmpdir.path, `lchmodSync-dest-${suffix}`); | | 78 | + const link = tmpdir.resolve(`lchmodSync-src-${suffix}`); | | 79 | + const file = tmpdir.resolve(`lchmodSync-dest-${suffix}`); | 81 | 80 | fs.writeFileSync(file, 'test', 'utf-8'); | 82 | 81 | fs.symlinkSync(file, link); | 83 | 82 |
| |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-fs-chmod.js +3-4Lines changed: 3 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 22 | 22 | 'use strict'; | 23 | 23 | const common = require('../common'); | 24 | 24 | const assert = require('assert'); | 25 | | -const path = require('path'); | 26 | 25 | const fs = require('fs'); | 27 | 26 |
| 28 | 27 | let mode_async; | @@ -74,8 +73,8 @@ if (common.isWindows) { | 74 | 73 | const tmpdir = require('../common/tmpdir'); | 75 | 74 | tmpdir.refresh(); | 76 | 75 |
| 77 | | -const file1 = path.join(tmpdir.path, 'a.js'); | 78 | | -const file2 = path.join(tmpdir.path, 'a1.js'); | | 76 | +const file1 = tmpdir.resolve('a.js'); | | 77 | +const file2 = tmpdir.resolve('a1.js'); | 79 | 78 |
| 80 | 79 | // Create file1. | 81 | 80 | fs.closeSync(fs.openSync(file1, 'w')); | @@ -123,7 +122,7 @@ fs.open(file2, 'w', common.mustSucceed((fd) => { | 123 | 122 |
| 124 | 123 | // lchmod | 125 | 124 | if (fs.lchmod) { | 126 | | - const link = path.join(tmpdir.path, 'symbolic-link'); | | 125 | + const link = tmpdir.resolve('symbolic-link'); | 127 | 126 |
| 128 | 127 | fs.symlinkSync(file2, link); | 129 | 128 |
| |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-fs-copyfile-respect-permissions.js +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,14 +16,13 @@ tmpdir.refresh(); | 16 | 16 |
| 17 | 17 | const assert = require('assert'); | 18 | 18 | const fs = require('fs'); | 19 | | -const path = require('path'); | 20 | 19 |
| 21 | 20 | let n = 0; | 22 | 21 |
| 23 | 22 | function beforeEach() { | 24 | 23 | n++; | 25 | | - const source = path.join(tmpdir.path, `source${n}`); | 26 | | - const dest = path.join(tmpdir.path, `dest${n}`); | | 24 | + const source = tmpdir.resolve(`source${n}`); | | 25 | + const dest = tmpdir.resolve(`dest${n}`); | 27 | 26 | fs.writeFileSync(source, 'source'); | 28 | 27 | fs.writeFileSync(dest, 'dest'); | 29 | 28 | fs.chmodSync(dest, '444'); | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-fs-copyfile.js +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,9 +10,8 @@ const { | 10 | 10 | UV_ENOENT, | 11 | 11 | UV_EEXIST | 12 | 12 | } = internalBinding('uv'); | 13 | | -const path = require('path'); | 14 | 13 | const src = fixtures.path('a.js'); | 15 | | -const dest = path.join(tmpdir.path, 'copyfile.out'); | | 14 | +const dest = tmpdir.resolve('copyfile.out'); | 16 | 15 | const { | 17 | 16 | COPYFILE_EXCL, | 18 | 17 | COPYFILE_FICLONE, | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-fs-cp.mjs +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -25,7 +25,7 @@ tmpdir.refresh(); | 25 | 25 |
| 26 | 26 | let dirc = 0; | 27 | 27 | function nextdir() { | 28 | | - return join(tmpdir.path, `copy_${++dirc}`); | | 28 | + return tmpdir.resolve(`copy_${++dirc}`); | 29 | 29 | } | 30 | 30 |
| 31 | 31 | // Synchronous implementation of copy. | |
|