6.4 KiB
Using Modern Tools
Using Nx, you can add Cypress, Jest, Prettier, and Nest into your dev workflow.
Of course, it's not the case that Cypress is always better than Protractor or Nest is always better than say Express. There are tradeoffs. But in many situations, for many projects, these innovative tools offer a lot of advantages.
Nest
Nest is a Node.js framework designed for building scalable server-side applications.
To create a new Nest application, run:
yarn add --dev @nrwl/nest # Add Nest Capabilities to a workspace
yarn g @nrwl/nest:application api # Create a Nest App
This will create the following:
<workspace name>/
├── apps/
│ └── api/
│ ├── jest.conf.js
│ ├── proxy.conf.json
│ ├── src/
│ │ ├── app/
│ │ │ ├── app.controller.ts
│ │ │ ├── app.controller.spec.ts
│ │ │ ├── app.module.ts
│ │ │ ├── app.service.ts
│ │ │ └── app.service.spec.ts
│ │ ├── assets/
│ │ ├── environments/
│ │ └── main.ts
│ ├── tsconfig.app.json
│ ├── tsconfig.json
│ ├── tsconfig.spec.json
│ └── tslint.json
├── libs/
├── workspace.json
├── nx.json
├── package.json
├── tools/
├── tsconfig.json
└── tslint.json
You can run:
ng serve apito serve the applicationng build apito build the applicationng test apito test the application
Adding a Nest app will also add Nest schematics to the workspace, which you can run as follows:
ng generate @nestjs/schematics:controller mycontroller --sourceRoot=apps/nestapp/src --path=app
Read more about Nest at nestjs.com.
Using Express
To create an express application, run:
yarn add --dev @nrwl/express # Add Express Capabilities to a workspace
ng g @nrwl/express:application api # Create an Express Application
Using Other Frameworks
To create an empty node application, run:
yarn add --dev @nrwl/node # Add Node Capabilities to a workspace
ng g @nrwl/node:application api # Create a Node Application
Cypress
Cypress is an e2e test runner built for modern web. It has a lot of great features:
- Time travel
- Real time reloads
- Automatic waiting
- Spies, stubs, and clocks
- Network traffic control
- Screenshots and videos
By default, when creating a new web application, Nx will use Cypress to create the e2e tests project.
So running ng g @nrwl/web:application frontend will create:
<workspace name>/
├── apps/
│ ├── myapp/
│ │ ├── src/
│ │ │ ├── app/
│ │ │ ├── assets/
│ │ │ ├── environments/
│ │ │ ├── favicon.ico
│ │ │ ├── index.html
│ │ │ ├── main.ts
│ │ │ ├── polyfills.ts
│ │ │ └── styles.css
│ │ ├── browserslist
│ │ ├── jest.config.js
│ │ ├── tsconfig.app.json
│ │ ├── tsconfig.json
│ │ ├── tsconfig.spec.json
│ │ └── tslint.json
│ └── myapp-e2e/
│ ├── src/
│ │ ├── fixtures/
│ │ │ └── example.json
│ │ ├── integration/
│ │ │ └── app.spec.ts
│ │ ├── plugins/
│ │ │ └── index.ts
│ │ └── support/
│ │ ├── app.po.ts
│ │ ├── commands.ts
│ │ └── index.ts
│ ├── cypress.json
│ ├── tsconfig.e2e.json
│ ├── tsconfig.json
│ └── tslint.json
├── libs/
├── tools/
├── README.md
├── workspace.json
├── nx.json
├── package.json
├── tsconfig.json
└── tslint.json
You can run:
ng e2e frontend-e2eto run e2e testsng e2e frontend-e2e --watchto run e2e tests in the watch modeng e2e frontend-e2e --headlessto run e2e tests in the headless mode (used in CI)
Read more about Cypress at cypress.io.
Jest
Jest is a fast 0-setup testing framework from Facebook.
By default, Nx uses Jest for both Web and Node.js applications. So if you run ng g application frontend, you will get:
<workspace name>/
├── apps/
│ ├── frontend/
│ │ ├── src/
│ │ │ ├── app/
│ │ │ ├── assets/
│ │ │ ├── environments/
│ │ │ ├── favicon.ico
│ │ │ ├── index.html
│ │ │ ├── main.tsx
│ │ │ ├── polyfills.ts
│ │ │ └── styles.css
│ │ ├── browserslist
│ │ ├── jest.config.js
│ │ ├── tsconfig.app.json
│ │ ├── tsconfig.json
│ │ ├── tsconfig.spec.json
│ │ └── tslint.json
│ └── frontend-e2e/
├── libs/
├── tools/
├── README.md
├── workspace.json
├── nx.json
├── package.json
├── tsconfig.json
└── tslint.json
Read more about Jest at jestjs.io.
Prettier
Prettier is an opinionated code formatter. An Nx workspace comes with Prettier preconfigured.
<workspace name>/
├── apps/
├── libs/
├── tools/
├── workspace.json
├── nx.json
├── README.md
├── package.json
├── .prettierrc # prettier config
├── .prettierignore # config to ignore files from prettier
├── tsconfig.json
└── tslint.json
You can run:
yarn format:writeto format the filesyarn format:checkto check the formatted files
Read more about Prettier.



