Skip to content

Commit acd5ad5

Browse files
jbedardalan-agius4
authored andcommitted
test: move tempdir creation to util method
1 parent ceb97be commit acd5ad5

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

tests/legacy-cli/e2e/setup/001-create-tmp-dir.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { mkdtempSync, realpathSync } from 'fs';
2-
import { tmpdir } from 'os';
3-
import { dirname, join } from 'path';
1+
import { dirname } from 'path';
42
import { getGlobalVariable, setGlobalVariable } from '../utils/env';
3+
import { mktempd } from '../utils/utils';
54

6-
export default function () {
5+
export default async function () {
76
const argv = getGlobalVariable('argv');
87

98
// Get to a temporary directory.
@@ -13,7 +12,7 @@ export default function () {
1312
} else if (argv.tmpdir) {
1413
tempRoot = argv.tmpdir;
1514
} else {
16-
tempRoot = mkdtempSync(join(realpathSync(tmpdir()), 'angular-cli-e2e-'));
15+
tempRoot = await mktempd('angular-cli-e2e-');
1716
}
1817
console.log(` Using "${tempRoot}" as temporary directory for a new project.`);
1918
setGlobalVariable('tmp-root', tempRoot);

tests/legacy-cli/e2e/tests/commands/completion/completion-prompt.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { promises as fs } from 'fs';
2-
import * as os from 'os';
32
import * as path from 'path';
43
import { env } from 'process';
54
import { getGlobalVariable } from '../../../utils/env';
5+
import { mktempd } from '../../../utils/utils';
6+
67
import {
78
execAndCaptureError,
89
execAndWaitForOutputToMatch,
@@ -448,7 +449,7 @@ async function windowsTests(): Promise<void> {
448449
}
449450

450451
async function mockHome(cb: (home: string) => Promise<void>): Promise<void> {
451-
const tempHome = await fs.mkdtemp(path.join(os.tmpdir(), 'angular-cli-e2e-home-'));
452+
const tempHome = await mktempd('angular-cli-e2e-home-');
452453

453454
try {
454455
await cb(tempHome);

tests/legacy-cli/e2e/tests/commands/completion/completion.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { promises as fs } from 'fs';
2-
import * as os from 'os';
32
import * as path from 'path';
43
import { getGlobalVariable } from '../../../utils/env';
4+
import { mktempd } from '../../../utils/utils';
55
import {
66
execAndCaptureError,
77
execAndWaitForOutputToMatch,
@@ -397,7 +397,7 @@ async function windowsTests(): Promise<void> {
397397
}
398398

399399
async function mockHome(cb: (home: string) => Promise<void>): Promise<void> {
400-
const tempHome = await fs.mkdtemp(path.join(os.tmpdir(), 'angular-cli-e2e-home-'));
400+
const tempHome = await mktempd('angular-cli-e2e-home-');
401401

402402
try {
403403
await cb(tempHome);

tests/legacy-cli/e2e/utils/registry.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import { spawn } from 'child_process';
2-
import { mkdtempSync, realpathSync } from 'fs';
3-
import { tmpdir } from 'os';
42
import { join } from 'path';
53
import { getGlobalVariable } from './env';
64
import { writeFile, readFile } from './fs';
5+
import { mktempd } from './utils';
76

87
export async function createNpmRegistry(
98
port: number,
109
httpsPort: number,
1110
withAuthentication = false,
1211
) {
1312
// Setup local package registry
14-
const registryPath = mkdtempSync(join(realpathSync(tmpdir()), 'angular-cli-e2e-registry-'));
13+
const registryPath = await mktempd('angular-cli-e2e-registry-');
1514

1615
let configContent = await readFile(
1716
join(__dirname, '../../', withAuthentication ? 'verdaccio_auth.yaml' : 'verdaccio.yaml'),

tests/legacy-cli/e2e/utils/utils.ts

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import { mkdtemp, realpath } from 'fs/promises';
2+
import { tmpdir } from 'os';
3+
import path from 'path';
4+
15
export function expectToFail(fn: () => Promise<any>, errorMessage?: string): Promise<any> {
26
return fn().then(
37
() => {
@@ -18,3 +22,7 @@ export function wait(msecs: number): Promise<void> {
1822
setTimeout(resolve, msecs);
1923
});
2024
}
25+
26+
export async function mktempd(prefix: string): Promise<string> {
27+
return realpath(await mkdtemp(path.join(tmpdir(), prefix)));
28+
}

0 commit comments

Comments
 (0)