Skip to content

Commit

Permalink
test: test dependsOn option (#240)
Browse files Browse the repository at this point in the history
* test: test dependsOn option

* test: test dependsOn option
  • Loading branch information
khalilou88 authored May 28, 2023
1 parent ba3961a commit 34187d0
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 140 deletions.
24 changes: 4 additions & 20 deletions packages/nx-boot-maven/src/generators/application/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -211,11 +207,7 @@ export default async function (
},
test: {
executor: '@jnxplus/nx-boot-maven:test',
dependsOn: [
{
target: 'build',
},
],
dependsOn: ['build'],
},
},
tags: normalizedOptions.parsedTags,
Expand All @@ -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',
Expand All @@ -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',
Expand Down
24 changes: 4 additions & 20 deletions packages/nx-maven/src/generators/application/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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,
Expand All @@ -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',
Expand All @@ -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',
Expand Down
32 changes: 2 additions & 30 deletions packages/nx-quarkus-maven/src/generators/application/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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,
Expand All @@ -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',
Expand All @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions packages/nx-quarkus-maven/src/generators/library/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ export default async function (
},
test: {
executor: '@jnxplus/nx-quarkus-maven:test',
dependsOn: ['build'],
},
},
tags: normalizedOptions.parsedTags,
Expand All @@ -211,6 +212,7 @@ export default async function (
},
test: {
executor: '@jnxplus/nx-quarkus-maven:test',
dependsOn: ['build'],
},
ktformat: {
executor: '@jnxplus/nx-quarkus-maven:ktformat',
Expand Down
130 changes: 96 additions & 34 deletions testing-projects/e2e/nx-boot-maven-e2e/tests/nx-boot-maven.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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-');
Expand Down
Loading

0 comments on commit 34187d0

Please sign in to comment.