Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: move tempdir creation to util method #23649

Merged
merged 1 commit into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions tests/legacy-cli/e2e/setup/001-create-tmp-dir.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -448,7 +449,7 @@ async function windowsTests(): Promise<void> {
}

async function mockHome(cb: (home: string) => Promise<void>): Promise<void> {
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);
Expand Down
4 changes: 2 additions & 2 deletions tests/legacy-cli/e2e/tests/commands/completion/completion.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -397,7 +397,7 @@ async function windowsTests(): Promise<void> {
}

async function mockHome(cb: (home: string) => Promise<void>): Promise<void> {
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);
Expand Down
5 changes: 2 additions & 3 deletions tests/legacy-cli/e2e/utils/registry.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
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,
httpsPort: number,
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'),
Expand Down
8 changes: 8 additions & 0 deletions tests/legacy-cli/e2e/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { mkdtemp, realpath } from 'fs/promises';
import { tmpdir } from 'os';
import path from 'path';

export function expectToFail(fn: () => Promise<any>, errorMessage?: string): Promise<any> {
return fn().then(
() => {
Expand All @@ -18,3 +22,7 @@ export function wait(msecs: number): Promise<void> {
setTimeout(resolve, msecs);
});
}

export async function mktempd(prefix: string): Promise<string> {
return realpath(await mkdtemp(path.join(tmpdir(), prefix)));
}