Skip to content
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
16 changes: 8 additions & 8 deletions src/editor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('editor', () => {
it('returns information about the editor from EDITOR if it resolves to an executable', async () => {
jest
.spyOn(envModule, 'getEnvironmentVariables')
.mockReturnValue({ EDITOR: 'editor', TODAY: undefined });
.mockReturnValue({ EDITOR: 'editor' });
when(jest.spyOn(miscUtils, 'resolveExecutable'))
.calledWith('editor')
.mockResolvedValue('/path/to/resolved-editor');
Expand All @@ -25,7 +25,7 @@ describe('editor', () => {
it('falls back to VSCode if it exists and if EDITOR does not point to an executable', async () => {
jest
.spyOn(envModule, 'getEnvironmentVariables')
.mockReturnValue({ EDITOR: 'editor', TODAY: undefined });
.mockReturnValue({ EDITOR: 'editor' });
when(jest.spyOn(miscUtils, 'resolveExecutable'))
.calledWith('editor')
.mockResolvedValue(null)
Expand All @@ -41,7 +41,7 @@ describe('editor', () => {
it('returns null if resolving EDITOR returns null and resolving VSCode returns null', async () => {
jest
.spyOn(envModule, 'getEnvironmentVariables')
.mockReturnValue({ EDITOR: 'editor', TODAY: undefined });
.mockReturnValue({ EDITOR: 'editor' });
when(jest.spyOn(miscUtils, 'resolveExecutable'))
.calledWith('editor')
.mockResolvedValue(null)
Expand All @@ -54,7 +54,7 @@ describe('editor', () => {
it('returns null if resolving EDITOR returns null and resolving VSCode throws', async () => {
jest
.spyOn(envModule, 'getEnvironmentVariables')
.mockReturnValue({ EDITOR: 'editor', TODAY: undefined });
.mockReturnValue({ EDITOR: 'editor' });
when(jest.spyOn(miscUtils, 'resolveExecutable'))
.calledWith('editor')
.mockResolvedValue(null)
Expand All @@ -67,7 +67,7 @@ describe('editor', () => {
it('returns null if resolving EDITOR throws and resolving VSCode returns null', async () => {
jest
.spyOn(envModule, 'getEnvironmentVariables')
.mockReturnValue({ EDITOR: 'editor', TODAY: undefined });
.mockReturnValue({ EDITOR: 'editor' });
when(jest.spyOn(miscUtils, 'resolveExecutable'))
.calledWith('editor')
.mockRejectedValue(new Error('some error'))
Expand All @@ -80,7 +80,7 @@ describe('editor', () => {
it('returns null if resolving EDITOR throws and resolving VSCode throws', async () => {
jest
.spyOn(envModule, 'getEnvironmentVariables')
.mockReturnValue({ EDITOR: 'editor', TODAY: undefined });
.mockReturnValue({ EDITOR: 'editor' });
when(jest.spyOn(miscUtils, 'resolveExecutable'))
.calledWith('editor')
.mockRejectedValue(new Error('some error'))
Expand All @@ -93,7 +93,7 @@ describe('editor', () => {
it('returns null if EDITOR is unset and resolving VSCode returns null', async () => {
jest
.spyOn(envModule, 'getEnvironmentVariables')
.mockReturnValue({ EDITOR: undefined, TODAY: undefined });
.mockReturnValue({ EDITOR: undefined });
when(jest.spyOn(miscUtils, 'resolveExecutable'))
.calledWith('code')
.mockResolvedValue(null);
Expand All @@ -104,7 +104,7 @@ describe('editor', () => {
it('returns null if EDITOR is unset and resolving VSCode throws', async () => {
jest
.spyOn(envModule, 'getEnvironmentVariables')
.mockReturnValue({ EDITOR: undefined, TODAY: undefined });
.mockReturnValue({ EDITOR: undefined });
when(jest.spyOn(miscUtils, 'resolveExecutable'))
.calledWith('code')
.mockRejectedValue(new Error('some error'));
Expand Down
2 changes: 0 additions & 2 deletions src/env.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ describe('env', () => {

it('returns only the environment variables from process.env that we use in this tool', () => {
process.env.EDITOR = 'editor';
process.env.TODAY = 'today';
process.env.EXTRA = 'extra';

expect(getEnvironmentVariables()).toStrictEqual({
EDITOR: 'editor',
TODAY: 'today',
});
});
});
Expand Down
3 changes: 1 addition & 2 deletions src/env.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
interface Env {
EDITOR: string | undefined;
TODAY: string | undefined;
}

/**
Expand All @@ -10,7 +9,7 @@ interface Env {
* this tool needs to access, whether their values are defined or not.
*/
export function getEnvironmentVariables(): Env {
return ['EDITOR', 'TODAY'].reduce((object, key) => {
return ['EDITOR'].reduce((object, key) => {
return { ...object, [key]: process.env[key] };
}, {} as Env);
}
18 changes: 8 additions & 10 deletions src/functional.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('create-release-branch (functional)', () => {
packages: {
$root$: {
name: '@scope/monorepo',
version: '2022.1.1',
version: '1.0.0',
directoryPath: '.',
},
a: {
Expand Down Expand Up @@ -41,7 +41,6 @@ describe('create-release-branch (functional)', () => {
workspaces: {
'.': ['packages/*'],
},
today: new Date('2022-06-24'),
},
async (environment) => {
await environment.updateJsonFile('package.json', {
Expand Down Expand Up @@ -88,7 +87,7 @@ describe('create-release-branch (functional)', () => {

expect(await environment.readJsonFile('package.json')).toStrictEqual({
name: '@scope/monorepo',
version: '2022.6.24',
version: '2.0.0',
private: true,
workspaces: ['packages/*'],
scripts: { foo: 'bar' },
Expand Down Expand Up @@ -138,7 +137,7 @@ describe('create-release-branch (functional)', () => {
packages: {
$root$: {
name: '@scope/monorepo',
version: '2022.1.1',
version: '1.0.0',
directoryPath: '.',
},
a: {
Expand Down Expand Up @@ -238,7 +237,7 @@ describe('create-release-branch (functional)', () => {
packages: {
$root$: {
name: '@scope/monorepo',
version: '2022.1.1',
version: '1.0.0',
directoryPath: '.',
},
a: {
Expand All @@ -250,7 +249,6 @@ describe('create-release-branch (functional)', () => {
workspaces: {
'.': ['packages/*'],
},
today: new Date('2022-06-24'),
},
async (environment) => {
await environment.runTool({
Expand All @@ -262,9 +260,9 @@ describe('create-release-branch (functional)', () => {
});

// Tests four things:
// * The latest commit should be called "Release YYYY-MM-DD"
// * The latest commit should be called "Release 1.0.0"
// * The latest commit should be the current commit (HEAD)
// * The latest branch should be called "release/YYYY-MM-DD"
// * The latest branch should be called "release/1.0.0"
// * The latest branch should point to the latest commit
const [latestCommitSubject, latestCommitId, latestCommitRevsMarker] =
(
Expand All @@ -284,9 +282,9 @@ describe('create-release-branch (functional)', () => {
'--max-count=1',
])
).stdout;
expect(latestCommitSubject).toStrictEqual('Release 2022-06-24');
expect(latestCommitSubject).toStrictEqual('Release 2.0.0');
expect(latestCommitRevs).toContain('HEAD');
expect(latestCommitRevs).toContain('release/2022-06-24');
expect(latestCommitRevs).toContain('release/2.0.0');
expect(latestBranchCommitId).toStrictEqual(latestCommitId);
},
);
Expand Down
35 changes: 15 additions & 20 deletions src/initial-parameters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('initial-parameters', () => {
});
jest
.spyOn(envModule, 'getEnvironmentVariables')
.mockReturnValue({ TODAY: '2022-06-22', EDITOR: undefined });
.mockReturnValue({ EDITOR: undefined });
when(jest.spyOn(projectModule, 'readProject'))
.calledWith('/path/to/project')
.mockResolvedValue(project);
Expand All @@ -46,7 +46,6 @@ describe('initial-parameters', () => {
project,
tempDirectoryPath: '/path/to/temp',
reset: true,
today: new Date('2022-06-22'),
});
});

Expand All @@ -63,7 +62,7 @@ describe('initial-parameters', () => {
});
jest
.spyOn(envModule, 'getEnvironmentVariables')
.mockReturnValue({ TODAY: undefined, EDITOR: undefined });
.mockReturnValue({ EDITOR: undefined });
const readProjectSpy = jest
.spyOn(projectModule, 'readProject')
.mockResolvedValue(project);
Expand All @@ -84,7 +83,7 @@ describe('initial-parameters', () => {
});
jest
.spyOn(envModule, 'getEnvironmentVariables')
.mockReturnValue({ TODAY: undefined, EDITOR: undefined });
.mockReturnValue({ EDITOR: undefined });
when(jest.spyOn(projectModule, 'readProject'))
.calledWith('/path/to/project')
.mockResolvedValue(project);
Expand All @@ -110,7 +109,7 @@ describe('initial-parameters', () => {
});
jest
.spyOn(envModule, 'getEnvironmentVariables')
.mockReturnValue({ TODAY: undefined, EDITOR: undefined });
.mockReturnValue({ EDITOR: undefined });
when(jest.spyOn(projectModule, 'readProject'))
.calledWith('/path/to/project')
.mockResolvedValue(project);
Expand All @@ -125,56 +124,52 @@ describe('initial-parameters', () => {
);
});

it('uses the current date if the TODAY environment variable was not provided', async () => {
it('returns initial parameters including reset: true, derived from a command-line argument of "--reset true"', async () => {
const project = buildMockProject();
const today = new Date('2022-01-01');
when(jest.spyOn(commandLineArgumentsModule, 'readCommandLineArguments'))
.calledWith(['arg1', 'arg2'])
.mockResolvedValue({
projectDirectory: '/path/to/project',
tempDirectory: undefined,
tempDirectory: '/path/to/temp',
reset: true,
});
jest
.spyOn(envModule, 'getEnvironmentVariables')
.mockReturnValue({ TODAY: undefined, EDITOR: undefined });
.mockReturnValue({ EDITOR: undefined });
when(jest.spyOn(projectModule, 'readProject'))
.calledWith('/path/to/project')
.mockResolvedValue(project);
jest.setSystemTime(today);

const config = await determineInitialParameters(
['arg1', 'arg2'],
'/path/to/cwd',
'/path/to/somewhere',
);

expect(config.today).toStrictEqual(today);
expect(config.reset).toBe(true);
});

it('uses the current date if TODAY is not a parsable date', async () => {
it('returns initial parameters including reset: false, derived from a command-line argument of "--reset false"', async () => {
const project = buildMockProject();
const today = new Date('2022-01-01');
when(jest.spyOn(commandLineArgumentsModule, 'readCommandLineArguments'))
.calledWith(['arg1', 'arg2'])
.mockResolvedValue({
projectDirectory: '/path/to/project',
tempDirectory: undefined,
reset: true,
tempDirectory: '/path/to/temp',
reset: false,
});
jest
.spyOn(envModule, 'getEnvironmentVariables')
.mockReturnValue({ TODAY: 'asdfgdasf', EDITOR: undefined });
.mockReturnValue({ EDITOR: undefined });
when(jest.spyOn(projectModule, 'readProject'))
.calledWith('/path/to/project')
.mockResolvedValue(project);
jest.setSystemTime(today);

const config = await determineInitialParameters(
['arg1', 'arg2'],
'/path/to/cwd',
'/path/to/somewhere',
);

expect(config.today).toStrictEqual(today);
expect(config.reset).toBe(false);
});
});
});
10 changes: 1 addition & 9 deletions src/initial-parameters.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import os from 'os';
import path from 'path';
import { getEnvironmentVariables } from './env';
import { readCommandLineArguments } from './command-line-arguments';
import { readProject, Project } from './project';

interface InitialParameters {
project: Project;
tempDirectoryPath: string;
reset: boolean;
today: Date;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to read the date from TODAY nor pass this down to anywhere, as a date isn't used anymore to calculate the version string. So it gets removed from everywhere.

}

/**
Expand All @@ -24,7 +22,6 @@ export async function determineInitialParameters(
cwd: string,
): Promise<InitialParameters> {
const inputs = await readCommandLineArguments(argv);
const { TODAY } = getEnvironmentVariables();

const projectDirectoryPath = path.resolve(cwd, inputs.projectDirectory);
const project = await readProject(projectDirectoryPath);
Expand All @@ -36,11 +33,6 @@ export async function determineInitialParameters(
project.rootPackage.validatedManifest.name.replace('/', '__'),
)
: path.resolve(cwd, inputs.tempDirectory);
const parsedTodayTimestamp =
TODAY === undefined ? NaN : new Date(TODAY).getTime();
const today = isNaN(parsedTodayTimestamp)
? new Date()
: new Date(parsedTodayTimestamp);

return { project, tempDirectoryPath, reset: inputs.reset, today };
return { project, tempDirectoryPath, reset: inputs.reset };
}
5 changes: 0 additions & 5 deletions src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ jest.mock('./monorepo-workflow-operations');
describe('main', () => {
it('executes the monorepo workflow if the project is a monorepo', async () => {
const project = buildMockProject({ isMonorepo: true });
const today = new Date();
const stdout = fs.createWriteStream('/dev/null');
const stderr = fs.createWriteStream('/dev/null');
jest
Expand All @@ -19,7 +18,6 @@ describe('main', () => {
project,
tempDirectoryPath: '/path/to/temp/directory',
reset: false,
today,
});
const followMonorepoWorkflowSpy = jest
.spyOn(monorepoWorkflowOperations, 'followMonorepoWorkflow')
Expand All @@ -36,15 +34,13 @@ describe('main', () => {
project,
tempDirectoryPath: '/path/to/temp/directory',
firstRemovingExistingReleaseSpecification: false,
today,
stdout,
stderr,
});
});

it('executes the polyrepo workflow if the project is within a polyrepo', async () => {
const project = buildMockProject({ isMonorepo: false });
const today = new Date();
const stdout = fs.createWriteStream('/dev/null');
const stderr = fs.createWriteStream('/dev/null');
jest
Expand All @@ -53,7 +49,6 @@ describe('main', () => {
project,
tempDirectoryPath: '/path/to/temp/directory',
reset: false,
today,
});
const followMonorepoWorkflowSpy = jest
.spyOn(monorepoWorkflowOperations, 'followMonorepoWorkflow')
Expand Down
3 changes: 1 addition & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function main({
stdout: Pick<WriteStream, 'write'>;
stderr: Pick<WriteStream, 'write'>;
}) {
const { project, tempDirectoryPath, reset, today } =
const { project, tempDirectoryPath, reset } =
await determineInitialParameters(argv, cwd);

if (project.isMonorepo) {
Expand All @@ -36,7 +36,6 @@ export async function main({
project,
tempDirectoryPath,
firstRemovingExistingReleaseSpecification: reset,
today,
stdout,
stderr,
});
Expand Down
Loading