<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes https://github.com/nrwl/nx/issues/28865
128 lines
3.7 KiB
TypeScript
128 lines
3.7 KiB
TypeScript
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": ".",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
],
|
|
]
|
|
`);
|
|
});
|
|
});
|