Skip to content

Commit

Permalink
Improve refactorability of other projects' tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
iclanton committed Feb 14, 2022
1 parent 379a48c commit 56278ee
Show file tree
Hide file tree
Showing 53 changed files with 226 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ function firstArgument(mockFn: jest.Mock): any {

/* eslint-disable @typescript-eslint/typedef */

describe('PackageMetadataManager', () => {
describe('.writeTsdocMetadataFile()', () => {
describe(PackageMetadataManager.name, () => {
describe(PackageMetadataManager.writeTsdocMetadataFile.name, () => {
const originalWriteFile = FileSystem.writeFile;
const mockWriteFile: jest.Mock = jest.fn();
beforeAll(() => {
Expand All @@ -50,7 +50,7 @@ describe('PackageMetadataManager', () => {
});
});

describe('.resolveTsdocMetadataPath()', () => {
describe(PackageMetadataManager.resolveTsdocMetadataPath.name, () => {
describe('when an empty tsdocMetadataPath is provided', () => {
const tsdocMetadataPath: string = '';
describe('given a package.json where the field "tsdocMetadata" is defined', () => {
Expand Down
4 changes: 2 additions & 2 deletions apps/api-extractor/src/analyzer/test/SyntaxHelpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import { SyntaxHelpers } from '../SyntaxHelpers';

describe('SyntaxHelpers', () => {
test('.toAlphaNumericCamelCase()', () => {
describe(SyntaxHelpers.name, () => {
it(SyntaxHelpers.makeCamelCaseIdentifier.name, () => {
// prettier-ignore
const inputs:string[] = [
'',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function expectEqualPaths(path1: string, path2: string): void {
}

// Tests for expanding the "<lookup>" token for the "projectFolder" setting in api-extractor.json
describe('ExtractorConfig-lookup', () => {
describe(`${ExtractorConfig.name}.${ExtractorConfig.loadFileAndPrepare.name}`, () => {
it.only('config-lookup1: looks up ./api-extractor.json', () => {
const extractorConfig: ExtractorConfig = ExtractorConfig.loadFileAndPrepare(
path.join(testDataFolder, 'config-lookup1/api-extractor.json')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { FileError, FileErrorFormat } from '../FileError';

describe('FileError', () => {
describe(FileError.name, () => {
it('normalizes slashes in file paths', () => {
const error1: FileError = new FileError('message', 'path\\to\\file', 0);
expect(error1.filePath).toEqual('path/to/file');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { SubprocessRunnerBase } from '../SubprocessRunnerBase';
import { FileError } from '../../../pluginFramework/logging/FileError';

describe('SubprocessRunnerBase', () => {
describe(SubprocessRunnerBase.name, () => {
it(`${SubprocessRunnerBase.serializeForIpcMessage.name} correctly serializes objects`, () => {
expect(SubprocessRunnerBase.serializeForIpcMessage(1)).toMatchSnapshot();
expect(SubprocessRunnerBase.serializeForIpcMessage(false)).toMatchSnapshot();
Expand Down
6 changes: 3 additions & 3 deletions apps/rush-lib/src/cli/actions/test/AddAction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { RushCommandLineParser } from '../../RushCommandLineParser';
import { AddAction } from '../AddAction';

describe(AddAction.name, () => {
describe(`basic "rush add" tests`, () => {
describe('basic "rush add" tests', () => {
let doRushAddMock: jest.SpyInstance;
let oldExitCode: number | undefined;
let oldArgs: string[];
Expand All @@ -28,7 +28,7 @@ describe(AddAction.name, () => {
process.argv = oldArgs;
});

describe(`'add' action`, () => {
describe("'add' action", () => {
it(`adds a dependency to just one repo in the workspace`, async () => {
const startPath: string = `${__dirname}/addRepo`;
const aPath: string = `${__dirname}/addRepo/a`;
Expand All @@ -53,7 +53,7 @@ describe(AddAction.name, () => {
});
});

describe(`'add' action with --all`, () => {
describe("'add' action with --all", () => {
it(`adds a dependency to all repos in the workspace`, async () => {
const startPath: string = `${__dirname}/addRepo`;
const aPath: string = `${__dirname}/addRepo/a`;
Expand Down
24 changes: 12 additions & 12 deletions apps/rush-lib/src/cli/test/RushCommandLineParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe(RushCommandLineParser.name, () => {
});

describe('in basic repo', () => {
describe(`'build' action`, () => {
describe("'build' action", () => {
it(`executes the package's 'build' script`, async () => {
const repoName: string = 'basicAndRunBuildActionRepo';
const instance: IParserTestInstance = getCommandLineParserInstance(repoName, 'build');
Expand Down Expand Up @@ -124,7 +124,7 @@ describe(RushCommandLineParser.name, () => {
});
});

describe(`'rebuild' action`, () => {
describe("'rebuild' action", () => {
it(`executes the package's 'build' script`, async () => {
const repoName: string = 'basicAndRunRebuildActionRepo';
const instance: IParserTestInstance = getCommandLineParserInstance(repoName, 'rebuild');
Expand Down Expand Up @@ -157,8 +157,8 @@ describe(RushCommandLineParser.name, () => {
});
});

describe(`in repo with 'rebuild' command overridden`, () => {
describe(`'build' action`, () => {
describe("in repo with 'rebuild' command overridden", () => {
describe("'build' action", () => {
it(`executes the package's 'build' script`, async () => {
const repoName: string = 'overrideRebuildAndRunBuildActionRepo';
const instance: IParserTestInstance = getCommandLineParserInstance(repoName, 'build');
Expand Down Expand Up @@ -190,7 +190,7 @@ describe(RushCommandLineParser.name, () => {
});
});

describe(`'rebuild' action`, () => {
describe("'rebuild' action", () => {
it(`executes the package's 'rebuild' script`, async () => {
const repoName: string = 'overrideRebuildAndRunRebuildActionRepo';
const instance: IParserTestInstance = getCommandLineParserInstance(repoName, 'rebuild');
Expand Down Expand Up @@ -223,8 +223,8 @@ describe(RushCommandLineParser.name, () => {
});
});

describe(`in repo with 'rebuild' or 'build' partially set`, () => {
describe(`'build' action`, () => {
describe("in repo with 'rebuild' or 'build' partially set", () => {
describe("'build' action", () => {
it(`executes the package's 'build' script`, async () => {
const repoName: string = 'overrideAndDefaultBuildActionRepo';
const instance: IParserTestInstance = getCommandLineParserInstance(repoName, 'build');
Expand Down Expand Up @@ -255,7 +255,7 @@ describe(RushCommandLineParser.name, () => {
});
});

describe(`'rebuild' action`, () => {
describe("'rebuild' action", () => {
it(`executes the package's 'build' script`, async () => {
// broken
const repoName: string = 'overrideAndDefaultRebuildActionRepo';
Expand Down Expand Up @@ -288,7 +288,7 @@ describe(RushCommandLineParser.name, () => {
});
});

describe(`in repo with 'build' command overridden as a global command`, () => {
describe("in repo with 'build' command overridden as a global command", () => {
it(`throws an error when starting Rush`, async () => {
const repoName: string = 'overrideBuildAsGlobalCommandRepo';

Expand All @@ -300,7 +300,7 @@ describe(RushCommandLineParser.name, () => {
});
});

describe(`in repo with 'rebuild' command overridden as a global command`, () => {
describe("in repo with 'rebuild' command overridden as a global command", () => {
it(`throws an error when starting Rush`, async () => {
const repoName: string = 'overrideRebuildAsGlobalCommandRepo';

Expand All @@ -312,7 +312,7 @@ describe(RushCommandLineParser.name, () => {
});
});

describe(`in repo with 'build' command overridden with 'safeForSimultaneousRushProcesses=true'`, () => {
describe("in repo with 'build' command overridden with 'safeForSimultaneousRushProcesses=true'", () => {
it(`throws an error when starting Rush`, async () => {
const repoName: string = 'overrideBuildWithSimultaneousProcessesRepo';

Expand All @@ -324,7 +324,7 @@ describe(RushCommandLineParser.name, () => {
});
});

describe(`in repo with 'rebuild' command overridden with 'safeForSimultaneousRushProcesses=true'`, () => {
describe("in repo with 'rebuild' command overridden with 'safeForSimultaneousRushProcesses=true'", () => {
it(`throws an error when starting Rush`, async () => {
const repoName: string = 'overrideRebuildWithSimultaneousProcessesRepo';

Expand Down
2 changes: 1 addition & 1 deletion apps/rush/src/test/MinimalRushConfiguration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as path from 'path';

import { MinimalRushConfiguration } from '../MinimalRushConfiguration';

describe('MinimalRushConfiguration', () => {
describe(MinimalRushConfiguration.name, () => {
afterEach(() => {
jest.restoreAllMocks();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { addThreeStars } from '..';

describe('addThreeStars', () => {
describe(addThreeStars.name, () => {
it('adds three stars', () => {
expect(addThreeStars('***Hello World')).toEqual('***Hello World***');
});
Expand Down
2 changes: 1 addition & 1 deletion eslint/eslint-plugin-packlets/src/test/Path.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function relativeCaseInsensitive(from: string, to: string) {
return toPosixPath(Path['_relativeCaseInsensitive'](toNativePath(from), toNativePath(to)));
}

describe('Path', () => {
describe(Path.name, () => {
test('_detectCaseSensitive()', () => {
// NOTE: To ensure these tests are deterministic, only use absolute paths
expect(relativeCaseInsensitive('/', '/')).toEqual('');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from '@rushstack/node-core-library';
import { RigConfig } from '@rushstack/rig-package';

describe('ConfigurationFile', () => {
describe(ConfigurationFile.name, () => {
const projectRoot: string = nodeJsPath.resolve(__dirname, '..', '..');
let terminalProvider: StringBufferTerminalProvider;
let terminal: Terminal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import * as colors from 'colors';
import { AnsiEscape } from '../AnsiEscape';

describe('AnsiEscape', () => {
describe(AnsiEscape.name, () => {
let initialColorsEnabled: boolean;

beforeAll(() => {
Expand Down
3 changes: 2 additions & 1 deletion libraries/node-core-library/src/Terminal/test/Colors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { Terminal } from '../Terminal';
import { StringBufferTerminalProvider } from '../StringBufferTerminalProvider';
import { createColorGrid } from './createColorGrid';
import { AnsiEscape } from '../AnsiEscape';
import { Colors } from '../Colors';

describe('Colors', () => {
describe(Colors.name, () => {
let terminal: Terminal;
let provider: StringBufferTerminalProvider;

Expand Down
6 changes: 3 additions & 3 deletions libraries/node-core-library/src/test/Async.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import { Async } from '../Async';

describe('Async', () => {
describe('mapAsync', () => {
describe(Async.name, () => {
describe(Async.mapAsync.name, () => {
it('handles an empty array correctly', async () => {
const result = await Async.mapAsync([] as number[], async (item) => `result ${item}`);
expect(result).toEqual([]);
Expand Down Expand Up @@ -128,7 +128,7 @@ describe('Async', () => {
});
});

describe('forEachAsync', () => {
describe(Async.forEachAsync.name, () => {
it('handles an empty array correctly', async () => {
let running: number = 0;
let maxRunning: number = 0;
Expand Down
2 changes: 1 addition & 1 deletion libraries/node-core-library/src/test/Enum.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ enum MixedEnum {
Banana = 'banana'
}

describe('Enum', () => {
describe(Enum.name, () => {
test('tryGetValueByKey', () => {
// NumericEnum
const numeric1: NumericEnum | undefined = Enum.tryGetValueByKey(NumericEnum, 'Apple');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import process from 'process';

import { EnvironmentMap } from '../EnvironmentMap';

describe('EnvironmentMap', () => {
describe(EnvironmentMap.name, () => {
test('_sanityCheck() throws', () => {
const map = new EnvironmentMap();
const environmentObject = { A: '123' };
Expand Down
6 changes: 3 additions & 3 deletions libraries/node-core-library/src/test/Import.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { Import } from '../Import';
import { PackageJsonLookup } from '../PackageJsonLookup';
import { Path } from '../Path';

describe('Import', () => {
describe(Import.name, () => {
const packageRoot: string = PackageJsonLookup.instance.tryGetPackageFolderFor(__dirname)!;

describe('resolveModule', () => {
describe(Import.resolveModule.name, () => {
it('returns an absolute path as-is', () => {
const absolutePaths: string[] = ['/var/test/path'];

Expand Down Expand Up @@ -135,7 +135,7 @@ describe('Import', () => {
});
});

describe('resolvePackage', () => {
describe(Import.resolvePackage.name, () => {
it('resolves a dependency', () => {
expect(
Import.resolvePackage({ packageName: '@rushstack/heft', baseFolderPath: __dirname }).replace(
Expand Down
2 changes: 1 addition & 1 deletion libraries/node-core-library/src/test/JsonFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { JsonFile } from '../JsonFile';
// The PosixModeBits are intended to be used with bitwise operations.
/* eslint-disable no-bitwise */

describe('JsonFile tests', () => {
describe(JsonFile.name, () => {
it('adds a header comment', () => {
expect(
JsonFile.stringify(
Expand Down
2 changes: 1 addition & 1 deletion libraries/node-core-library/src/test/JsonSchema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { JsonFile, JsonObject } from '../JsonFile';
import { JsonSchema, IJsonSchemaErrorInfo } from '../JsonSchema';

describe('JsonSchema', () => {
describe(JsonSchema.name, () => {
const schemaPath: string = `${__dirname}/test-data/test-schema.json`;
const schema: JsonSchema = JsonSchema.fromFile(schemaPath);

Expand Down
10 changes: 5 additions & 5 deletions libraries/node-core-library/src/test/LockFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ function setLockFileGetProcessStartTime(fn: (process: number) => string | undefi
(LockFile as any)._getStartTime = fn;
}

describe('LockFile', () => {
describe(LockFile.name, () => {
afterEach(() => {
setLockFileGetProcessStartTime(getProcessStartTime);
});

describe('getLockFilePath', () => {
describe(LockFile.getLockFilePath.name, () => {
test('only accepts alphabetical characters for resource name', () => {
expect(() => {
LockFile.getLockFilePath(process.cwd(), 'foo123');
Expand Down Expand Up @@ -49,7 +49,7 @@ describe('LockFile', () => {
});
});

describe('getProcessStartTimeFromProcStat', () => {
describe(getProcessStartTimeFromProcStat.name, () => {
function createStatOutput(value2: string, n: number): string {
let statOutput: string = `0 ${value2} S`;
for (let i: number = 0; i < n; i++) {
Expand Down Expand Up @@ -97,7 +97,7 @@ describe('LockFile', () => {

if (process.platform === 'darwin' || process.platform === 'linux') {
describe('Linux and Mac', () => {
describe('getLockFilePath()', () => {
describe(LockFile.getLockFilePath.name, () => {
test('returns a resolved path containing the pid', () => {
expect(path.join(process.cwd(), `test#${process.pid}.lock`)).toEqual(
LockFile.getLockFilePath('./', 'test')
Expand Down Expand Up @@ -171,7 +171,7 @@ describe('LockFile', () => {
}

if (process.platform === 'win32') {
describe('getLockFilePath()', () => {
describe(LockFile.getLockFilePath.name, () => {
test("returns a resolved path that doesn't contain", () => {
expect(path.join(process.cwd(), `test.lock`)).toEqual(LockFile.getLockFilePath('./', 'test'));
});
Expand Down
10 changes: 5 additions & 5 deletions libraries/node-core-library/src/test/PackageJsonLookup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { PackageJsonLookup } from '../PackageJsonLookup';
import { IPackageJson, INodePackageJson } from '../IPackageJson';
import { FileConstants } from '../Constants';

describe('PackageJsonLookup', () => {
describe(PackageJsonLookup.name, () => {
describe('basic tests', () => {
test('', () => {
test(PackageJsonLookup.loadOwnPackageJson.name, () => {
expect(PackageJsonLookup.loadOwnPackageJson(__dirname).name).toEqual('@rushstack/node-core-library');
});

test('tryLoadPackageJsonFor() test', () => {
test(PackageJsonLookup.prototype.tryLoadPackageJsonFor.name, () => {
const packageJsonLookup: PackageJsonLookup = new PackageJsonLookup();
const sourceFilePath: string = path.join(__dirname, './test-data/example-package');
const packageJson: IPackageJson | undefined = packageJsonLookup.tryLoadPackageJsonFor(sourceFilePath);
Expand All @@ -26,7 +26,7 @@ describe('PackageJsonLookup', () => {
}
});

test('tryLoadNodePackageJsonFor() test package with no version', () => {
test(`${PackageJsonLookup.prototype.tryLoadNodePackageJsonFor.name} test package with no version`, () => {
const packageJsonLookup: PackageJsonLookup = new PackageJsonLookup();
const sourceFilePath: string = path.join(__dirname, './test-data/example-package-no-version');
const packageJson: INodePackageJson | undefined =
Expand All @@ -41,7 +41,7 @@ describe('PackageJsonLookup', () => {
}
});

test('tryGetPackageFolderFor() test', () => {
test(PackageJsonLookup.prototype.tryGetPackageFolderFor.name, () => {
const packageJsonLookup: PackageJsonLookup = new PackageJsonLookup();
const sourceFilePath: string = path.join(__dirname, './test-data/example-package/src/ExampleFile.txt');

Expand Down
Loading

0 comments on commit 56278ee

Please sign in to comment.