Skip to content

Commit

Permalink
feat(core): rework the tasks runner to use life cycle for printing me…
Browse files Browse the repository at this point in the history
…ssages
  • Loading branch information
vsavkin committed Nov 17, 2021
1 parent 9bedb80 commit e3c7b97
Show file tree
Hide file tree
Showing 39 changed files with 694 additions and 727 deletions.
6 changes: 0 additions & 6 deletions docs/angular/cli/affected-build.md
Expand Up @@ -18,12 +18,6 @@ Run build in parallel:
nx affected:build --parallel=5
```

Rerun the build target only for the projects that failed last time:

```bash
nx affected:build --only-failed
```

Run the build target for all projects:

```bash
Expand Down
6 changes: 0 additions & 6 deletions docs/angular/cli/affected-e2e.md
Expand Up @@ -18,12 +18,6 @@ Run tests in parallel:
nx affected:e2e --parallel=5
```

Rerun the test target only for the projects that failed last time:

```bash
nx affected:e2e --only-failed
```

Run the test target for all projects:

```bash
Expand Down
6 changes: 0 additions & 6 deletions docs/angular/cli/affected-lint.md
Expand Up @@ -18,12 +18,6 @@ Run lint in parallel:
nx affected:lint --parallel=5
```

Rerun the lint target only for the projects that failed last time:

```bash
nx affected:lint --only-failed
```

Run the lint target for all projects:

```bash
Expand Down
6 changes: 0 additions & 6 deletions docs/angular/cli/affected-test.md
Expand Up @@ -18,12 +18,6 @@ Run tests in parallel:
nx affected:test --parallel=5
```

Rerun the test target only for the projects that failed last time:

```bash
nx affected:test --only-failed
```

Run the test target for all projects:

```bash
Expand Down
6 changes: 0 additions & 6 deletions docs/angular/cli/affected.md
Expand Up @@ -24,12 +24,6 @@ Run tests in parallel:
nx affected --target=test --parallel=5
```

Rerun the test target only for the projects that failed last time:

```bash
nx affected --target=test --only-failed
```

Run the test target for all projects:

```bash
Expand Down
6 changes: 0 additions & 6 deletions docs/node/cli/affected-build.md
Expand Up @@ -18,12 +18,6 @@ Run build in parallel:
nx affected:build --parallel=5
```

Rerun the build target only for the projects that failed last time:

```bash
nx affected:build --only-failed
```

Run the build target for all projects:

```bash
Expand Down
6 changes: 0 additions & 6 deletions docs/node/cli/affected-e2e.md
Expand Up @@ -18,12 +18,6 @@ Run tests in parallel:
nx affected:e2e --parallel=5
```

Rerun the test target only for the projects that failed last time:

```bash
nx affected:e2e --only-failed
```

Run the test target for all projects:

```bash
Expand Down
6 changes: 0 additions & 6 deletions docs/node/cli/affected-lint.md
Expand Up @@ -18,12 +18,6 @@ Run lint in parallel:
nx affected:lint --parallel=5
```

Rerun the lint target only for the projects that failed last time:

```bash
nx affected:lint --only-failed
```

Run the lint target for all projects:

```bash
Expand Down
6 changes: 0 additions & 6 deletions docs/node/cli/affected-test.md
Expand Up @@ -18,12 +18,6 @@ Run tests in parallel:
nx affected:test --parallel=5
```

Rerun the test target only for the projects that failed last time:

```bash
nx affected:test --only-failed
```

Run the test target for all projects:

```bash
Expand Down
6 changes: 0 additions & 6 deletions docs/node/cli/affected.md
Expand Up @@ -24,12 +24,6 @@ Run tests in parallel:
nx affected --target=test --parallel=5
```

Rerun the test target only for the projects that failed last time:

```bash
nx affected --target=test --only-failed
```

Run the test target for all projects:

```bash
Expand Down
6 changes: 0 additions & 6 deletions docs/react/cli/affected-build.md
Expand Up @@ -18,12 +18,6 @@ Run build in parallel:
nx affected:build --parallel=5
```

Rerun the build target only for the projects that failed last time:

```bash
nx affected:build --only-failed
```

Run the build target for all projects:

```bash
Expand Down
6 changes: 0 additions & 6 deletions docs/react/cli/affected-e2e.md
Expand Up @@ -18,12 +18,6 @@ Run tests in parallel:
nx affected:e2e --parallel=5
```

Rerun the test target only for the projects that failed last time:

```bash
nx affected:e2e --only-failed
```

Run the test target for all projects:

```bash
Expand Down
6 changes: 0 additions & 6 deletions docs/react/cli/affected-lint.md
Expand Up @@ -18,12 +18,6 @@ Run lint in parallel:
nx affected:lint --parallel=5
```

Rerun the lint target only for the projects that failed last time:

```bash
nx affected:lint --only-failed
```

Run the lint target for all projects:

```bash
Expand Down
6 changes: 0 additions & 6 deletions docs/react/cli/affected-test.md
Expand Up @@ -18,12 +18,6 @@ Run tests in parallel:
nx affected:test --parallel=5
```

Rerun the test target only for the projects that failed last time:

```bash
nx affected:test --only-failed
```

Run the test target for all projects:

```bash
Expand Down
6 changes: 0 additions & 6 deletions docs/react/cli/affected.md
Expand Up @@ -24,12 +24,6 @@ Run tests in parallel:
nx affected --target=test --parallel=5
```

Rerun the test target only for the projects that failed last time:

```bash
nx affected --target=test --only-failed
```

Run the test target for all projects:

```bash
Expand Down
72 changes: 0 additions & 72 deletions e2e/workspace-integrations/src/workspace.test.ts
Expand Up @@ -271,50 +271,6 @@ describe('run-many', () => {
});
expect(buildWithDaemon).toContain(`Running target "build" succeeded`);
}, 1000000);

it('should run only failed projects', () => {
const myapp = uniq('myapp');
const myapp2 = uniq('myapp2');
runCLI(`generate @nrwl/angular:app ${myapp}`);
runCLI(`generate @nrwl/angular:app ${myapp2}`);

// set broken test for myapp
updateFile(
`apps/${myapp}/src/app/app.component.spec.ts`,
`
describe('sample test', () => {
it('should test', () => {
expect(1).toEqual(2);
});
});
`
);

const failedTests = runCLI(`run-many --target=test --all`, {
silenceError: true,
});
expect(failedTests).toContain(`Running target test for 2 project(s):`);
expect(failedTests).toContain(`- ${myapp}`);
expect(failedTests).toContain(`- ${myapp2}`);
expect(failedTests).toContain(`Failed tasks:`);

// Fix failing Unit Test
updateFile(
`apps/${myapp}/src/app/app.component.spec.ts`,
readFile(`apps/${myapp}/src/app/app.component.spec.ts`).replace(
'.toEqual(2)',
'.toEqual(1)'
)
);

const isolatedTests = runCLI(`run-many --target=test --all --only-failed`);
expect(isolatedTests).toContain(`Running target test for 1 project(s)`);
expect(isolatedTests).toContain(`- ${myapp}`);
expect(isolatedTests).not.toContain(`- ${myapp2}`);

const interpolatedTests = runCLI(`run-many --target=test --all`);
expect(interpolatedTests).toContain(`Running target \"test\" succeeded`);
}, 1000000);
});

describe('affected:*', () => {
Expand Down Expand Up @@ -447,23 +403,6 @@ describe('affected:*', () => {
expect(failedTests).toContain(`- ${myapp}`);
expect(failedTests).toContain(`- ${mypublishablelib}`);
expect(failedTests).toContain(`Failed tasks:`);
expect(failedTests).toContain(
'You can isolate the above projects by passing: --only-failed'
);
expect(
readJson(
`${
process.env.NX_CACHE_DIRECTORY ?? 'node_modules/.cache/nx'
}/results.json`
)
).toEqual({
command: 'test',
results: {
[myapp]: false,
[mylib]: true,
[mypublishablelib]: true,
},
});

// Fix failing Unit Test
updateFile(
Expand All @@ -473,17 +412,6 @@ describe('affected:*', () => {
'.toEqual(1)'
)
);

const isolatedTests = runCLI(
`affected:test --files="libs/${mylib}/src/index.ts" --only-failed`
);
expect(isolatedTests).toContain(`Running target test for 1 project(s)`);
expect(isolatedTests).toContain(`- ${myapp}`);

const interpolatedTests = runCLI(
`affected --target test --files="libs/${mylib}/src/index.ts" --jest-config {project.root}/jest.config.js`
);
expect(interpolatedTests).toContain(`Running target \"test\" succeeded`);
}, 1000000);
});

Expand Down
6 changes: 2 additions & 4 deletions packages/workspace/src/command-line/affected.ts
Expand Up @@ -11,19 +11,17 @@ import {
ProjectGraphNode,
ProjectGraphProjectNode,
} from '@nrwl/devkit';
import { DefaultReporter } from '../tasks-runner/default-reporter';
import { runCommand } from '../tasks-runner/run-command';
import { output } from '../utilities/output';
import { projectHasTarget } from '../utilities/project-graph-utils';
import { generateGraph } from './dep-graph';
import { printAffected } from './print-affected';
import { connectToNxCloudUsingScan } from './connect-to-nx-cloud';
import { parseFiles } from './shared';
import { splitArgsIntoNxArgsAndOverrides } from './utils';
import type { NxArgs, RawNxArgs } from './utils';
import { splitArgsIntoNxArgsAndOverrides } from './utils';
import { performance } from 'perf_hooks';
import type { Environment } from '../core/shared-interfaces';
import { EmptyReporter } from '../tasks-runner/empty-reporter';

export async function affected(
command: 'apps' | 'libs' | 'dep-graph' | 'print-affected' | 'affected',
Expand Down Expand Up @@ -122,7 +120,7 @@ export async function affected(
env,
nxArgs,
overrides,
nxArgs.hideCachedOutput ? new EmptyReporter() : new DefaultReporter(),
nxArgs.hideCachedOutput ? 'hide-cached-output' : 'default',
null
);
break;
Expand Down
25 changes: 0 additions & 25 deletions packages/workspace/src/command-line/examples.ts
Expand Up @@ -40,11 +40,6 @@ export const examples: Record<string, Example[]> = {
command: 'affected --target=test --parallel=5',
description: 'Run tests in parallel',
},
{
command: 'affected --target=test --only-failed',
description:
'Rerun the test target only for the projects that failed last time',
},
{
command: 'affected --target=test --all',
description: 'Run the test target for all projects',
Expand All @@ -70,11 +65,6 @@ export const examples: Record<string, Example[]> = {
command: 'affected:test --parallel=5',
description: 'Run tests in parallel',
},
{
command: 'affected:test --only-failed',
description:
'Rerun the test target only for the projects that failed last time',
},
{
command: 'affected:test --all',
description: 'Run the test target for all projects',
Expand All @@ -100,11 +90,6 @@ export const examples: Record<string, Example[]> = {
command: 'affected:build --parallel=5',
description: 'Run build in parallel',
},
{
command: 'affected:build --only-failed',
description:
'Rerun the build target only for the projects that failed last time',
},
{
command: 'affected:build --all',
description: 'Run the build target for all projects',
Expand All @@ -130,11 +115,6 @@ export const examples: Record<string, Example[]> = {
command: 'affected:e2e --parallel=5',
description: 'Run tests in parallel',
},
{
command: 'affected:e2e --only-failed',
description:
'Rerun the test target only for the projects that failed last time',
},
{
command: 'affected:e2e --all',
description: 'Run the test target for all projects',
Expand All @@ -160,11 +140,6 @@ export const examples: Record<string, Example[]> = {
command: 'affected:lint --parallel=5',
description: 'Run lint in parallel',
},
{
command: 'affected:lint --only-failed',
description:
'Rerun the lint target only for the projects that failed last time',
},
{
command: 'affected:lint --all',
description: 'Run the lint target for all projects',
Expand Down

1 comment on commit e3c7b97

@vercel
Copy link

@vercel vercel bot commented on e3c7b97 Nov 17, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.