From 65e24c32b220cb1bd8246908f3a0189e8f190d17 Mon Sep 17 00:00:00 2001 From: Emily Xiong Date: Wed, 4 Dec 2024 14:57:38 -0500 Subject: [PATCH] fix(gradle): change gradle glob to include root gradlew --- packages/gradle/plugin.spec.ts | 127 ++++++++++++++++++ .../gradle/src/utils/split-config-files.ts | 2 + 2 files changed, 129 insertions(+) create mode 100644 packages/gradle/plugin.spec.ts diff --git a/packages/gradle/plugin.spec.ts b/packages/gradle/plugin.spec.ts new file mode 100644 index 0000000000000..c07019a01d431 --- /dev/null +++ b/packages/gradle/plugin.spec.ts @@ -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([ + ['proj/build.gradle', 'proj'], + ]), + buildFileToDepsMap: new Map(), + gradleFileToOutputDirsMap: new Map>([ + ['proj/build.gradle', new Map([['build', 'build']])], + ]), + gradleProjectToTasksTypeMap: new Map>([ + ['proj', new Map([['test', 'Verification']])], + ]), + gradleProjectToProjectName: new Map([['proj', 'proj']]), + gradleProjectNameToProjectRootMap: new Map([ + ['proj', 'proj'], + ]), + gradleProjectToChildProjects: new Map(), + }; + 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": ".", + }, + }, + }, + }, + }, + }, + ], + ] + `); + }); +}); diff --git a/packages/gradle/src/utils/split-config-files.ts b/packages/gradle/src/utils/split-config-files.ts index c8b900e91568d..2869107e88f44 100644 --- a/packages/gradle/src/utils/split-config-files.ts +++ b/packages/gradle/src/utils/split-config-files.ts @@ -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