Skip to content

Commit

Permalink
chore: add commn-jvm/testing package and make relevant packages dep…
Browse files Browse the repository at this point in the history
…end on it
  • Loading branch information
tinesoft committed Jun 1, 2024
1 parent dffc125 commit 3cf9de8
Show file tree
Hide file tree
Showing 58 changed files with 557 additions and 336 deletions.
32 changes: 19 additions & 13 deletions e2e/nx-ktor-e2e/tests/create-nx-ktor.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { hasNxWrapper, isNxWrapperInstalled } from '@nxrocks/common-cli';
import { createCLITestProject } from '@nxrocks/common/testing';
import { createCLITestProject } from '@nxrocks/common-jvm/testing';
import { execSync } from 'child_process';
import { rmSync } from 'fs';
import { join } from 'path';
Expand All @@ -9,29 +9,35 @@ describe('create-nx-ktor', () => {

beforeAll(() => {
// Cleanup the test project
projectDirectory && rmSync(projectDirectory, {
recursive: true,
force: true,
});
projectDirectory &&
rmSync(projectDirectory, {
recursive: true,
force: true,
});
});

it.each`
useNxWrapper
${true}
${false}
`('should be installed with Nx Wrapper=$useNxWrapper', ({useNxWrapper}) => {
projectDirectory = createCLITestProject('create-nx-ktor', `--prjName=bootapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --no-interactive --verbose=true`);
useNxWrapper
${true}
${false}
`('should be installed with Nx Wrapper=$useNxWrapper', ({ useNxWrapper }) => {
projectDirectory = createCLITestProject(
'create-nx-ktor',
`--prjName=bootapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --no-interactive --verbose=true`
);

// npm ls will fail if the package is not installed properly
execSync('npm ls @nxrocks/nx-ktor', {
cwd: useNxWrapper ? join(projectDirectory, '/.nx/installation'): projectDirectory,
cwd: useNxWrapper
? join(projectDirectory, '/.nx/installation')
: projectDirectory,
stdio: 'inherit',
});

expect(hasNxWrapper(projectDirectory)).toEqual(useNxWrapper);

if(useNxWrapper){
expect(isNxWrapperInstalled(projectDirectory)).toBe(true)
if (useNxWrapper) {
expect(isNxWrapperInstalled(projectDirectory)).toBe(true);
}
});
});
56 changes: 31 additions & 25 deletions e2e/nx-ktor-e2e/tests/nx-ktor.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { uniq } from '@nx/plugin/testing';
import {
uniq,
} from '@nx/plugin/testing';
import {
createTestProject, checkFilesExist, isWin, runNxCommandAsync,
readJson, tmpProjPath, octal
} from '@nxrocks/common/testing';
createTestProject,
checkFilesExist,
isWin,
runNxCommandAsync,
readJson,
tmpProjPath,
octal,
} from '@nxrocks/common-jvm/testing';
import { execSync } from 'child_process';
import { lstatSync, rmSync } from 'fs-extra';

Expand All @@ -25,10 +28,11 @@ describe('nx-ktor e2e', () => {

afterAll(() => {
// Cleanup the test project
projectDirectory && rmSync(projectDirectory, {
recursive: true,
force: true,
});
projectDirectory &&
rmSync(projectDirectory, {
recursive: true,
force: true,
});
});

it('should be installed', () => {
Expand All @@ -41,27 +45,29 @@ describe('nx-ktor e2e', () => {

it('should create nx-ktor', async () => {
const prjName = uniq('nx-ktor');
await runNxCommandAsync(`generate @nxrocks/nx-ktor:new ${prjName} --no-interactive --verbose`);
await runNxCommandAsync(
`generate @nxrocks/nx-ktor:new ${prjName} --no-interactive --verbose`
);
const resultBuild = await runNxCommandAsync(`build ${prjName}`);
expect(resultBuild.stdout).toContain(
`Executing command: ${isWin ? 'gradlew.bat' : './gradlew'} buildFatJar`
);
expect(() =>
checkFilesExist(
`${prjName}/gradlew`,
`${prjName}/build.gradle.kts`,
`${prjName}/src/main/kotlin/example/com/Application.kt`
)
).not.toThrow();
checkFilesExist(
`${prjName}/gradlew`,
`${prjName}/build.gradle.kts`,
`${prjName}/src/main/kotlin/example/com/Application.kt`
)
).not.toThrow();

// make sure the build wrapper file is executable (*nix only)
if (!isWin) {
const execPermission = '755';
expect(
lstatSync(tmpProjPath(`${prjName}/gradlew`)).mode &
octal(execPermission)
).toEqual(octal(execPermission));
}
// make sure the build wrapper file is executable (*nix only)
if (!isWin) {
const execPermission = '755';
expect(
lstatSync(tmpProjPath(`${prjName}/gradlew`)).mode &
octal(execPermission)
).toEqual(octal(execPermission));
}
}, 120000);

describe('--directory', () => {
Expand Down
32 changes: 19 additions & 13 deletions e2e/nx-micronaut-e2e/tests/create-nx-micronaut.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { hasNxWrapper, isNxWrapperInstalled } from '@nxrocks/common-cli';
import { createCLITestProject } from '@nxrocks/common/testing';
import { createCLITestProject } from '@nxrocks/common-jvm/testing';
import { execSync } from 'child_process';
import { rmSync } from 'fs';
import { join } from 'path';
Expand All @@ -9,29 +9,35 @@ describe('create-nx-micronaut', () => {

beforeAll(() => {
// Cleanup the test project
projectDirectory && rmSync(projectDirectory, {
recursive: true,
force: true,
});
projectDirectory &&
rmSync(projectDirectory, {
recursive: true,
force: true,
});
});

it.each`
useNxWrapper
${true}
${false}
`('should be installed with Nx Wrapper=$useNxWrapper', ({useNxWrapper}) => {
projectDirectory = createCLITestProject('create-nx-micronaut', `--prjName=bootapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --no-interactive`);
useNxWrapper
${true}
${false}
`('should be installed with Nx Wrapper=$useNxWrapper', ({ useNxWrapper }) => {
projectDirectory = createCLITestProject(
'create-nx-micronaut',
`--prjName=bootapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --no-interactive`
);

// npm ls will fail if the package is not installed properly
execSync('npm ls @nxrocks/nx-micronaut', {
cwd: useNxWrapper ? join(projectDirectory, '/.nx/installation'): projectDirectory,
cwd: useNxWrapper
? join(projectDirectory, '/.nx/installation')
: projectDirectory,
stdio: 'inherit',
});

expect(hasNxWrapper(projectDirectory)).toEqual(useNxWrapper);

if(useNxWrapper){
expect(isNxWrapperInstalled(projectDirectory)).toBe(true)
if (useNxWrapper) {
expect(isNxWrapperInstalled(projectDirectory)).toBe(true);
}
});
});
39 changes: 22 additions & 17 deletions e2e/nx-micronaut-e2e/tests/nx-micronaut.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { uniq } from '@nx/plugin/testing';
import {
uniq,
} from '@nx/plugin/testing';
import {
createTestProject, checkFilesExist, tmpProjPath, runNxCommandAsync, readFile,
readJson, octal, isWin
} from '@nxrocks/common/testing';
createTestProject,
checkFilesExist,
tmpProjPath,
runNxCommandAsync,
readFile,
readJson,
octal,
isWin,
} from '@nxrocks/common-jvm/testing';
import { execSync } from 'child_process';
import { lstatSync, rmSync } from 'fs';

describe('nx-micronaut e2e', () => {

let projectDirectory: string;

beforeAll(() => {
Expand All @@ -26,10 +29,11 @@ describe('nx-micronaut e2e', () => {

afterAll(() => {
// Cleanup the test project
projectDirectory && rmSync(projectDirectory, {
recursive: true,
force: true,
});
projectDirectory &&
rmSync(projectDirectory, {
recursive: true,
force: true,
});
});

it('should be installed', () => {
Expand All @@ -42,7 +46,9 @@ describe('nx-micronaut e2e', () => {

xit('should create nx-micronaut with default options', async () => {
const prjName = uniq('nx-micronaut');
runNxCommandAsync(`generate @nxrocks/nx-micronaut:new ${prjName} --no-interactive`);
runNxCommandAsync(
`generate @nxrocks/nx-micronaut:new ${prjName} --no-interactive`
);

const resultBuild = await runNxCommandAsync(`build ${prjName}`);
expect(resultBuild.stdout).toContain(
Expand All @@ -62,7 +68,7 @@ describe('nx-micronaut e2e', () => {
const execPermission = '755';
expect(
lstatSync(tmpProjPath(`${prjName}/gradlew`)).mode &
octal(execPermission)
octal(execPermission)
).toEqual(octal(execPermission));
}
}, 200000);
Expand Down Expand Up @@ -101,8 +107,7 @@ describe('nx-micronaut e2e', () => {
if (!isWin) {
const execPermission = '755';
expect(
lstatSync(tmpProjPath(`${prjName}/mvnw`)).mode &
octal(execPermission)
lstatSync(tmpProjPath(`${prjName}/mvnw`)).mode & octal(execPermission)
).toEqual(octal(execPermission));
}
},
Expand Down Expand Up @@ -155,7 +160,7 @@ describe('nx-micronaut e2e', () => {
const execPermission = '755';
expect(
lstatSync(tmpProjPath(`${prjName}/gradlew`)).mode &
octal(execPermission)
octal(execPermission)
).toEqual(octal(execPermission));
}
}, 200000);
Expand Down Expand Up @@ -187,7 +192,7 @@ describe('nx-micronaut e2e', () => {
const execPermission = '755';
expect(
lstatSync(tmpProjPath(`${prjName}/gradlew`)).mode &
octal(execPermission)
octal(execPermission)
).toEqual(octal(execPermission));
}
}, 200000);
Expand Down
32 changes: 19 additions & 13 deletions e2e/nx-quarkus-e2e/tests/create-nx-quarkus.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { hasNxWrapper, isNxWrapperInstalled } from '@nxrocks/common-cli';
import { createCLITestProject } from '@nxrocks/common/testing';
import { createCLITestProject } from '@nxrocks/common-jvm/testing';
import { execSync } from 'child_process';
import { rmSync } from 'fs';
import { join } from 'path';
Expand All @@ -9,29 +9,35 @@ describe('create-nx-spring-boot', () => {

beforeAll(() => {
// Cleanup the test project
projectDirectory && rmSync(projectDirectory, {
recursive: true,
force: true,
});
projectDirectory &&
rmSync(projectDirectory, {
recursive: true,
force: true,
});
});

it.each`
useNxWrapper
${true}
${false}
`('should be installed with Nx Wrapper=$useNxWrapper', ({useNxWrapper}) => {
projectDirectory = createCLITestProject('create-nx-spring-boot', `--prjName=bootapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --no-interactive`);
useNxWrapper
${true}
${false}
`('should be installed with Nx Wrapper=$useNxWrapper', ({ useNxWrapper }) => {
projectDirectory = createCLITestProject(
'create-nx-spring-boot',
`--prjName=bootapp --useNxWrapper=${useNxWrapper} --nxCloud=skip --no-interactive`
);

// npm ls will fail if the package is not installed properly
execSync('npm ls @nxrocks/nx-spring-boot', {
cwd: useNxWrapper ? join(projectDirectory, '/.nx/installation'): projectDirectory,
cwd: useNxWrapper
? join(projectDirectory, '/.nx/installation')
: projectDirectory,
stdio: 'inherit',
});

expect(hasNxWrapper(projectDirectory)).toEqual(useNxWrapper);

if(useNxWrapper){
expect(isNxWrapperInstalled(projectDirectory)).toBe(true)
if (useNxWrapper) {
expect(isNxWrapperInstalled(projectDirectory)).toBe(true);
}
});
});
Loading

0 comments on commit 3cf9de8

Please sign in to comment.