Skip to content

Commit 693cf2b

Browse files
authored
Merge pull request #3220 from iclanton/clean-up-tests
Improve refactorability of tests and remove some superfluous path.* operations.
2 parents b33ffb5 + c04796b commit 693cf2b

File tree

97 files changed

+597
-414
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+597
-414
lines changed

apps/api-extractor/src/analyzer/test/PackageMetadataManager.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ function firstArgument(mockFn: jest.Mock): any {
3030

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

33-
describe('PackageMetadataManager', () => {
34-
describe('.writeTsdocMetadataFile()', () => {
33+
describe(PackageMetadataManager.name, () => {
34+
describe(PackageMetadataManager.writeTsdocMetadataFile.name, () => {
3535
const originalWriteFile = FileSystem.writeFile;
3636
const mockWriteFile: jest.Mock = jest.fn();
3737
beforeAll(() => {
@@ -50,7 +50,7 @@ describe('PackageMetadataManager', () => {
5050
});
5151
});
5252

53-
describe('.resolveTsdocMetadataPath()', () => {
53+
describe(PackageMetadataManager.resolveTsdocMetadataPath.name, () => {
5454
describe('when an empty tsdocMetadataPath is provided', () => {
5555
const tsdocMetadataPath: string = '';
5656
describe('given a package.json where the field "tsdocMetadata" is defined', () => {

apps/api-extractor/src/analyzer/test/SyntaxHelpers.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

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

6-
describe('SyntaxHelpers', () => {
7-
test('.toAlphaNumericCamelCase()', () => {
6+
describe(SyntaxHelpers.name, () => {
7+
it(SyntaxHelpers.makeCamelCaseIdentifier.name, () => {
88
// prettier-ignore
99
const inputs:string[] = [
1010
'',

apps/api-extractor/src/api/test/ExtractorConfig-lookup.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function expectEqualPaths(path1: string, path2: string): void {
1515
}
1616

1717
// Tests for expanding the "<lookup>" token for the "projectFolder" setting in api-extractor.json
18-
describe('ExtractorConfig-lookup', () => {
18+
describe(`${ExtractorConfig.name}.${ExtractorConfig.loadFileAndPrepare.name}`, () => {
1919
it.only('config-lookup1: looks up ./api-extractor.json', () => {
2020
const extractorConfig: ExtractorConfig = ExtractorConfig.loadFileAndPrepare(
2121
path.join(testDataFolder, 'config-lookup1/api-extractor.json')

apps/heft/src/pluginFramework/logging/test/FileError.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

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

6-
describe('FileError', () => {
6+
describe(FileError.name, () => {
77
it('normalizes slashes in file paths', () => {
88
const error1: FileError = new FileError('message', 'path\\to\\file', 0);
99
expect(error1.filePath).toEqual('path/to/file');

apps/heft/src/utilities/subprocess/test/SubprocessRunnerBase.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { SubprocessRunnerBase } from '../SubprocessRunnerBase';
55
import { FileError } from '../../../pluginFramework/logging/FileError';
66

7-
describe('SubprocessRunnerBase', () => {
7+
describe(SubprocessRunnerBase.name, () => {
88
it(`${SubprocessRunnerBase.serializeForIpcMessage.name} correctly serializes objects`, () => {
99
expect(SubprocessRunnerBase.serializeForIpcMessage(1)).toMatchSnapshot();
1010
expect(SubprocessRunnerBase.serializeForIpcMessage(false)).toMatchSnapshot();

apps/rush-lib/src/api/test/ChangeFile.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4-
import * as path from 'path';
5-
64
import { ChangeFile } from '../ChangeFile';
75
import { RushConfiguration } from '../RushConfiguration';
86
import { ChangeType } from '../ChangeManagement';
97

10-
describe('ChangeFile', () => {
8+
describe(ChangeFile.name, () => {
119
it('can add a change', () => {
12-
const rushFilename: string = path.resolve(__dirname, 'repo', 'rush-npm.json');
10+
const rushFilename: string = `${__dirname}/repo/rush-npm.json`;
1311
const rushConfiguration: RushConfiguration = RushConfiguration.loadFromConfigurationFile(rushFilename);
1412

1513
const changeFile: ChangeFile = new ChangeFile(

apps/rush-lib/src/api/test/CommonVersionsConfiguration.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4-
import * as path from 'path';
5-
64
import { CommonVersionsConfiguration } from '../CommonVersionsConfiguration';
75

8-
describe('CommonVersionsConfiguration', () => {
6+
describe(CommonVersionsConfiguration.name, () => {
97
it('can load the file', () => {
10-
const filename: string = path.resolve(__dirname, 'jsonFiles', 'common-versions.json');
8+
const filename: string = `${__dirname}/jsonFiles/common-versions.json`;
119
const configuration: CommonVersionsConfiguration = CommonVersionsConfiguration.loadFromFile(filename);
1210

1311
expect(configuration.preferredVersions.get('@scope/library-1')).toEqual('~3.2.1');

apps/rush-lib/src/api/test/EnvironmentConfiguration.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import * as path from 'path';
55
import { EnvironmentConfiguration } from '../EnvironmentConfiguration';
66

7-
describe('EnvironmentConfiguration', () => {
7+
describe(EnvironmentConfiguration.name, () => {
88
let _oldEnv: typeof process.env;
99

1010
beforeEach(() => {
@@ -17,7 +17,7 @@ describe('EnvironmentConfiguration', () => {
1717
process.env = _oldEnv;
1818
});
1919

20-
describe('validate', () => {
20+
describe(EnvironmentConfiguration.validate.name, () => {
2121
it('correctly allows no environment variables', () => {
2222
expect(EnvironmentConfiguration.validate).not.toThrow();
2323
});
@@ -99,7 +99,7 @@ describe('EnvironmentConfiguration', () => {
9999
});
100100

101101
it('returns expected path from environment variable with normalization', () => {
102-
const expectedValue: string = path.resolve(path.join(process.cwd(), 'temp'));
102+
const expectedValue: string = path.resolve(process.cwd(), 'temp');
103103
const envVar: string = './temp';
104104
process.env[ENV_VAR] = envVar;
105105

apps/rush-lib/src/api/test/EventHooks.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4-
import * as path from 'path';
54
import { RushConfiguration } from '../RushConfiguration';
65
import { Event, EventHooks } from '../EventHooks';
76

8-
describe('EventHooks', () => {
7+
describe(EventHooks.name, () => {
98
it('loads a post build hook from rush.json', () => {
10-
const rushFilename: string = path.resolve(__dirname, 'repo', 'rush-npm.json');
9+
const rushFilename: string = `${__dirname}/repo/rush-npm.json`;
1110
const rushConfiguration: RushConfiguration = RushConfiguration.loadFromConfigurationFile(rushFilename);
1211
expect(rushConfiguration.eventHooks.get(Event.postRushBuild)).toEqual(['do something']);
1312
});

apps/rush-lib/src/api/test/LastInstallFlag.test.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4-
import * as path from 'path';
4+
import { FileSystem } from '@rushstack/node-core-library';
55

66
import { LastInstallFlag } from '../LastInstallFlag';
7-
import { FileSystem } from '@rushstack/node-core-library';
87

9-
const TEMP_DIR: string = path.join(__dirname, 'temp');
8+
const TEMP_DIR_PATH: string = `${__dirname}/temp`;
109

11-
describe('LastInstallFlag', () => {
10+
describe(LastInstallFlag.name, () => {
1211
beforeEach(() => {
13-
FileSystem.ensureEmptyFolder(TEMP_DIR);
12+
FileSystem.ensureEmptyFolder(TEMP_DIR_PATH);
1413
});
1514

1615
afterEach(() => {
17-
FileSystem.ensureEmptyFolder(TEMP_DIR);
16+
FileSystem.ensureEmptyFolder(TEMP_DIR_PATH);
1817
});
1918

2019
it('can create and remove a flag in an empty directory', () => {
2120
// preparation
22-
const flag: LastInstallFlag = new LastInstallFlag(TEMP_DIR);
21+
const flag: LastInstallFlag = new LastInstallFlag(TEMP_DIR_PATH);
2322
FileSystem.deleteFile(flag.path);
2423

2524
// test state, should be invalid since the file doesn't exist
@@ -38,8 +37,8 @@ describe('LastInstallFlag', () => {
3837

3938
it('can detect if the last flag was in a different state', () => {
4039
// preparation
41-
const flag1: LastInstallFlag = new LastInstallFlag(TEMP_DIR, { node: '5.0.0' });
42-
const flag2: LastInstallFlag = new LastInstallFlag(TEMP_DIR, { node: '8.9.4' });
40+
const flag1: LastInstallFlag = new LastInstallFlag(TEMP_DIR_PATH, { node: '5.0.0' });
41+
const flag2: LastInstallFlag = new LastInstallFlag(TEMP_DIR_PATH, { node: '8.9.4' });
4342
FileSystem.deleteFile(flag1.path);
4443

4544
// test state, should be invalid since the file doesn't exist
@@ -63,7 +62,7 @@ describe('LastInstallFlag', () => {
6362

6463
it('can detect if the last flag was in a corrupted state', () => {
6564
// preparation, write non-json into flag file
66-
const flag: LastInstallFlag = new LastInstallFlag(TEMP_DIR);
65+
const flag: LastInstallFlag = new LastInstallFlag(TEMP_DIR_PATH);
6766
FileSystem.writeFile(flag.path, 'sdfjkaklfjksldajgfkld');
6867

6968
// test state, should be invalid since the file is not JSON
@@ -72,13 +71,13 @@ describe('LastInstallFlag', () => {
7271
});
7372

7473
it("throws an error if new storePath doesn't match the old one", () => {
75-
const flag1: LastInstallFlag = new LastInstallFlag(TEMP_DIR, {
74+
const flag1: LastInstallFlag = new LastInstallFlag(TEMP_DIR_PATH, {
7675
packageManager: 'pnpm',
77-
storePath: path.join(TEMP_DIR, 'pnpm-store')
76+
storePath: `${TEMP_DIR_PATH}/pnpm-store`
7877
});
79-
const flag2: LastInstallFlag = new LastInstallFlag(TEMP_DIR, {
78+
const flag2: LastInstallFlag = new LastInstallFlag(TEMP_DIR_PATH, {
8079
packageManager: 'pnpm',
81-
storePath: path.join(TEMP_DIR, 'temp-store')
80+
storePath: `${TEMP_DIR_PATH}/temp-store`
8281
});
8382

8483
flag1.create();
@@ -88,11 +87,11 @@ describe('LastInstallFlag', () => {
8887
});
8988

9089
it("doesn't throw an error if conditions for error aren't met", () => {
91-
const flag1: LastInstallFlag = new LastInstallFlag(TEMP_DIR, {
90+
const flag1: LastInstallFlag = new LastInstallFlag(TEMP_DIR_PATH, {
9291
packageManager: 'pnpm',
93-
storePath: path.join(TEMP_DIR, 'pnpm-store')
92+
storePath: `${TEMP_DIR_PATH}/pnpm-store`
9493
});
95-
const flag2: LastInstallFlag = new LastInstallFlag(TEMP_DIR, {
94+
const flag2: LastInstallFlag = new LastInstallFlag(TEMP_DIR_PATH, {
9695
packageManager: 'npm'
9796
});
9897

0 commit comments

Comments
 (0)