* docs(react): update react tutorial text * docs(react): fixes to computation cache lesson * docs(react): reworking react tutorial * docs(react): fixing broken links in tutorial * docs(react): fixing broken more links in tutorial * docs(react): fixing last broken link in tutorial * docs(react): really fixing last broken link in tutorial * fixing images in preview * docs(react): cleaning up text and formatting issues * docs(react): more fixes and cleanup * docs(react): more fixes * docs(react): fixing nx console broken links * docs(react): adjusting ending summary cards * docs(react): more typo fixes * docs(react): incorporating victor and isaac's feedback * docs(react): fixing broken link * docs(react): a self-round of typo and formatting fixes * docs(react): another round of formatting fixes * docs(react): another small change * docs(react): another typo fix * docs(react): more typo fixed noticed working with node tutorial * docs(react): making h1's consistent * docs(react): fixing tab title for part 1 * docs(react): fixing the title * docs(react): escaping colon in title * docs(node): copying react tutorials as starting point * docs(node): fixing map.json and links to other lessons * docs(node): updating the copy-pasted react tutorial for the node example * docs(node): more fixes after self-review * docs(node): fixing another typo * docs(node): Making h1's consistent * docs(node): fixing tab title in step 1 * docs(node): fixing the title * docs(node): escaping colon in title * docs(core): nx graph => project graph * docs(core): fixing titles * docs(core): further shortening the text * docs(core): formatting fixes * docs(core): responding to victor comments * docs(core): switching to new terminal code blocks * docs(core): light and dark mode friendly images
5.3 KiB
Node Tutorial - Part 3: Task-Running
Common tasks include:
- Building an application
- Serving an application locally for development purposes
- Running your unit tests
- Linting your code
When you ran your generators in Part 1, you already set up these more common tasks for each project.
Defining Targets
Here's the project.json file for your products-data-client project:
{
"name": "products-data-client",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/products-data-client/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nrwl/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/libs/products-data-client",
"main": "libs/products-data-client/src/index.ts",
"tsConfig": "libs/products-data-client/tsconfig.lib.json",
"assets": ["libs/products-data-client/*.md"]
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["libs/products-data-client/**/*.ts"]
}
},
"test": {
"executor": "@nrwl/jest:jest",
"outputs": ["coverage/libs/products-data-client"],
"options": {
"jestConfig": "libs/products-data-client/jest.config.ts",
"passWithNoTests": true
}
}
},
"tags": []
}
You can see that three targets are defined here: build, lint and test.
The properties inside each of these these targets is defined as follows:
executor- which Nx executor to run. The syntax here is:<plugin name>:<executor name>outputs- this is an array of files that would be created by running this target. (This informs Nx on what to save for it's caching mechanisms you'll learn about in 4 - Workspace Optimizations).options- this is an object defining which executor options to use for the given target. Every Nx executor allows for options as a way to parameterize it's functionality.
Running Tasks
Run the build target for your products-data-client project:
> nx run products-data-client:build
Compiling TypeScript files for project "products-data-client"...
Done compiling TypeScript files for project "products-data-client".
———————————————————————————————————————————————————————————————————————————————————————————————
> NX Successfully ran target build for project products-data-client (780ms)
You can now find your built products-data-client distributable in your dist/libs/products-data-client directory, as specified in the outputPath property of the build target options in your project.json file.
Next, run a lint check on products-data-client:
> nx run products-data-client:lint
Linting "products-data-client"...
All files pass linting.
———————————————————————————————————————————————————————————————————————————————————————————————
> NX Successfully ran target lint for project products-data-client (777ms)
Next, add some tests to your data client in the products-data-client.spec.ts file:
import {
createProductsDataClient,
exampleProducts,
} from './products-data-client';
describe('productsDataClient', () => {
it('should get all example products', async () => {
const productsDataClient = createProductsDataClient();
const products = await productsDataClient.getProducts();
expect(products).toEqual(Object.values(exampleProducts));
});
it('should get example product by id', async () => {
const productsDataClient = createProductsDataClient();
const product = await productsDataClient.getProductById('1');
expect(product).toEqual(exampleProducts['1']);
});
});
And then run your test target:
> nx run products-data-client:test
PASS products-data-client libs/products-data-client/src/lib/products-data-client.spec.ts
productsDataClient
✓ should get all example products (1 ms)
✓ should get example product by id
Test Suites: 1 passed, 1 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: 0.843 s
Ran all test suites.
———————————————————————————————————————————————————————————————————————————————————————————————
> NX Successfully ran target test for project products-data-client (2s)
What's Next
- Continue to 4: Workspace Optimization
