Skip to content

Commit

Permalink
feat(graph): display expanded task inputs (#19597)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKless authored Oct 16, 2023
1 parent 92e0500 commit c727a22
Show file tree
Hide file tree
Showing 33 changed files with 24,588 additions and 65 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jest.debug.config.js
/graph/client/src/assets/dev/environment.js
/graph/client/src/assets/generated-project-graphs
/graph/client/src/assets/generated-task-graphs
/graph/client/src/assets/generated-task-inputs
/nx-dev/nx-dev/public/documentation
/nx-dev/nx-dev/public/images/open-graph

Expand Down
106 changes: 106 additions & 0 deletions e2e/nx-misc/src/extras.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { parseJson } from '@nx/devkit';
import {
checkFilesExist,
cleanupProject,
Expand All @@ -8,6 +9,7 @@ import {
setMaxWorkers,
uniq,
updateFile,
readFile,
updateJson,
} from '@nx/e2e/utils';
import { join } from 'path';
Expand Down Expand Up @@ -321,4 +323,108 @@ describe('Extra Nx Misc Tests', () => {
expect(unitTestsOutput).toContain('Successfully ran target test');
});
});

describe('task graph inputs', () => {
const readExpandedTaskInputResponse = (): Record<
string,
Record<string, string[]>
> =>
parseJson(
readFile('static/environment.js').match(
/window\.expandedTaskInputsResponse\s*=\s*(.*?);/
)[1]
);

const baseLib = 'lib-base-123';
beforeAll(() => {
runCLI(`generate @nx/js:lib ${baseLib}`);
});

it('should correctly expand default task inputs', () => {
runCLI('graph --file=graph.html');

expect(readExpandedTaskInputResponse()[`${baseLib}:build`])
.toMatchInlineSnapshot(`
{
"external": [
"npm:@nx/js",
"npm:tslib",
],
"general": [
".gitignore",
"nx.json",
],
"lib-base-123": [
"libs/lib-base-123/README.md",
"libs/lib-base-123/package.json",
"libs/lib-base-123/project.json",
"libs/lib-base-123/src/index.ts",
"libs/lib-base-123/src/lib/lib-base-123.ts",
"libs/lib-base-123/tsconfig.json",
"libs/lib-base-123/tsconfig.lib.json",
],
}
`);
});

it('should correctly expand dependent task inputs', () => {
const dependentLib = 'lib-dependent-123';
runCLI(`generate @nx/js:lib ${dependentLib}`);

updateJson(join('libs', baseLib, 'project.json'), (config) => {
config.targets['build'].inputs = ['default', '^default'];
config.implicitDependencies = [dependentLib];
return config;
});

updateJson('nx.json', (json) => {
json.namedInputs = {
...json.namedInputs,
default: ['{projectRoot}/**/*'],
};
return json;
});
runCLI('graph --file=graph.html');

expect(readExpandedTaskInputResponse()[`${baseLib}:build`])
.toMatchInlineSnapshot(`
{
"external": [
"npm:@nx/js",
"npm:tslib",
],
"general": [
".gitignore",
"nx.json",
],
"lib-base-123": [
"libs/lib-base-123/.eslintrc.json",
"libs/lib-base-123/README.md",
"libs/lib-base-123/jest.config.ts",
"libs/lib-base-123/package.json",
"libs/lib-base-123/project.json",
"libs/lib-base-123/src/index.ts",
"libs/lib-base-123/src/lib/lib-base-123.spec.ts",
"libs/lib-base-123/src/lib/lib-base-123.ts",
"libs/lib-base-123/tsconfig.json",
"libs/lib-base-123/tsconfig.lib.json",
"libs/lib-base-123/tsconfig.spec.json",
],
"lib-dependent-123": [
"libs/lib-dependent-123/.eslintrc.json",
"libs/lib-dependent-123/README.md",
"libs/lib-dependent-123/jest.config.ts",
"libs/lib-dependent-123/package.json",
"libs/lib-dependent-123/project.json",
"libs/lib-dependent-123/src/index.ts",
"libs/lib-dependent-123/src/lib/lib-dependent-123.spec.ts",
"libs/lib-dependent-123/src/lib/lib-dependent-123.ts",
"libs/lib-dependent-123/tsconfig.json",
"libs/lib-dependent-123/tsconfig.lib.json",
"libs/lib-dependent-123/tsconfig.spec.json",
],
}
`);
});
});
});
1 change: 1 addition & 0 deletions graph/client-e2e/cypress/downloads/downloads.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cr24
53 changes: 52 additions & 1 deletion graph/client-e2e/src/e2e/dev-task-graph.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ import {
getToggleAllButtonForFolder,
getUncheckedProjectItems,
getUnfocusProjectButton,
openTooltipForNode,
} from '../support/app.po';

import * as affectedJson from '../fixtures/affected.json';
import { testProjectsRoutes, testTaskRoutes } from '../support/routing-tests';
import * as nxExamplesJson from '../fixtures/nx-examples-project-graph.json';
import * as nxExamplesTaskInputs from '../fixtures/nx-examples-task-inputs.json';

describe('dev mode - task graph', () => {
before(() => {
Expand Down Expand Up @@ -183,4 +184,54 @@ describe('dev mode - task graph', () => {
// and also new /projects route
testTaskRoutes('browser', ['/e2e/tasks']);
});

describe('file inputs', () => {
beforeEach(() => {
cy.intercept(
{
method: 'GET',
url: '/task-inputs.json*',
},
async (req) => {
// Extract the desired query parameter
const taskId = req.url.split('taskId=')[1];
// Load the fixture data and find the property based on the query parameter

const expandedInputs = nxExamplesTaskInputs[taskId];

// Reply with the selected property
req.reply({
body: expandedInputs,
});
}
).as('getTaskInputs');
});
it('should display input files', () => {
getSelectTargetDropdown().select('build', { force: true });
cy.get('[data-project="cart"]').click({
force: true,
});
openTooltipForNode('cart:build');
cy.get('[data-cy="inputs-accordion"]').click();

cy.get('[data-cy="input-list-entry"]').should('have.length', 18);
const expectedSections = [
'cart-cart-page',
'shared-assets',
'shared-header',
'shared-styles',
'External Inputs',
];
cy.get('[data-cy="input-section-entry"]').each((el, idx) => {
expect(el.text()).to.equal(expectedSections[idx]);
});

const sharedHeaderSelector =
'[data-cy="input-section-entry"]:contains(shared-header)';
cy.get(sharedHeaderSelector).click();
cy.get(sharedHeaderSelector)
.nextAll('[data-cy="input-list-entry"]')
.should('have.length', 9);
});
});
});
Loading

1 comment on commit c727a22

@vercel
Copy link

@vercel vercel bot commented on c727a22 Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-nrwl.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app
nx.dev

Please sign in to comment.