diff --git a/tests/legacy-cli/e2e/setup/001-create-tmp-dir.ts b/tests/legacy-cli/e2e/setup/001-create-tmp-dir.ts index f15e504daef1..07c5855a8394 100644 --- a/tests/legacy-cli/e2e/setup/001-create-tmp-dir.ts +++ b/tests/legacy-cli/e2e/setup/001-create-tmp-dir.ts @@ -1,9 +1,8 @@ -import { mkdtempSync, realpathSync } from 'fs'; -import { tmpdir } from 'os'; -import { dirname, join } from 'path'; +import { dirname } from 'path'; import { getGlobalVariable, setGlobalVariable } from '../utils/env'; +import { mktempd } from '../utils/utils'; -export default function () { +export default async function () { const argv = getGlobalVariable('argv'); // Get to a temporary directory. @@ -13,7 +12,7 @@ export default function () { } else if (argv.tmpdir) { tempRoot = argv.tmpdir; } else { - tempRoot = mkdtempSync(join(realpathSync(tmpdir()), 'angular-cli-e2e-')); + tempRoot = await mktempd('angular-cli-e2e-'); } console.log(` Using "${tempRoot}" as temporary directory for a new project.`); setGlobalVariable('tmp-root', tempRoot); diff --git a/tests/legacy-cli/e2e/tests/commands/completion/completion-prompt.ts b/tests/legacy-cli/e2e/tests/commands/completion/completion-prompt.ts index 2661b89d0564..7efb5795aa19 100644 --- a/tests/legacy-cli/e2e/tests/commands/completion/completion-prompt.ts +++ b/tests/legacy-cli/e2e/tests/commands/completion/completion-prompt.ts @@ -1,8 +1,9 @@ import { promises as fs } from 'fs'; -import * as os from 'os'; import * as path from 'path'; import { env } from 'process'; import { getGlobalVariable } from '../../../utils/env'; +import { mktempd } from '../../../utils/utils'; + import { execAndCaptureError, execAndWaitForOutputToMatch, @@ -448,7 +449,7 @@ async function windowsTests(): Promise { } async function mockHome(cb: (home: string) => Promise): Promise { - const tempHome = await fs.mkdtemp(path.join(os.tmpdir(), 'angular-cli-e2e-home-')); + const tempHome = await mktempd('angular-cli-e2e-home-'); try { await cb(tempHome); diff --git a/tests/legacy-cli/e2e/tests/commands/completion/completion.ts b/tests/legacy-cli/e2e/tests/commands/completion/completion.ts index 22c233aa3b40..2e8875c19193 100644 --- a/tests/legacy-cli/e2e/tests/commands/completion/completion.ts +++ b/tests/legacy-cli/e2e/tests/commands/completion/completion.ts @@ -1,7 +1,7 @@ import { promises as fs } from 'fs'; -import * as os from 'os'; import * as path from 'path'; import { getGlobalVariable } from '../../../utils/env'; +import { mktempd } from '../../../utils/utils'; import { execAndCaptureError, execAndWaitForOutputToMatch, @@ -397,7 +397,7 @@ async function windowsTests(): Promise { } async function mockHome(cb: (home: string) => Promise): Promise { - const tempHome = await fs.mkdtemp(path.join(os.tmpdir(), 'angular-cli-e2e-home-')); + const tempHome = await mktempd('angular-cli-e2e-home-'); try { await cb(tempHome); diff --git a/tests/legacy-cli/e2e/utils/registry.ts b/tests/legacy-cli/e2e/utils/registry.ts index 6b3b07ade96e..3cfee5f71405 100644 --- a/tests/legacy-cli/e2e/utils/registry.ts +++ b/tests/legacy-cli/e2e/utils/registry.ts @@ -1,9 +1,8 @@ import { spawn } from 'child_process'; -import { mkdtempSync, realpathSync } from 'fs'; -import { tmpdir } from 'os'; import { join } from 'path'; import { getGlobalVariable } from './env'; import { writeFile, readFile } from './fs'; +import { mktempd } from './utils'; export async function createNpmRegistry( port: number, @@ -11,7 +10,7 @@ export async function createNpmRegistry( withAuthentication = false, ) { // Setup local package registry - const registryPath = mkdtempSync(join(realpathSync(tmpdir()), 'angular-cli-e2e-registry-')); + const registryPath = await mktempd('angular-cli-e2e-registry-'); let configContent = await readFile( join(__dirname, '../../', withAuthentication ? 'verdaccio_auth.yaml' : 'verdaccio.yaml'), diff --git a/tests/legacy-cli/e2e/utils/utils.ts b/tests/legacy-cli/e2e/utils/utils.ts index da9557166602..da7b8b5921bc 100644 --- a/tests/legacy-cli/e2e/utils/utils.ts +++ b/tests/legacy-cli/e2e/utils/utils.ts @@ -1,3 +1,7 @@ +import { mkdtemp, realpath } from 'fs/promises'; +import { tmpdir } from 'os'; +import path from 'path'; + export function expectToFail(fn: () => Promise, errorMessage?: string): Promise { return fn().then( () => { @@ -18,3 +22,7 @@ export function wait(msecs: number): Promise { setTimeout(resolve, msecs); }); } + +export async function mktempd(prefix: string): Promise { + return realpath(await mkdtemp(path.join(tmpdir(), prefix))); +}