Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bc2bcd4

Browse files
authored
test: use promise based fs functions in integration tests helpers (#6515)
1 parent 9a61a79 commit bc2bcd4

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

integration-tests/helpers/index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ const childProcess = require('child_process')
55
const { fork, spawn } = childProcess
66
const exec = promisify(childProcess.exec)
77
const http = require('http')
8-
const fs = require('fs')
8+
const { existsSync, readFileSync, unlinkSync } = require('fs')
9+
const fs = require('fs/promises')
910
const { builtinModules } = require('module')
1011
const os = require('os')
1112
const path = require('path')
@@ -218,7 +219,7 @@ async function createSandbox (dependencies = [], isGitRepo = false,
218219
const out = path.join(folder, `dd-trace-${version}.tgz`)
219220
const allDependencies = [`file:${out}`].concat(cappedDependencies)
220221

221-
fs.mkdirSync(folder)
222+
await fs.mkdir(folder)
222223
const preferOfflineFlag = process.env.OFFLINE === '1' || process.env.OFFLINE === 'true' ? ' --prefer-offline' : ''
223224
const addCommand = `yarn add ${allDependencies.join(' ')} --ignore-engines${preferOfflineFlag}`
224225
const addOptions = { cwd: folder, env: restOfEnv }
@@ -250,14 +251,14 @@ async function createSandbox (dependencies = [], isGitRepo = false,
250251

251252
if (isGitRepo) {
252253
await exec('git init', { cwd: folder })
253-
fs.writeFileSync(path.join(folder, '.gitignore'), 'node_modules/', { flush: true })
254+
await fs.writeFile(path.join(folder, '.gitignore'), 'node_modules/', { flush: true })
254255
await exec('git config user.email "[email protected]"', { cwd: folder })
255256
await exec('git config user.name "John Doe"', { cwd: folder })
256257
await exec('git config commit.gpgsign false', { cwd: folder })
257258

258259
// Create a unique local bare repo for this test
259260
const localRemotePath = path.join(folder, '..', `${path.basename(folder)}-remote.git`)
260-
if (!fs.existsSync(localRemotePath)) {
261+
if (!existsSync(localRemotePath)) {
261262
await exec(`git init --bare ${localRemotePath}`)
262263
}
263264

@@ -333,7 +334,7 @@ function telemetryForwarder (shouldExpectTelemetryPoints = true) {
333334
const cleanup = function () {
334335
let msgs
335336
try {
336-
msgs = fs.readFileSync(process.env.FORWARDER_OUT, 'utf8').trim().split('\n')
337+
msgs = readFileSync(process.env.FORWARDER_OUT, 'utf8').trim().split('\n')
337338
} catch (e) {
338339
if (shouldExpectTelemetryPoints && e.code === 'ENOENT' && retries < 10) {
339340
return tryAgain()
@@ -356,7 +357,7 @@ function telemetryForwarder (shouldExpectTelemetryPoints = true) {
356357
}
357358
msgs[i] = [telemetryType, parsed]
358359
}
359-
fs.unlinkSync(process.env.FORWARDER_OUT)
360+
unlinkSync(process.env.FORWARDER_OUT)
360361
delete process.env.FORWARDER_OUT
361362
delete process.env.DD_TELEMETRY_FORWARDER_PATH
362363
return msgs

0 commit comments

Comments
 (0)