Skip to content

Commit

Permalink
feat(vcs): defined the tag property under scm when lifting
Browse files Browse the repository at this point in the history
for #9
  • Loading branch information
travi committed Feb 10, 2024
1 parent ae853b9 commit 11476a0
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export {default as scaffold} from './scaffolder.js';
export {lift} from './pom/index.js';
1 change: 1 addition & 0 deletions src/pom/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';
13 changes: 13 additions & 0 deletions src/pom/lifter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {promises as fs} from 'node:fs';
import {XMLBuilder, XMLParser} from 'fast-xml-parser';

export default async function ({projectRoot}) {
const pathToPom = `${projectRoot}/pom.xml`;
const parser = new XMLParser();
const builder = new XMLBuilder({format: true});
const existingPomContents = parser.parse(await fs.readFile(pathToPom, 'utf-8'));
existingPomContents.project.scm = {tag: 'HEAD'};
await fs.writeFile(pathToPom, builder.build(existingPomContents));

return {};
}
34 changes: 34 additions & 0 deletions src/pom/lifter.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {promises as fs} from 'node:fs';

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

import liftPom from './lifter.js';

vi.mock('node:fs');

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

it('should define the vcs details', async () => {
const projectRoot = any.string();
when(fs.readFile)
.calledWith(`${projectRoot}/pom.xml`, 'utf-8')
.mockResolvedValue('<project><modelVersion>4.0.0</modelVersion></project>');

expect(await liftPom({projectRoot})).toEqual({});
expect(fs.writeFile).toHaveBeenCalledWith(
`${projectRoot}/pom.xml`,
`<project>
<modelVersion>4.0.0</modelVersion>
<scm>
<tag>HEAD</tag>
</scm>
</project>
`
);
});
});
8 changes: 6 additions & 2 deletions test/integration/features/step_definitions/common-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import stubbedFs from 'mock-fs';
const __dirname = dirname(fileURLToPath(import.meta.url)); // eslint-disable-line no-underscore-dangle
const stubbedNodeModules = stubbedFs.load(resolve(__dirname, '..', '..', '..', '..', 'node_modules'));

let scaffold;
let scaffold, lift;

Before(async function () {
// eslint-disable-next-line import/no-extraneous-dependencies,import/no-unresolved
({scaffold} = await import('@form8ion/java'));
({scaffold, lift} = await import('@form8ion/java'));

stubbedFs({
node_modules: stubbedNodeModules
Expand All @@ -27,3 +27,7 @@ After(function () {
When('the project is scaffolded', async function () {
await scaffold({projectRoot: this.projectRoot, projectName: this.projectName});
});

When('the project is lifted', async function () {
await lift({projectRoot: this.projectRoot});
});
16 changes: 16 additions & 0 deletions test/integration/features/step_definitions/vcs-steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {promises as fs} from 'node:fs';

import {Given, Then} from '@cucumber/cucumber';
import {XMLParser} from 'fast-xml-parser';
import {assert} from 'chai';

Given('vcs details are not defined in the pom', async function () {
await fs.writeFile(`${this.projectRoot}/pom.xml`, '<project><modelVersion>4.0.0</modelVersion></project>');
});

Then('vcs details are defined in the pom', async function () {
const parser = new XMLParser();
const {project: {scm}} = parser.parse(await fs.readFile(`${this.projectRoot}/pom.xml`, 'utf-8'));

assert.deepEqual(scm, {tag: 'HEAD'});
});
6 changes: 6 additions & 0 deletions test/integration/features/vcs.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: Version Control Details

Scenario: No Details Defined
Given vcs details are not defined in the pom
When the project is lifted
Then vcs details are defined in the pom

0 comments on commit 11476a0

Please sign in to comment.