Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): fix output text for multiple targets #28043

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
339 changes: 338 additions & 1 deletion packages/nx/src/tasks-runner/life-cycles/formatting-utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { formatFlags } from './formatting-utils';
import { output } from '../../utils/output';
import { formatFlags, formatTargetsAndProjects } from './formatting-utils';

describe('formatFlags', () => {
it('should properly show string values', () => {
Expand Down Expand Up @@ -42,3 +43,339 @@ describe('formatFlags', () => {
);
});
});

describe('formatTargetsAndProjects', () => {
it('should handle single project and target', () => {
expect(
formatTargetsAndProjects(
['myproject'],
['lint', 'build', 'test'],
[
{
id: 'myproject:build',
target: {
project: 'myproject',
target: 'build',
},
overrides: {},
parallelism: false,
outputs: [],
},
]
)
).toEqual(`target ${output.bold('build')} for project myproject`);

expect(
formatTargetsAndProjects(
['myproject'],
['lint', 'build', 'test'],
[
{
id: 'myproject:lint',
target: {
project: 'myproject',
target: 'lint',
},
overrides: {},
parallelism: false,
outputs: [],
},
]
)
).toEqual(`target ${output.bold('lint')} for project myproject`);
});

it('should handle single project and multiple targets', () => {
expect(
formatTargetsAndProjects(
['myproject'],
['lint', 'build', 'test'],
[
{
id: 'myproject:build',
target: {
project: 'myproject',
target: 'build',
},
overrides: {},
parallelism: false,
outputs: [],
},
{
id: 'myproject:test',
target: {
project: 'myproject',
target: 'test',
},
overrides: {},
parallelism: false,
outputs: [],
},
]
)
).toEqual(
`targets ${output.bold('build')}, ${output.bold(
'test'
)} for project myproject`
);
expect(
formatTargetsAndProjects(
['myproject', 'myproject2'],
['lint', 'build', 'test'],
[
{
id: 'myproject:lint',
target: {
project: 'myproject',
target: 'lint',
},
overrides: {},
parallelism: false,
outputs: [],
},
]
)
).toEqual(`target ${output.bold('lint')} for project myproject`);

expect(
formatTargetsAndProjects(
['myproject', 'myproject2'],
['lint', 'build', 'test'],
[
{
id: 'myproject2:lint',
target: {
project: 'myproject2',
target: 'lint',
},
overrides: {},
parallelism: false,
outputs: [],
},
]
)
).toEqual(`target ${output.bold('lint')} for project myproject2`);
});

it('should handle multiple projects and targets', () => {
expect(
formatTargetsAndProjects(
['myproject', 'myproject2'],
['lint', 'build', 'test'],
[
{
id: 'myproject:build',
target: {
project: 'myproject',
target: 'build',
},
overrides: {},
parallelism: false,
outputs: [],
},
{
id: 'myproject2:build',
target: {
project: 'myproject2',
target: 'build',
},
overrides: {},
parallelism: false,
outputs: [],
},
]
)
).toEqual(`target ${output.bold('build')} for 2 projects`);

expect(
formatTargetsAndProjects(
['myproject', 'myproject2'],
['lint', 'build', 'test'],
[
{
id: 'myproject:lint',
target: {
project: 'myproject',
target: 'lint',
},
overrides: {},
parallelism: false,
outputs: [],
},
{
id: 'myproject2:lint',
target: {
project: 'myproject2',
target: 'lint',
},
overrides: {},
parallelism: false,
outputs: [],
},
]
)
).toEqual(`target ${output.bold('lint')} for 2 projects`);

expect(
formatTargetsAndProjects(
['myproject', 'myproject2'],
['lint', 'build', 'test'],
[
{
id: 'myproject:lint',
target: {
project: 'myproject',
target: 'lint',
},
overrides: {},
parallelism: false,
outputs: [],
},
{
id: 'myproject2:build',
target: {
project: 'myproject2',
target: 'build',
},
overrides: {},
parallelism: false,
outputs: [],
},
]
)
).toEqual(
`targets ${output.bold('lint')}, ${output.bold('build')} for 2 projects`
);
});

it('should handle dependent tasks', () => {
expect(
formatTargetsAndProjects(
['myproject', 'myproject2'],
['lint', 'build', 'test'],
[
{
id: 'myproject:build',
target: {
project: 'myproject',
target: 'build',
},
overrides: {},
parallelism: false,
outputs: [],
},
{
id: 'myproject3:build',
target: {
project: 'myproject3',
target: 'build',
},
overrides: {},
parallelism: false,
outputs: [],
},
]
)
).toEqual(
`target ${output.bold('build')} for project myproject and ${output.bold(
1
)} task it depends on`
);

expect(
formatTargetsAndProjects(
['myproject', 'myproject2'],
['lint', 'build', 'test'],
[
{
id: 'myproject:lint',
target: {
project: 'myproject',
target: 'lint',
},
overrides: {},
parallelism: false,
outputs: [],
},
{
id: 'myproject2:lint',
target: {
project: 'myproject2',
target: 'lint',
},
overrides: {},
parallelism: false,
outputs: [],
},
{
id: 'myproject3:lint',
target: {
project: 'myproject3',
target: 'lint',
},
overrides: {},
parallelism: false,
outputs: [],
},
]
)
).toEqual(
`target ${output.bold('lint')} for 2 projects and ${output.bold(
1
)} task they depend on`
);

expect(
formatTargetsAndProjects(
['myproject', 'myproject2'],
['lint', 'build', 'test'],
[
{
id: 'myproject:lint',
target: {
project: 'myproject',
target: 'lint',
},
overrides: {},
parallelism: false,
outputs: [],
},
{
id: 'myproject2:build',
target: {
project: 'myproject2',
target: 'build',
},
overrides: {},
parallelism: false,
outputs: [],
},
{
id: 'myproject3:build',
target: {
project: 'myproject3',
target: 'build',
},
overrides: {},
parallelism: false,
outputs: [],
},
{
id: 'myproject3:bundle',
target: {
project: 'myproject3',
target: 'bundle',
},
overrides: {},
parallelism: false,
outputs: [],
},
]
)
).toEqual(
`targets ${output.bold('lint')}, ${output.bold(
'build'
)} for 2 projects and ${output.bold(2)} tasks they depend on`
);
});
});
Loading