Skip to content

Commit

Permalink
fix(gradle): change gradle glob to include root gradlew
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi committed Dec 4, 2024
1 parent 7157e7a commit 65e24c3
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 0 deletions.
127 changes: 127 additions & 0 deletions packages/gradle/plugin.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import { CreateNodesContext } from '@nx/devkit';
import { TempFs } from '@nx/devkit/internal-testing-utils';
import { createNodesV2 } from './plugin';
import { type GradleReport } from './src/utils/get-gradle-report';

let gradleReport: GradleReport;
jest.mock('./src/utils/get-gradle-report', () => {
return {
GRADLE_BUILD_FILES: new Set(['build.gradle', 'build.gradle.kts']),
populateGradleReport: jest.fn().mockImplementation(() => void 0),
getCurrentGradleReport: jest.fn().mockImplementation(() => gradleReport),
};
});

describe('@nx/gradle/plugin', () => {
let createNodesFunction = createNodesV2[1];
let context: CreateNodesContext;
let tempFs: TempFs;

beforeEach(async () => {
tempFs = new TempFs('gradle-plugin');
gradleReport = {
gradleFileToGradleProjectMap: new Map<string, string>([
['proj/build.gradle', 'proj'],
]),
buildFileToDepsMap: new Map<string, string>(),
gradleFileToOutputDirsMap: new Map<string, Map<string, string>>([
['proj/build.gradle', new Map([['build', 'build']])],
]),
gradleProjectToTasksTypeMap: new Map<string, Map<string, string>>([
['proj', new Map([['test', 'Verification']])],
]),
gradleProjectToProjectName: new Map<string, string>([['proj', 'proj']]),
gradleProjectNameToProjectRootMap: new Map<string, string>([
['proj', 'proj'],
]),
gradleProjectToChildProjects: new Map<string, string[]>(),
};
context = {
nxJsonConfiguration: {
namedInputs: {
default: ['{projectRoot}/**/*'],
production: ['!{projectRoot}/**/*.spec.ts'],
},
},
workspaceRoot: tempFs.tempDir,
configFiles: [],
};
tempFs.createFileSync('package.json', JSON.stringify({ name: 'repo' }));
tempFs.createFileSync(
'my-app/project.json',
JSON.stringify({ name: 'my-app' })
);
});

afterEach(() => {
jest.resetModules();
tempFs.cleanup();
tempFs = null;
});

it('should create nodes', async () => {
tempFs.createFileSync('gradlew', '');

const nodes = await createNodesFunction(
['gradlew', 'proj/build.gradle'],
undefined,
context
);

expect(nodes).toMatchInlineSnapshot(`
[
[
"proj/build.gradle",
{
"projects": {
"proj": {
"metadata": {
"targetGroups": {
"Verification": [
"test",
],
},
"technologies": [
"gradle",
],
},
"name": "proj",
"targets": {
"test": {
"cache": true,
"command": "./gradlew proj:test",
"dependsOn": [
"testClasses",
],
"inputs": [
"default",
"^production",
],
"metadata": {
"help": {
"command": "./gradlew help --task proj:test",
"example": {
"options": {
"args": [
"--rerun",
],
},
},
},
"technologies": [
"gradle",
],
},
"options": {
"cwd": ".",
},
},
},
},
},
},
],
]
`);
});
});
2 changes: 2 additions & 0 deletions packages/gradle/src/utils/split-config-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const gradleConfigGlob = combineGlobPatterns(
);

export const gradleConfigAndTestGlob = combineGlobPatterns(
...Array.from(GRADLE_BUILD_FILES),
...Array.from(GRALDEW_FILES),
...Array.from(GRADLE_BUILD_FILES).map((file) => `**/${file}`),
...Array.from(GRALDEW_FILES).map((file) => `**/${file}`),
...GRADLE_TEST_FILES
Expand Down

0 comments on commit 65e24c3

Please sign in to comment.