Skip to content

Commit

Permalink
cleanup(angular): speed up e2e-angular-core tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leosvelperez committed Mar 20, 2023
1 parent bcca1f5 commit 85aee88
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 288 deletions.
112 changes: 51 additions & 61 deletions e2e/angular-core/src/angular-linting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,73 +7,63 @@ import {
} from '@nrwl/e2e/utils';
import * as path from 'path';

describe('Angular Package', () => {
describe('linting', () => {
beforeAll(() => newProject());
afterAll(() => cleanupProject());
describe('linting', () => {
beforeAll(() => newProject());
afterAll(() => cleanupProject());

it('should support eslint and pass linting on the standard generated code', async () => {
const myapp = uniq('myapp');
runCLI(
`generate @nrwl/angular:app ${myapp} --linter=eslint --no-interactive`
);
expect(runCLI(`lint ${myapp}`)).toContain('All files pass linting.');
it('should lint correctly with eslint and handle external HTML files and inline templates', async () => {
const app = uniq('app');
const lib = uniq('lib');

const mylib = uniq('mylib');
runCLI(
`generate @nrwl/angular:lib ${mylib} --linter=eslint --no-interactive`
);
expect(runCLI(`lint ${mylib}`)).toContain('All files pass linting.');
});
runCLI(
`generate @nrwl/angular:app ${app} --linter=eslint --no-interactive`
);
runCLI(
`generate @nrwl/angular:lib ${lib} --linter=eslint --no-interactive`
);

it('should support eslint and successfully lint external HTML files and inline templates', async () => {
const myapp = uniq('myapp');
// check app and lib pass linting for initial generated code
expect(runCLI(`lint ${app}`)).toContain('All files pass linting.');
expect(runCLI(`lint ${lib}`)).toContain('All files pass linting.');

runCLI(
`generate @nrwl/angular:app ${myapp} --linter=eslint --no-interactive`
);
// External HTML template file
const templateWhichFailsBananaInBoxLintCheck = `<div ([foo])="bar"></div>`;
updateFile(
`apps/${app}/src/app/app.component.html`,
templateWhichFailsBananaInBoxLintCheck
);
// Inline template within component.ts file
const wrappedAsInlineTemplate = `
import { Component } from '@angular/core';
const templateWhichFailsBananaInBoxLintCheck = `<div ([foo])="bar"></div>`;
const wrappedAsInlineTemplate = `
import { Component } from '@angular/core';
@Component({
selector: 'inline-template-component',
template: \`
${templateWhichFailsBananaInBoxLintCheck}
\`,
})
export class InlineTemplateComponent {}
`;
updateFile(
`apps/${app}/src/app/inline-template.component.ts`,
wrappedAsInlineTemplate
);

@Component({
selector: 'inline-template-component',
template: \`
${templateWhichFailsBananaInBoxLintCheck}
\`,
})
export class InlineTemplateComponent {}
`;
const appLintStdOut = runCLI(`lint ${app}`, { silenceError: true });
expect(appLintStdOut).toContain(
path.normalize(`apps/${app}/src/app/app.component.html`)
);
expect(appLintStdOut).toContain(`1:6`);
expect(appLintStdOut).toContain(`Invalid binding syntax`);
expect(appLintStdOut).toContain(
path.normalize(`apps/${app}/src/app/inline-template.component.ts`)
);

// External HTML template file
updateFile(
`apps/${myapp}/src/app/app.component.html`,
templateWhichFailsBananaInBoxLintCheck
);

// Inline template within component.ts file
updateFile(
`apps/${myapp}/src/app/inline-template.component.ts`,
wrappedAsInlineTemplate
);

const appLintStdOut = runCLI(`lint ${myapp}`, { silenceError: true });
expect(appLintStdOut).toContain(
path.normalize(`apps/${myapp}/src/app/app.component.html`)
);
expect(appLintStdOut).toContain(`1:6`);
expect(appLintStdOut).toContain(`Invalid binding syntax`);
expect(appLintStdOut).toContain(
path.normalize(`apps/${myapp}/src/app/inline-template.component.ts`)
);

expect(appLintStdOut).toContain(`5:21`);
expect(appLintStdOut).toContain(
`The selector should start with one of these prefixes`
);
expect(appLintStdOut).toContain(`7:18`);
expect(appLintStdOut).toContain(`Invalid binding syntax`);
});
expect(appLintStdOut).toContain(`5:19`);
expect(appLintStdOut).toContain(
`The selector should start with one of these prefixes`
);
expect(appLintStdOut).toContain(`7:16`);
expect(appLintStdOut).toContain(`Invalid binding syntax`);
});
});
Loading

0 comments on commit 85aee88

Please sign in to comment.