diff --git a/packages/nx-boot-maven/src/generators/application/generator.ts b/packages/nx-boot-maven/src/generators/application/generator.ts index 54c66aee1..613f74907 100644 --- a/packages/nx-boot-maven/src/generators/application/generator.ts +++ b/packages/nx-boot-maven/src/generators/application/generator.ts @@ -197,11 +197,7 @@ export default async function ( }, serve: { executor: '@jnxplus/nx-boot-maven:serve', - dependsOn: [ - { - target: 'build', - }, - ], + dependsOn: ['build'], }, lint: { executor: '@jnxplus/nx-boot-maven:lint', @@ -211,11 +207,7 @@ export default async function ( }, test: { executor: '@jnxplus/nx-boot-maven:test', - dependsOn: [ - { - target: 'build', - }, - ], + dependsOn: ['build'], }, }, tags: normalizedOptions.parsedTags, @@ -235,11 +227,7 @@ export default async function ( }, serve: { executor: '@jnxplus/nx-boot-maven:serve', - dependsOn: [ - { - target: 'build', - }, - ], + dependsOn: ['build'], }, lint: { executor: '@jnxplus/nx-boot-maven:lint', @@ -249,11 +237,7 @@ export default async function ( }, test: { executor: '@jnxplus/nx-boot-maven:test', - dependsOn: [ - { - target: 'build', - }, - ], + dependsOn: ['build'], }, ktformat: { executor: '@jnxplus/nx-boot-maven:ktformat', diff --git a/packages/nx-maven/src/generators/application/generator.ts b/packages/nx-maven/src/generators/application/generator.ts index f11a8e822..c7f36efd5 100644 --- a/packages/nx-maven/src/generators/application/generator.ts +++ b/packages/nx-maven/src/generators/application/generator.ts @@ -194,11 +194,7 @@ export default async function (tree: Tree, options: NxMavenAppGeneratorSchema) { }, serve: { executor: '@jnxplus/nx-maven:serve', - dependsOn: [ - { - target: 'build', - }, - ], + dependsOn: ['build'], }, lint: { executor: '@jnxplus/nx-maven:lint', @@ -208,11 +204,7 @@ export default async function (tree: Tree, options: NxMavenAppGeneratorSchema) { }, test: { executor: '@jnxplus/nx-maven:test', - dependsOn: [ - { - target: 'build', - }, - ], + dependsOn: ['build'], }, }, tags: normalizedOptions.parsedTags, @@ -232,11 +224,7 @@ export default async function (tree: Tree, options: NxMavenAppGeneratorSchema) { }, serve: { executor: '@jnxplus/nx-maven:serve', - dependsOn: [ - { - target: 'build', - }, - ], + dependsOn: ['build'], }, lint: { executor: '@jnxplus/nx-maven:lint', @@ -246,11 +234,7 @@ export default async function (tree: Tree, options: NxMavenAppGeneratorSchema) { }, test: { executor: '@jnxplus/nx-maven:test', - dependsOn: [ - { - target: 'build', - }, - ], + dependsOn: ['build'], }, ktformat: { executor: '@jnxplus/nx-maven:ktformat', diff --git a/packages/nx-quarkus-maven/src/generators/application/generator.ts b/packages/nx-quarkus-maven/src/generators/application/generator.ts index 68e83d92a..d4610296b 100644 --- a/packages/nx-quarkus-maven/src/generators/application/generator.ts +++ b/packages/nx-quarkus-maven/src/generators/application/generator.ts @@ -206,11 +206,6 @@ export default async function ( }, serve: { executor: '@jnxplus/nx-quarkus-maven:serve', - dependsOn: [ - { - target: 'build', - }, - ], }, lint: { executor: '@jnxplus/nx-quarkus-maven:lint', @@ -220,19 +215,10 @@ export default async function ( }, test: { executor: '@jnxplus/nx-quarkus-maven:test', - dependsOn: [ - { - target: 'build', - }, - ], + dependsOn: ['build'], }, 'integration-test': { executor: '@jnxplus/nx-quarkus-maven:integration-test', - dependsOn: [ - { - target: 'build', - }, - ], }, }, tags: normalizedOptions.parsedTags, @@ -252,11 +238,6 @@ export default async function ( }, serve: { executor: '@jnxplus/nx-quarkus-maven:serve', - dependsOn: [ - { - target: 'build', - }, - ], }, lint: { executor: '@jnxplus/nx-quarkus-maven:lint', @@ -266,19 +247,10 @@ export default async function ( }, test: { executor: '@jnxplus/nx-quarkus-maven:test', - dependsOn: [ - { - target: 'build', - }, - ], + dependsOn: ['build'], }, 'integration-test': { executor: '@jnxplus/nx-quarkus-maven:integration-test', - dependsOn: [ - { - target: 'build', - }, - ], }, ktformat: { executor: '@jnxplus/nx-quarkus-maven:ktformat', diff --git a/packages/nx-quarkus-maven/src/generators/library/generator.ts b/packages/nx-quarkus-maven/src/generators/library/generator.ts index 5a7d2f81d..1535e1734 100644 --- a/packages/nx-quarkus-maven/src/generators/library/generator.ts +++ b/packages/nx-quarkus-maven/src/generators/library/generator.ts @@ -189,6 +189,7 @@ export default async function ( }, test: { executor: '@jnxplus/nx-quarkus-maven:test', + dependsOn: ['build'], }, }, tags: normalizedOptions.parsedTags, @@ -211,6 +212,7 @@ export default async function ( }, test: { executor: '@jnxplus/nx-quarkus-maven:test', + dependsOn: ['build'], }, ktformat: { executor: '@jnxplus/nx-quarkus-maven:ktformat', diff --git a/testing-projects/e2e/nx-boot-maven-e2e/tests/nx-boot-maven.spec.ts b/testing-projects/e2e/nx-boot-maven-e2e/tests/nx-boot-maven.spec.ts index f006cb4a4..c7de1671b 100644 --- a/testing-projects/e2e/nx-boot-maven-e2e/tests/nx-boot-maven.spec.ts +++ b/testing-projects/e2e/nx-boot-maven-e2e/tests/nx-boot-maven.spec.ts @@ -374,6 +374,22 @@ describe('nx-boot-maven e2e', () => { expect(pomXml.includes('com.example')).toBeTruthy(); expect(pomXml.includes('0.0.1-SNAPSHOT')).toBeTruthy(); + const process = await runNxCommandUntil(`serve ${appName}`, (output) => + output.includes(`Tomcat started on port(s): ${port}`) + ); + + const dataResult = await getData(port); + expect(dataResult.status).toEqual(200); + expect(dataResult.message).toMatch('Hello World!'); + + // port and process cleanup + try { + await promisifiedTreeKill(process.pid, 'SIGKILL'); + await killPorts(port); + } catch (err) { + // ignore err + } + const testResult = await runNxCommandAsync(`test ${appName}`); expect(testResult.stdout).toContain('Executor ran for Test'); @@ -409,22 +425,6 @@ describe('nx-boot-maven e2e', () => { source: appName, target: parentProjectName, }); - - const process = await runNxCommandUntil(`serve ${appName}`, (output) => - output.includes(`Tomcat started on port(s): ${port}`) - ); - - const dataResult = await getData(port); - expect(dataResult.status).toEqual(200); - expect(dataResult.message).toMatch('Hello World!'); - - // port and process cleanup - try { - await promisifiedTreeKill(process.pid, 'SIGKILL'); - await killPorts(port); - } catch (err) { - // ignore err - } }, 120000); it('should build-image a kotlin application', async () => { @@ -483,6 +483,23 @@ describe('nx-boot-maven e2e', () => { const projectJson = readJson(`apps/${appDir}/${randomName}/project.json`); expect(projectJson.tags).toEqual(['e2etag', 'e2ePackage']); + const process = await runNxCommandUntil( + `serve ${appName} --args="-Dspring-boot.run.profiles=test"`, + (output) => output.includes(`Tomcat started on port(s): ${port}`) + ); + + const dataResult = await getData(port); + expect(dataResult.status).toEqual(200); + expect(dataResult.message).toMatch('Hello World!'); + + // port and process cleanup + try { + await promisifiedTreeKill(process.pid, 'SIGKILL'); + await killPorts(port); + } catch (err) { + // ignore err + } + const testResult = await runNxCommandAsync(`test ${appName}`); expect(testResult.stdout).toContain('Executor ran for Test'); @@ -510,23 +527,6 @@ describe('nx-boot-maven e2e', () => { source: appName, target: parentProjectName, }); - - const process = await runNxCommandUntil( - `serve ${appName} --args="-Dspring-boot.run.profiles=test"`, - (output) => output.includes(`Tomcat started on port(s): ${port}`) - ); - - const dataResult = await getData(port); - expect(dataResult.status).toEqual(200); - expect(dataResult.message).toMatch('Hello World!'); - - // port and process cleanup - try { - await promisifiedTreeKill(process.pid, 'SIGKILL'); - await killPorts(port); - } catch (err) { - // ignore err - } }, 120000); it('should generate an app with a simple package name', async () => { @@ -971,11 +971,12 @@ describe('nx-boot-maven e2e', () => { }, 120000); it('should add a lib to an app dependencies', async () => { + const port = 9090; const appName = uniq('boot-maven-app-'); const libName = uniq('boot-maven-lib-'); await runNxCommandAsync( - `generate @jnxplus/nx-boot-maven:application ${appName}` + `generate @jnxplus/nx-boot-maven:application ${appName} --port ${port}` ); await runNxCommandAsync( @@ -1009,6 +1010,22 @@ describe('nx-boot-maven e2e', () => { updateFile(helloControllerPath, newHelloControllerContent); + const process = await runNxCommandUntil(`serve ${appName}`, (output) => + output.includes(`Tomcat started on port(s): ${port}`) + ); + + const dataResult = await getData(port); + expect(dataResult.status).toEqual(200); + expect(dataResult.message).toMatch('Hello World!'); + + // port and process cleanup + try { + await promisifiedTreeKill(process.pid, 'SIGKILL'); + await killPorts(port); + } catch (err) { + // ignore err + } + const testResult = await runNxCommandAsync(`test ${appName}`); expect(testResult.stdout).toContain('Executor ran for Test'); @@ -1047,6 +1064,51 @@ describe('nx-boot-maven e2e', () => { }); }, 120000); + it('should test an app with a lib', async () => { + const appName = uniq('boot-maven-app-'); + const libName = uniq('boot-maven-lib-'); + + await runNxCommandAsync( + `generate @jnxplus/nx-boot-maven:application ${appName}` + ); + + await runNxCommandAsync( + `generate @jnxplus/nx-boot-maven:library ${libName} --projects ${appName}` + ); + + const helloControllerPath = `apps/${appName}/src/main/java/com/example/${names( + appName + ).className.toLocaleLowerCase()}/HelloController.java`; + const helloControllerContent = readFile(helloControllerPath); + + const regex1 = /package\s*com\.example\..*\s*;/; + + const regex2 = /public\s*class\s*HelloController\s*{/; + + const regex3 = /"Hello World!"/; + + const newHelloControllerContent = helloControllerContent + .replace( + regex1, + `$&\nimport org.springframework.beans.factory.annotation.Autowired;\nimport com.example.${names( + libName + ).className.toLocaleLowerCase()}.HelloService;` + ) + .replace(regex2, '$&\n@Autowired\nprivate HelloService helloService;') + .replace(regex3, 'this.helloService.message()'); + + updateFile(helloControllerPath, newHelloControllerContent); + + const testResult = await runNxCommandAsync(`test ${appName}`); + expect(testResult.stdout).toContain('Executor ran for Test'); + + const buildResult = await runNxCommandAsync(`build ${appName}`); + expect(buildResult.stdout).toContain('Executor ran for Build'); + + const testResult2 = await runNxCommandAsync(`test ${libName}`); + expect(testResult2.stdout).toContain('Executor ran for Test'); + }, 120000); + it('should add a kotlin lib to a kotlin app dependencies', async () => { const appName = uniq('boot-maven-app-'); const libName = uniq('boot-maven-lib-'); diff --git a/testing-projects/e2e/nx-quarkus-maven-e2e/tests/nx-quarkus-maven.spec.ts b/testing-projects/e2e/nx-quarkus-maven-e2e/tests/nx-quarkus-maven.spec.ts index 7e9ef7424..a6ea9e7eb 100644 --- a/testing-projects/e2e/nx-quarkus-maven-e2e/tests/nx-quarkus-maven.spec.ts +++ b/testing-projects/e2e/nx-quarkus-maven-e2e/tests/nx-quarkus-maven.spec.ts @@ -280,6 +280,23 @@ describe('nx-quarkus-maven e2e', () => { const projectJson = readJson(`apps/${appDir}/${randomName}/project.json`); expect(projectJson.tags).toEqual(['e2etag', 'e2ePackage']); + const process = await runNxCommandUntil( + `serve ${appName} --args="-Dquarkus-profile=prod"`, + (output) => output.includes(`Listening on: http://localhost:${port}`) + ); + + const dataResult = await getData(port, '/hello'); + expect(dataResult.status).toEqual(200); + expect(dataResult.message).toMatch('Hello World!'); + + // port and process cleanup + try { + await promisifiedTreeKill(process.pid, 'SIGKILL'); + await killPorts(port); + } catch (err) { + // ignore err + } + const testResult = await runNxCommandAsync(`test ${appName}`); expect(testResult.stdout).toContain('Executor ran for Test'); @@ -309,23 +326,6 @@ describe('nx-quarkus-maven e2e', () => { source: appName, target: parentProjectName, }); - - const process = await runNxCommandUntil( - `serve ${appName} --args="-Dquarkus-profile=prod"`, - (output) => output.includes(`Listening on: http://localhost:${port}`) - ); - - const dataResult = await getData(port, '/hello'); - expect(dataResult.status).toEqual(200); - expect(dataResult.message).toMatch('Hello World!'); - - // port and process cleanup - try { - await promisifiedTreeKill(process.pid, 'SIGKILL'); - await killPorts(port); - } catch (err) { - // ignore err - } }, 120000); it('should create a kotlin application', async () => { @@ -354,6 +354,22 @@ describe('nx-quarkus-maven e2e', () => { expect(pomXml.includes('org.acme')).toBeTruthy(); expect(pomXml.includes('0.0.1-SNAPSHOT')).toBeTruthy(); + const process = await runNxCommandUntil(`serve ${appName}`, (output) => + output.includes(`Listening on: http://localhost:${port}`) + ); + + const dataResult = await getData(port, '/hello'); + expect(dataResult.status).toEqual(200); + expect(dataResult.message).toMatch('Hello World!'); + + // port and process cleanup + try { + await promisifiedTreeKill(process.pid, 'SIGKILL'); + await killPorts(port); + } catch (err) { + // ignore err + } + const testResult = await runNxCommandAsync(`test ${appName}`); expect(testResult.stdout).toContain('Executor ran for Test'); @@ -389,22 +405,6 @@ describe('nx-quarkus-maven e2e', () => { source: appName, target: parentProjectName, }); - - const process = await runNxCommandUntil(`serve ${appName}`, (output) => - output.includes(`Listening on: http://localhost:${port}`) - ); - - const dataResult = await getData(port, '/hello'); - expect(dataResult.status).toEqual(200); - expect(dataResult.message).toMatch('Hello World!'); - - // port and process cleanup - try { - await promisifiedTreeKill(process.pid, 'SIGKILL'); - await killPorts(port); - } catch (err) { - // ignore err - } }, 240000); it('should build-image a kotlin app', async () => { @@ -763,13 +763,13 @@ describe('nx-quarkus-maven e2e', () => { expect(pomXml.includes('org.jnxplus')).toBeTruthy(); expect(pomXml.includes('1.2.3')).toBeTruthy(); - const testResult = await runNxCommandAsync(`test ${libName}`); - expect(testResult.stdout).toContain('Executor ran for Test'); - //should add tags to project.json const projectJson = readJson(`libs/${libDir}/${randomName}/project.json`); expect(projectJson.tags).toEqual(['e2etag', 'e2ePackage']); + const testResult = await runNxCommandAsync(`test ${libName}`); + expect(testResult.stdout).toContain('Executor ran for Test'); + const buildResult = await runNxCommandAsync(`build ${libName}`); expect(buildResult.stdout).toContain('Executor ran for Build');