| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ae372f0 commit eb25252
155 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,22 +2,15 @@ | |||
| 2 | 2 | ||
| 3 | 3 | const assert = require('assert'); | |
| 4 | 4 | const http = require('http'); | |
| 5 | - const fs = require('fs'); | ||
| 6 | 5 | const { fork } = require('child_process'); | |
| 7 | 6 | const common = require('../common.js'); | |
| 8 | - const { PIPE, tmpDir } = require('../../test/common'); | ||
| 7 | + const { PIPE } = require('../../test/common'); | ||
| 8 | + const tmpdir = require('../../test/common/tmpdir'); | ||
| 9 | 9 | process.env.PIPE_NAME = PIPE; | |
| 10 | 10 | ||
| 11 | - try { | ||
| 12 | - fs.accessSync(tmpDir, fs.F_OK); | ||
| 13 | - } catch (e) { | ||
| 14 | - fs.mkdirSync(tmpDir); | ||
| 15 | - } | ||
| 11 | + tmpdir.refresh(); | ||
| 16 | 12 | ||
| 17 | 13 | var server; | |
| 18 | - try { | ||
| 19 | - fs.unlinkSync(process.env.PIPE_NAME); | ||
| 20 | - } catch (e) { /* ignore */ } | ||
| 21 | 14 | ||
| 22 | 15 | server = http.createServer(function(req, res) { | |
| 23 | 16 | const headers = { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,8 +3,8 @@ const fs = require('fs'); | |||
| 3 | 3 | const path = require('path'); | |
| 4 | 4 | const common = require('../common.js'); | |
| 5 | 5 | ||
| 6 | - const { refreshTmpDir, tmpDir } = require('../../test/common'); | ||
| 7 | - const benchmarkDirectory = path.join(tmpDir, 'nodejs-benchmark-module'); | ||
| 6 | + const tmpdir = require('../../test/common/tmpdir'); | ||
| 7 | + const benchmarkDirectory = path.join(tmpdir.path, 'nodejs-benchmark-module'); | ||
| 8 | 8 | ||
| 9 | 9 | const bench = common.createBenchmark(main, { | |
| 10 | 10 | thousands: [50], | |
@@ -15,7 +15,7 @@ const bench = common.createBenchmark(main, { | |||
| 15 | 15 | function main({ thousands, fullPath, useCache }) { | |
| 16 | 16 | const n = thousands * 1e3; | |
| 17 | 17 | ||
| 18 | - refreshTmpDir(); | ||
| 18 | + tmpdir.refresh(); | ||
| 19 | 19 | try { fs.mkdirSync(benchmarkDirectory); } catch (e) {} | |
| 20 | 20 | ||
| 21 | 21 | for (var i = 0; i <= n; i++) { | |
@@ -35,7 +35,7 @@ function main({ thousands, fullPath, useCache }) { | |||
| 35 | 35 | else | |
| 36 | 36 | measureDir(n, useCache === 'true'); | |
| 37 | 37 | ||
| 38 | - refreshTmpDir(); | ||
| 38 | + tmpdir.refresh(); | ||
| 39 | 39 | } | |
| 40 | 40 | ||
| 41 | 41 | function measureFull(n, useCache) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,12 +7,13 @@ const fs = require('fs'); | |||
| 7 | 7 | const path = require('path'); | |
| 8 | 8 | const assert = require('assert'); | |
| 9 | 9 | ||
| 10 | - common.refreshTmpDir(); | ||
| 10 | + const tmpdir = require('../../common/tmpdir'); | ||
| 11 | + tmpdir.refresh(); | ||
| 11 | 12 | ||
| 12 | 13 | // make a path that is more than 260 chars long. | |
| 13 | 14 | // Any given folder cannot have a name longer than 260 characters, | |
| 14 | 15 | // so create 10 nested folders each with 30 character long names. | |
| 15 | - let addonDestinationDir = path.resolve(common.tmpDir); | ||
| 16 | + let addonDestinationDir = path.resolve(tmpdir.path); | ||
| 16 | 17 | ||
| 17 | 18 | for (let i = 0; i < 10; i++) { | |
| 18 | 19 | addonDestinationDir = path.join(addonDestinationDir, 'x'.repeat(30)); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,10 +12,11 @@ const assert = require('assert'); | |||
| 12 | 12 | // This test should pass in Node.js v4 and v5. This test will pass in Node.js | |
| 13 | 13 | // with https://github.com/nodejs/node/pull/5950 reverted. | |
| 14 | 14 | ||
| 15 | - common.refreshTmpDir(); | ||
| 15 | + const tmpdir = require('../../common/tmpdir'); | ||
| 16 | + tmpdir.refresh(); | ||
| 16 | 17 | ||
| 17 | 18 | const addonPath = path.join(__dirname, 'build', common.buildType); | |
| 18 | - const addonLink = path.join(common.tmpDir, 'addon'); | ||
| 19 | + const addonLink = path.join(tmpdir.path, 'addon'); | ||
| 19 | 20 | ||
| 20 | 21 | try { | |
| 21 | 22 | fs.symlinkSync(addonPath, addonLink); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,7 +6,8 @@ const verifyGraph = require('./verify-graph'); | |||
| 6 | 6 | ||
| 7 | 7 | const net = require('net'); | |
| 8 | 8 | ||
| 9 | - common.refreshTmpDir(); | ||
| 9 | + const tmpdir = require('../common/tmpdir'); | ||
| 10 | + tmpdir.refresh(); | ||
| 10 | 11 | ||
| 11 | 12 | const hooks = initHooks(); | |
| 12 | 13 | hooks.enable(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,7 +8,8 @@ const { checkInvocations } = require('./hook-checks'); | |||
| 8 | 8 | ||
| 9 | 9 | const net = require('net'); | |
| 10 | 10 | ||
| 11 | - common.refreshTmpDir(); | ||
| 11 | + const tmpdir = require('../common/tmpdir'); | ||
| 12 | + tmpdir.refresh(); | ||
| 12 | 13 | ||
| 13 | 14 | const hooks = initHooks(); | |
| 14 | 15 | hooks.enable(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,6 +12,7 @@ This directory contains modules used to test the Node.js implementation. | |||
| 12 | 12 | * [Fixtures module](#fixtures-module) | |
| 13 | 13 | * [HTTP2 module](#http2-module) | |
| 14 | 14 | * [Internet module](#internet-module) | |
| 15 | + * [tmpdir module](#tmpdir-module) | ||
| 15 | 16 | * [WPT module](#wpt-module) | |
| 16 | 17 | ||
| 17 | 18 | ## Benchmark Module | |
@@ -332,11 +333,6 @@ A port number for tests to use if one is needed. | |||
| 332 | 333 | ||
| 333 | 334 | Logs '1..0 # Skipped: ' + `msg` | |
| 334 | 335 | ||
| 335 | - ### refreshTmpDir() | ||
| 336 | - * return [<String>] | ||
| 337 | - | ||
| 338 | - Deletes the testing 'tmp' directory and recreates it. | ||
| 339 | - | ||
| 340 | 336 | ### restoreStderr() | |
| 341 | 337 | ||
| 342 | 338 | Restore the original `process.stderr.write`. Used to restore `stderr` to its | |
@@ -384,11 +380,6 @@ Platform normalizes the `pwd` command. | |||
| 384 | 380 | ||
| 385 | 381 | Synchronous version of `spawnPwd`. | |
| 386 | 382 | ||
| 387 | - ### tmpDir | ||
| 388 | - * [<String>] | ||
| 389 | - | ||
| 390 | - The realpath of the 'tmp' directory. | ||
| 391 | - | ||
| 392 | 383 | ## Countdown Module | |
| 393 | 384 | ||
| 394 | 385 | The `Countdown` module provides a simple countdown mechanism for tests that | |
@@ -670,6 +661,19 @@ via `NODE_TEST_*` environment variables. For example, to configure | |||
| 670 | 661 | `internet.addresses.INET_HOST`, set the environment | |
| 671 | 662 | variable `NODE_TEST_INET_HOST` to a specified host. | |
| 672 | 663 | ||
| 664 | + ## tmpdir Module | ||
| 665 | + | ||
| 666 | + The `tmpdir` module supports the use of a temporary directory for testing. | ||
| 667 | + | ||
| 668 | + ### path | ||
| 669 | + * [<String>] | ||
| 670 | + | ||
| 671 | + The realpath of the testing temporary directory. | ||
| 672 | + | ||
| 673 | + ### refresh() | ||
| 674 | + | ||
| 675 | + Deletes and recreates the testing temporary directory. | ||
| 676 | + | ||
| 673 | 677 | ## WPT Module | |
| 674 | 678 | ||
| 675 | 679 | The wpt.js module is a port of parts of | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,16 +30,10 @@ const stream = require('stream'); | |||
| 30 | 30 | const util = require('util'); | |
| 31 | 31 | const Timer = process.binding('timer_wrap').Timer; | |
| 32 | 32 | const { fixturesDir } = require('./fixtures'); | |
| 33 | - | ||
| 34 | - const testRoot = process.env.NODE_TEST_DIR ? | ||
| 35 | - fs.realpathSync(process.env.NODE_TEST_DIR) : path.resolve(__dirname, '..'); | ||
| 33 | + const tmpdir = require('./tmpdir'); | ||
| 36 | 34 | ||
| 37 | 35 | const noop = () => {}; | |
| 38 | 36 | ||
| 39 | - // Using a `.` prefixed name, which is the convention for "hidden" on POSIX, | ||
| 40 | - // gets tools to ignore it by default or by simple rules, especially eslint. | ||
| 41 | - let tmpDirName = '.tmp'; | ||
| 42 | - | ||
| 43 | 37 | Object.defineProperty(exports, 'PORT', { | |
| 44 | 38 | get: () => { | |
| 45 | 39 | if (+process.env.TEST_PARALLEL) { | |
@@ -120,62 +114,6 @@ if (process.env.NODE_TEST_WITH_ASYNC_HOOKS) { | |||
| 120 | 114 | }).enable(); | |
| 121 | 115 | } | |
| 122 | 116 | ||
| 123 | - function rimrafSync(p) { | ||
| 124 | - let st; | ||
| 125 | - try { | ||
| 126 | - st = fs.lstatSync(p); | ||
| 127 | - } catch (e) { | ||
| 128 | - if (e.code === 'ENOENT') | ||
| 129 | - return; | ||
| 130 | - } | ||
| 131 | - | ||
| 132 | - try { | ||
| 133 | - if (st && st.isDirectory()) | ||
| 134 | - rmdirSync(p, null); | ||
| 135 | - else | ||
| 136 | - fs.unlinkSync(p); | ||
| 137 | - } catch (e) { | ||
| 138 | - if (e.code === 'ENOENT') | ||
| 139 | - return; | ||
| 140 | - if (e.code === 'EPERM') | ||
| 141 | - return rmdirSync(p, e); | ||
| 142 | - if (e.code !== 'EISDIR') | ||
| 143 | - throw e; | ||
| 144 | - rmdirSync(p, e); | ||
| 145 | - } | ||
| 146 | - } | ||
| 147 | - | ||
| 148 | - function rmdirSync(p, originalEr) { | ||
| 149 | - try { | ||
| 150 | - fs.rmdirSync(p); | ||
| 151 | - } catch (e) { | ||
| 152 | - if (e.code === 'ENOTDIR') | ||
| 153 | - throw originalEr; | ||
| 154 | - if (e.code === 'ENOTEMPTY' || e.code === 'EEXIST' || e.code === 'EPERM') { | ||
| 155 | - const enc = exports.isLinux ? 'buffer' : 'utf8'; | ||
| 156 | - fs.readdirSync(p, enc).forEach((f) => { | ||
| 157 | - if (f instanceof Buffer) { | ||
| 158 | - const buf = Buffer.concat([Buffer.from(p), Buffer.from(path.sep), f]); | ||
| 159 | - rimrafSync(buf); | ||
| 160 | - } else { | ||
| 161 | - rimrafSync(path.join(p, f)); | ||
| 162 | - } | ||
| 163 | - }); | ||
| 164 | - fs.rmdirSync(p); | ||
| 165 | - } | ||
| 166 | - } | ||
| 167 | - } | ||
| 168 | - | ||
| 169 | - exports.refreshTmpDir = function() { | ||
| 170 | - rimrafSync(exports.tmpDir); | ||
| 171 | - fs.mkdirSync(exports.tmpDir); | ||
| 172 | - }; | ||
| 173 | - | ||
| 174 | - if (process.env.TEST_THREAD_ID) { | ||
| 175 | - tmpDirName += `.${process.env.TEST_THREAD_ID}`; | ||
| 176 | - } | ||
| 177 | - exports.tmpDir = path.join(testRoot, tmpDirName); | ||
| 178 | - | ||
| 179 | 117 | let opensslCli = null; | |
| 180 | 118 | let inFreeBSDJail = null; | |
| 181 | 119 | let localhostIPv4 = null; | |
@@ -269,7 +207,7 @@ Object.defineProperty(exports, 'hasFipsCrypto', { | |||
| 269 | 207 | }); | |
| 270 | 208 | ||
| 271 | 209 | { | |
| 272 | - const localRelative = path.relative(process.cwd(), `${exports.tmpDir}/`); | ||
| 210 | + const localRelative = path.relative(process.cwd(), `${tmpdir.path}/`); | ||
| 273 | 211 | const pipePrefix = exports.isWindows ? '\\\\.\\pipe\\' : localRelative; | |
| 274 | 212 | const pipeName = `node-test.${process.pid}.sock`; | |
| 275 | 213 | exports.PIPE = path.join(pipePrefix, pipeName); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,67 @@ | |||
| 1 | + /* eslint-disable required-modules */ | ||
| 2 | + 'use strict'; | ||
| 3 | + | ||
| 4 | + const fs = require('fs'); | ||
| 5 | + const path = require('path'); | ||
| 6 | + | ||
| 7 | + function rimrafSync(p) { | ||
| 8 | + let st; | ||
| 9 | + try { | ||
| 10 | + st = fs.lstatSync(p); | ||
| 11 | + } catch (e) { | ||
| 12 | + if (e.code === 'ENOENT') | ||
| 13 | + return; | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + try { | ||
| 17 | + if (st && st.isDirectory()) | ||
| 18 | + rmdirSync(p, null); | ||
| 19 | + else | ||
| 20 | + fs.unlinkSync(p); | ||
| 21 | + } catch (e) { | ||
| 22 | + if (e.code === 'ENOENT') | ||
| 23 | + return; | ||
| 24 | + if (e.code === 'EPERM') | ||
| 25 | + return rmdirSync(p, e); | ||
| 26 | + if (e.code !== 'EISDIR') | ||
| 27 | + throw e; | ||
| 28 | + rmdirSync(p, e); | ||
| 29 | + } | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + function rmdirSync(p, originalEr) { | ||
| 33 | + try { | ||
| 34 | + fs.rmdirSync(p); | ||
| 35 | + } catch (e) { | ||
| 36 | + if (e.code === 'ENOTDIR') | ||
| 37 | + throw originalEr; | ||
| 38 | + if (e.code === 'ENOTEMPTY' || e.code === 'EEXIST' || e.code === 'EPERM') { | ||
| 39 | + const enc = process.platform === 'linux' ? 'buffer' : 'utf8'; | ||
| 40 | + fs.readdirSync(p, enc).forEach((f) => { | ||
| 41 | + if (f instanceof Buffer) { | ||
| 42 | + const buf = Buffer.concat([Buffer.from(p), Buffer.from(path.sep), f]); | ||
| 43 | + rimrafSync(buf); | ||
| 44 | + } else { | ||
| 45 | + rimrafSync(path.join(p, f)); | ||
| 46 | + } | ||
| 47 | + }); | ||
| 48 | + fs.rmdirSync(p); | ||
| 49 | + } | ||
| 50 | + } | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + const testRoot = process.env.NODE_TEST_DIR ? | ||
| 54 | + fs.realpathSync(process.env.NODE_TEST_DIR) : path.resolve(__dirname, '..'); | ||
| 55 | + | ||
| 56 | + // Using a `.` prefixed name, which is the convention for "hidden" on POSIX, | ||
| 57 | + // gets tools to ignore it by default or by simple rules, especially eslint. | ||
| 58 | + let tmpdirName = '.tmp'; | ||
| 59 | + if (process.env.TEST_THREAD_ID) { | ||
| 60 | + tmpdirName += `.${process.env.TEST_THREAD_ID}`; | ||
| 61 | + } | ||
| 62 | + exports.path = path.join(testRoot, tmpdirName); | ||
| 63 | + | ||
| 64 | + exports.refresh = () => { | ||
| 65 | + rimrafSync(exports.path); | ||
| 66 | + fs.mkdirSync(exports.path); | ||
| 67 | + }; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,8 +7,9 @@ const assert = require('assert'); | |||
| 7 | 7 | const path = require('path'); | |
| 8 | 8 | const fs = require('fs'); | |
| 9 | 9 | ||
| 10 | - common.refreshTmpDir(); | ||
| 11 | - const tmpDir = common.tmpDir; | ||
| 10 | + const tmpdir = require('../common/tmpdir'); | ||
| 11 | + tmpdir.refresh(); | ||
| 12 | + const tmpDir = tmpdir.path; | ||
| 12 | 13 | ||
| 13 | 14 | const entry = path.join(tmpDir, 'entry.js'); | |
| 14 | 15 | const real = path.join(tmpDir, 'real.js'); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments