Skip to content

Commit

Permalink
feat(config): migrate legacy config name to modern config name
Browse files Browse the repository at this point in the history
  • Loading branch information
travi committed Jul 23, 2024
1 parent bd6b9c1 commit c4e10c2
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import {lift, test as projectUsesRenovate, scaffold} from '@form8ion/renovate-sc
await scaffold({projectRoot: process.cwd()});

if (await projectUsesRenovate({projectRoot: process.cwd()})) {
await lift();
await lift({projectRoot: process.cwd()});
}
})();
```
Expand Down
2 changes: 1 addition & 1 deletion example.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ stubbedFs();
await scaffold({projectRoot: process.cwd()});

if (await projectUsesRenovate({projectRoot: process.cwd()})) {
await lift();
await lift({projectRoot: process.cwd()});
}
})();
1 change: 1 addition & 0 deletions src/config/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export {default as scaffold} from './scaffolder.js';
export {default as lift} from './lifter.js';
8 changes: 8 additions & 0 deletions src/config/lifter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {promises as fs} from 'node:fs';
import {fileExists} from '@form8ion/core';

export default async function ({projectRoot}) {
if (await fileExists(`${projectRoot}/renovate.json`)) {
await fs.rename(`${projectRoot}/renovate.json`, `${projectRoot}/.renovaterc.json`);
}
}
35 changes: 35 additions & 0 deletions src/config/lifter.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {promises as fs} from 'node:fs';
import {fileExists} from '@form8ion/core';

import any from '@travi/any';
import {when} from 'jest-when';
import {afterEach, describe, expect, it, vi} from 'vitest';

import liftConfig from './lifter.js';

vi.mock('node:fs');
vi.mock('@form8ion/core');

describe('config lifter', () => {
const projectRoot = any.string();

afterEach(() => {
vi.clearAllMocks();
});

it('should move legacy config to the modern filename', async () => {
when(fileExists).calledWith(`${projectRoot}/renovate.json`).mockResolvedValue(true);

await liftConfig({projectRoot});

expect(fs.rename).toHaveBeenCalledWith(`${projectRoot}/renovate.json`, `${projectRoot}/.renovaterc.json`);
});

it('should not attempt to move legacy config if none exists', async () => {
when(fileExists).calledWith(`${projectRoot}/renovate.json`).mockResolvedValue(false);

await liftConfig({projectRoot});

expect(fs.rename).not.toHaveBeenCalled();
});
});
5 changes: 4 additions & 1 deletion src/lift/lift.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import deepmerge from 'deepmerge';

import {scaffold as scaffoldBadges} from '../badges/index.js';
import {lift as liftConfig} from '../config/index.js';

export default async function ({projectRoot}) {
await liftConfig({projectRoot});

export default function () {
return deepmerge.all([
scaffoldBadges(),
{branchesToVerify: ['renovate/**']}
Expand Down
9 changes: 7 additions & 2 deletions src/lift/lift.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,29 @@ import {when} from 'jest-when';
import any from '@travi/any';

import {scaffold as scaffoldBadges} from '../badges/index.js';
import {lift as liftConfig} from '../config/index.js';
import lift from './lift.js';

vi.mock('deepmerge');
vi.mock('../badges');
vi.mock('../config/index.js');

describe('lift', () => {
afterEach(() => {
vi.clearAllMocks();
});

it('should define renovate branches as branches to verify', () => {
it('should define renovate branches as branches to verify', async () => {
const badgesResults = any.simpleObject();
const mergedResults = any.simpleObject();
const projectRoot = any.string();
scaffoldBadges.mockReturnValue(badgesResults);
when(deepmerge.all)
.calledWith([badgesResults, {branchesToVerify: ['renovate/**']}])
.mockReturnValue(mergedResults);

expect(lift()).toEqual(mergedResults);
expect(await lift({projectRoot})).toEqual(mergedResults);

expect(liftConfig).toHaveBeenCalledWith({projectRoot});
});
});
6 changes: 6 additions & 0 deletions test/integration/features/lift/config.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: Lift Config

Scenario: legacy config
Given the project uses a renovate config with the legacy filename
When the scaffolder results are processed
Then the project uses config with the modern filename
13 changes: 12 additions & 1 deletion test/integration/features/step_definitions/config-steps.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import {promises as fs} from 'node:fs';
import {fileExists} from '@form8ion/core';

import {Given} from '@cucumber/cucumber';
import assert from 'node:assert';
import {Given, Then} from '@cucumber/cucumber';
import any from '@travi/any';

Given('the project uses a renovate config with the modern filename', async function () {
await fs.writeFile(`${this.projectRoot}/.renovaterc.json`, JSON.stringify(any.simpleObject()));
});

Given('the project uses a renovate config with the legacy filename', async function () {
await fs.writeFile(`${this.projectRoot}/renovate.json`, JSON.stringify(any.simpleObject()));
});

Then('the project uses config with the modern filename', async function () {
assert.equal(await fileExists(`${this.projectRoot}/renovate.json`), false);
assert.equal(await fileExists(`${this.projectRoot}/.renovaterc.json`), true);
});

0 comments on commit c4e10c2

Please sign in to comment.