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

feat(core): always use nx cli to invoke generators and execute tasks #4121

Merged
merged 1 commit into from
Nov 20, 2020
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
65 changes: 30 additions & 35 deletions e2e/angular/src/angular-app.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { toClassName } from '@nrwl/workspace';
import {
forEachCli,
newProject,
readFile,
readJson,
Expand All @@ -9,26 +8,25 @@ import {
updateFile,
} from '@nrwl/e2e/utils';

forEachCli('angular', (cli) => {
describe('Angular Nrwl app builder', () => {
let app;
let buildableLib;
describe('Angular Nrwl app builder', () => {
let app;
let buildableLib;

beforeEach(() => {
app = uniq('app');
buildableLib = uniq('buildlib1');
beforeEach(() => {
app = uniq('app');
buildableLib = uniq('buildlib1');

newProject();
newProject();

runCLI(`generate @nrwl/angular:app ${app} --style=css --no-interactive`);
runCLI(
`generate @nrwl/angular:library ${buildableLib} --buildable=true --no-interactive`
);
runCLI(`generate @nrwl/angular:app ${app} --style=css --no-interactive`);
runCLI(
`generate @nrwl/angular:library ${buildableLib} --buildable=true --no-interactive`
);

// update the app module to include a ref to the buildable lib
updateFile(
`apps/${app}/src/app/app.module.ts`,
`
// update the app module to include a ref to the buildable lib
updateFile(
`apps/${app}/src/app/app.module.ts`,
`
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import {${toClassName(
Expand All @@ -45,26 +43,23 @@ forEachCli('angular', (cli) => {
})
export class AppModule {}
`
);
);

// update the angular.json
const workspaceJson = readJson(`angular.json`);
workspaceJson.projects[app].architect.build.builder =
'@nrwl/angular:webpack-browser';
updateFile('angular.json', JSON.stringify(workspaceJson, null, 2));
});
// update the angular.json
const workspaceJson = readJson(`angular.json`);
workspaceJson.projects[app].architect.build.builder =
'@nrwl/angular:webpack-browser';
updateFile('angular.json', JSON.stringify(workspaceJson, null, 2));
});

it('should build the dependent buildable lib as well as the app', () => {
const libOutput = runCLI(`build ${app} --with-deps`);
expect(libOutput).toContain(
`Building entry point '@proj/${buildableLib}'`
);
expect(libOutput).toContain(`ng run ${app}:build`);
it('should build the dependent buildable lib as well as the app', () => {
const libOutput = runCLI(`build ${app} --with-deps`);
expect(libOutput).toContain(`Building entry point '@proj/${buildableLib}'`);
expect(libOutput).toContain(`nx run ${app}:build`);

// to proof it has been built from source the "main.js" should actually contain
// the path to dist
const mainBundle = readFile(`dist/apps/${app}/main.js`);
expect(mainBundle).toContain(`dist/libs/${buildableLib}`);
});
// to proof it has been built from source the "main.js" should actually contain
// the path to dist
const mainBundle = readFile(`dist/apps/${app}/main.js`);
expect(mainBundle).toContain(`dist/libs/${buildableLib}`);
});
});
201 changes: 99 additions & 102 deletions e2e/angular/src/angular-core.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
checkFilesExist,
expectTestsPass,
forEachCli,
getSize,
newProject,
runCLI,
Expand All @@ -12,25 +11,24 @@ import {
} from '@nrwl/e2e/utils';
import { toClassName } from '@nrwl/workspace';

forEachCli(() => {
describe('Angular Package', () => {
beforeEach(() => {
newProject();
});

it('should work', async () => {
const myapp = uniq('myapp');
const mylib = uniq('mylib');
runCLI(
`generate @nrwl/angular:app ${myapp} --directory=myDir --no-interactive`
);
runCLI(
`generate @nrwl/angular:lib ${mylib} --directory=myDir --add-module-spec --no-interactive`
);

updateFile(
`apps/my-dir/${myapp}/src/app/app.module.ts`,
`
describe('Angular Package', () => {
beforeEach(() => {
newProject();
});

it('should work', async () => {
const myapp = uniq('myapp');
const mylib = uniq('mylib');
runCLI(
`generate @nrwl/angular:app ${myapp} --directory=myDir --no-interactive`
);
runCLI(
`generate @nrwl/angular:lib ${mylib} --directory=myDir --add-module-spec --no-interactive`
);

updateFile(
`apps/my-dir/${myapp}/src/app/app.module.ts`,
`
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { MyDir${toClassName(
Expand All @@ -45,87 +43,86 @@ forEachCli(() => {
})
export class AppModule {}
`
);
runCLI(`build my-dir-${myapp} --prod --output-hashing none`);

checkFilesExist(`dist/apps/my-dir/${myapp}/main.js`);

// This is a loose requirement because there are a lot of
// influences external from this project that affect this.
const es2015BundleSize = getSize(
tmpProjPath(`dist/apps/my-dir/${myapp}/main.js`)
);
console.log(
`The current es2015 bundle size is ${es2015BundleSize / 1000} KB`
);
expect(es2015BundleSize).toBeLessThanOrEqual(125000);

// running tests for the app
expectTestsPass(await runCLIAsync(`test my-dir-${myapp} --no-watch`));

// running tests for the lib
expectTestsPass(await runCLIAsync(`test my-dir-${mylib} --no-watch`));

// if (supportUi()) {
// try {
// const r = runCLI(`e2e my-dir-${myapp}-e2e --headless --no-watch`);
// console.log(r);
// expect(r).toContain('All specs passed!');
// } catch (e) {
// console.log(e);
// if (e.stdout) {
// console.log(e.stdout.toString());
// }
// if (e.stderr) {
// console.log(e.stdout.toString());
// }
// throw e;
// }
// }
}, 1000000);

it('should support router config generation (lazy)', async () => {
const myapp = uniq('myapp');
const mylib = uniq('mylib');
runCLI(`generate @nrwl/angular:app ${myapp} --directory=myDir --routing`);
runCLI(
`generate @nrwl/angular:lib ${mylib} --directory=myDir --routing --lazy --parentModule=apps/my-dir/${myapp}/src/app/app.module.ts`
);

runCLI(`build my-dir-${myapp} --aot`);
expectTestsPass(await runCLIAsync(`test my-dir-${myapp} --no-watch`));
}, 1000000);

it('should support router config generation (eager)', async () => {
const myapp = uniq('myapp');
runCLI(`generate @nrwl/angular:app ${myapp} --directory=myDir --routing`);
const mylib = uniq('mylib');
runCLI(
`generate @nrwl/angular:lib ${mylib} --directory=myDir --routing --parentModule=apps/my-dir/${myapp}/src/app/app.module.ts`
);

runCLI(`build my-dir-${myapp} --aot`);
expectTestsPass(await runCLIAsync(`test my-dir-${myapp} --no-watch`));
}, 1000000);

it('should support Ivy', async () => {
const myapp = uniq('myapp');
runCLI(
`generate @nrwl/angular:app ${myapp} --directory=myDir --routing --enable-ivy`
);

runCLI(`build my-dir-${myapp} --aot`);
expectTestsPass(await runCLIAsync(`test my-dir-${myapp} --no-watch`));
}, 1000000);

it('should support eslint', async () => {
const myapp = uniq('myapp');
runCLI(`generate @nrwl/angular:app ${myapp} --linter=eslint`);
expect(runCLI(`lint ${myapp}`)).toContain('All files pass linting.');

const mylib = uniq('mylib');
runCLI(`generate @nrwl/angular:lib ${mylib} --linter=eslint`);
expect(runCLI(`lint ${mylib}`)).toContain('All files pass linting.');
});
);
runCLI(`build my-dir-${myapp} --prod --output-hashing none`);

checkFilesExist(`dist/apps/my-dir/${myapp}/main.js`);

// This is a loose requirement because there are a lot of
// influences external from this project that affect this.
const es2015BundleSize = getSize(
tmpProjPath(`dist/apps/my-dir/${myapp}/main.js`)
);
console.log(
`The current es2015 bundle size is ${es2015BundleSize / 1000} KB`
);
expect(es2015BundleSize).toBeLessThanOrEqual(125000);

// running tests for the app
expectTestsPass(await runCLIAsync(`test my-dir-${myapp} --no-watch`));

// running tests for the lib
expectTestsPass(await runCLIAsync(`test my-dir-${mylib} --no-watch`));

// if (supportUi()) {
// try {
// const r = runCLI(`e2e my-dir-${myapp}-e2e --headless --no-watch`);
// console.log(r);
// expect(r).toContain('All specs passed!');
// } catch (e) {
// console.log(e);
// if (e.stdout) {
// console.log(e.stdout.toString());
// }
// if (e.stderr) {
// console.log(e.stdout.toString());
// }
// throw e;
// }
// }
}, 1000000);

it('should support router config generation (lazy)', async () => {
const myapp = uniq('myapp');
const mylib = uniq('mylib');
runCLI(`generate @nrwl/angular:app ${myapp} --directory=myDir --routing`);
runCLI(
`generate @nrwl/angular:lib ${mylib} --directory=myDir --routing --lazy --parentModule=apps/my-dir/${myapp}/src/app/app.module.ts`
);

runCLI(`build my-dir-${myapp} --aot`);
expectTestsPass(await runCLIAsync(`test my-dir-${myapp} --no-watch`));
}, 1000000);

it('should support router config generation (eager)', async () => {
const myapp = uniq('myapp');
runCLI(`generate @nrwl/angular:app ${myapp} --directory=myDir --routing`);
const mylib = uniq('mylib');
runCLI(
`generate @nrwl/angular:lib ${mylib} --directory=myDir --routing --parentModule=apps/my-dir/${myapp}/src/app/app.module.ts`
);

runCLI(`build my-dir-${myapp} --aot`);
expectTestsPass(await runCLIAsync(`test my-dir-${myapp} --no-watch`));
}, 1000000);

it('should support Ivy', async () => {
const myapp = uniq('myapp');
runCLI(
`generate @nrwl/angular:app ${myapp} --directory=myDir --routing --enable-ivy`
);

runCLI(`build my-dir-${myapp} --aot`);
expectTestsPass(await runCLIAsync(`test my-dir-${myapp} --no-watch`));
}, 1000000);

it('should support eslint', async () => {
const myapp = uniq('myapp');
runCLI(`generate @nrwl/angular:app ${myapp} --linter=eslint`);
expect(runCLI(`lint ${myapp}`)).toContain('All files pass linting.');

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