mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
test: standardized jest unit testing (#10047)
This commit is contained in:
@@ -143,7 +143,7 @@ If the commit reverts a previous commit, it should begin with `revert: `, follow
|
||||
Must be one of the following:
|
||||
|
||||
* **build**: Changes that affect the build system or external dependencies (example scopes: npm)
|
||||
* **ci**: Changes to our CI configuration files and scripts (example scopes: Travis, Jenkins)
|
||||
* **ci**: Changes to our CI configuration files and scripts
|
||||
* **docs**: Documentation only changes
|
||||
* **feat**: A new feature
|
||||
* **fix**: A bug fix
|
||||
|
||||
@@ -1,141 +1,87 @@
|
||||
Development Workflow
|
||||
====================
|
||||
|
||||
## Project Structure
|
||||
```bash
|
||||
# Setup local dependencies and repo for work
|
||||
npm run setup
|
||||
|
||||
The repository contains several packages and apps:
|
||||
- `nativescript-core` - The core NativeScript TypeScript modules used to develop NativeScript apps. Produces `@nativescript/core` npm package
|
||||
- `tns-core-modules-package` - Base for generating the `tns-core-modules` package (compatibility package for projects that still import code from `tns-core-modules`).
|
||||
- `tns-core-modules-widgets` - The native widgets (Java and Objective-C) used by the core NativeScript modules. Produces `tns-core-modules-widgets` npm package
|
||||
- `tns-platform-declarations` - TypeScript definitions for Android and iOS native APIs. Produces `tns-platform-declarations` npm package
|
||||
- `tests` - Unit tests app for the `@nativescript/core` package. These test are executed as nativescript application on mobile device or emulator.
|
||||
- `unit-test` - Node unit tests. These test validate parts of the framework that do not require the nativescript runtime and so can be executed in node environment
|
||||
- `e2e` - applications and *e2e* tests
|
||||
- `e2e/ui-tests-app` - UI app used for manual testing and automation
|
||||
- `apps` - legacy apps for testing
|
||||
- `build` - scripts used for building and infrastructure
|
||||
- `dist` - construction site for packing npm modules
|
||||
# See what commands you can run
|
||||
npm start
|
||||
```
|
||||
|
||||
Working with the repo is organized with npm scripts,
|
||||
go and read through the `scripts` section in the [package.json](./package.json).
|
||||
|
||||
Managing dependencies:
|
||||
- `tns-core-modules-widgets` depends on:
|
||||
- no deps
|
||||
- `@nativescript/core` depends on:
|
||||
- `tns-core-modules-widgets`
|
||||
- (devDep)`tns-platform-declarations`
|
||||
- `tns-core-modules` depends on:
|
||||
- `@nativescript/core`
|
||||
- (devDep)`tns-platform-declarations`
|
||||
To simplify workspace development and maintenance we provide an interactive menu via `npm start` which lists all the commands you can run. You can type to filter the list and hit ENTER to run. Each command invokes a [Nx](https://nx.dev) workspace command which you can even copy/paste to run directly if you don't want to use the interactive menu any longer.
|
||||
|
||||
## Initial Setup
|
||||
|
||||
Clone (or fork/clone) the repo and run setup script:
|
||||
|
||||
``` bash
|
||||
```bash
|
||||
git clone https://github.com/NativeScript/NativeScript.git
|
||||
cd NativeScript
|
||||
npm run setup
|
||||
```
|
||||
|
||||
## Running Unit Tests Application
|
||||
After the [initial setup](#initial-setup) you can run the tests with:
|
||||
## Unit Testing
|
||||
|
||||
``` bash
|
||||
cd tests
|
||||
tns run android | ios
|
||||
### Run unit tests with jest with either option:
|
||||
|
||||
A. Using convenient start menu:
|
||||
|
||||
```bash
|
||||
npm start
|
||||
> (Type) "core.test" (...to isolate the menu to "@nativescript.core.test"), hit ENTER
|
||||
```
|
||||
|
||||
B. Using direct Nx command:
|
||||
|
||||
```bash
|
||||
npx nx run core:test
|
||||
```
|
||||
|
||||
### Watch mode
|
||||
|
||||
To enable live watch mode you can add the `--watch` flag, for example:
|
||||
|
||||
```bash
|
||||
npx nx run core:test --watch
|
||||
```
|
||||
|
||||
### Isolate tests by name
|
||||
|
||||
Run a single test by it's decribe name, for example to run just the `xml/index.spec.ts`, the describe block is named `XmlParser` therefore:
|
||||
|
||||
```
|
||||
npx nx run core:test --watch -t 'XmlParser'
|
||||
```
|
||||
You can do changes in the test app and `nativescript-core` and rely on HMR to re-run tests.
|
||||
|
||||
## Running the `e2e` Test Apps
|
||||
|
||||
There are a couple of application used for development and testing.
|
||||
The `ui-test-app` is the more frequently used for development and validation. It is an ordinary NativeScript app that logs the test results on the go.
|
||||
* `apps/automated` Automated e2e tests
|
||||
* `apps/toolbox` Used for local development experimentation and confirming cases. More simplistic, use this one most often.
|
||||
* `apps/ui` Also used for local development experimentation and confirming cases. More sophisticated setup.
|
||||
|
||||
After the [initial setup](#initial-setup) run the e2e apps with:
|
||||
Run automated e2e test suite with:
|
||||
|
||||
``` bash
|
||||
cd e2e/<app-name>
|
||||
```bash
|
||||
npx nx run apps-automated:ios
|
||||
|
||||
# Run the Android app
|
||||
tns platform add android@next
|
||||
tns run android
|
||||
// or...
|
||||
|
||||
# Run the iOS app
|
||||
tns platform add ios@next
|
||||
tns run ios
|
||||
npx nx run apps-automated:android
|
||||
```
|
||||
|
||||
>Note: NOTE: do not commit changes in the runtime versions to `e2e/<app-name>/package.json`
|
||||
|
||||
---
|
||||
|
||||
## Running Another App
|
||||
|
||||
### TypeScript Applications
|
||||
Link both the `nativescript-core` folders and the generated compatibility package (`dist\tns-core-modules`):
|
||||
``` bash
|
||||
npm i <path-to-nativescript-repo>/nativescript-core --save
|
||||
npm i <path-to-nativescript-repo>/dist/tns-core-modules --save
|
||||
```
|
||||
|
||||
You can do changes in the app code and `nativescript-core` and rely on HMR to refresh the app.
|
||||
|
||||
### JavaScript Applications
|
||||
Use the same steps as with TS application. However, the configuration of JS application does not include loading and transpiling TS code. You need to transpile the TS code in `nativescript-core` yourself. The following npm script will run tsc in watch mode in `nativescript-core` (run it in a separate terminal so that you can do `tns run` in parallel):
|
||||
|
||||
``` bash
|
||||
npm run tsc-core-watch
|
||||
```
|
||||
|
||||
### Angular Applications
|
||||
Linking `tns-core-modules` and `@nativescript/core` in **Angular applications** does not work at the moment. Check [#7905](https://github.com/NativeScript/NativeScript/issues/7905) for more details on the issue.
|
||||
|
||||
|
||||
## Building `tns-core-modules-widgets`
|
||||
You can the following npm script to build and link the `tns-core-modules-widgets` package.
|
||||
``` bash
|
||||
npm run setup-widgets
|
||||
```
|
||||
|
||||
This script will build the `tns-core-modules-widgets` package and link it inside the `nativescript-core` so it will be used for running the tests and e2e apps.
|
||||
|
||||
>Note: NOTE: do not commit changes in the `tns-core-modules-widgets` dependency in the `nativescript-core/package.json`
|
||||
|
||||
## Running Node Unit Tests
|
||||
Run node unit tests with:
|
||||
```
|
||||
npm run unit-test
|
||||
```
|
||||
or run tests in watch mode:
|
||||
|
||||
```
|
||||
npm run unit-test-watch
|
||||
```
|
||||
|
||||
## Platform declarations
|
||||
To update the platform declarations (the ios.d.ts-es) you can run:
|
||||
|
||||
```
|
||||
npm install
|
||||
npm run dev-declarations
|
||||
```
|
||||
|
||||
This script will update the iOS declarations. Android tools are not integrated yet.
|
||||
The declarations are generated from the test app and will include the native code from tns-core-modules-widgets.
|
||||
|
||||
# Documentation API reference
|
||||
|
||||
The following will build the API reference pages in `bin/dist/apiref`:
|
||||
|
||||
```
|
||||
```bash
|
||||
npm run typedoc
|
||||
```
|
||||
|
||||
If you want to improve on the documentation you can also build and start up dev web server:
|
||||
|
||||
```
|
||||
```bash
|
||||
npm run dev-typedoc
|
||||
```
|
||||
|
||||
|
||||
6
tools/testing/assets/core.light.css
Normal file
6
tools/testing/assets/core.light.css
Normal file
File diff suppressed because one or more lines are too long
23
tools/testing/assets/what-is-new.ios.css
Normal file
23
tools/testing/assets/what-is-new.ios.css
Normal file
@@ -0,0 +1,23 @@
|
||||
@import url('~/views/what-is-new-common.css');
|
||||
|
||||
.news-card {
|
||||
margin: 12 12 0 12;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 14;
|
||||
}
|
||||
.body {
|
||||
font-size: 14;
|
||||
}
|
||||
.learn-more {
|
||||
font-size: 14;
|
||||
}
|
||||
.date {
|
||||
font-size: 12;
|
||||
}
|
||||
|
||||
.empty-placeholder {
|
||||
vertical-align: center;
|
||||
text-align: center;
|
||||
}
|
||||
3
tools/testing/out/.gitignore
vendored
Normal file
3
tools/testing/out/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
*.*
|
||||
!*.md
|
||||
!.gitignore
|
||||
2
tools/testing/out/README.md
Normal file
2
tools/testing/out/README.md
Normal file
@@ -0,0 +1,2 @@
|
||||
Some tests output .json files in attempt to serialize the CSS.
|
||||
These are used for reference during development, that's why the folder is gitignored.
|
||||
@@ -89,12 +89,8 @@ module.exports = {
|
||||
description: '@nativescript/core: Build'
|
||||
},
|
||||
test: {
|
||||
script: 'nx run core:unit',
|
||||
description: '@nativescript/core: Unit tests',
|
||||
watch: {
|
||||
script: 'nx run core:unit.watch',
|
||||
description: '@nativescript/core: Unit tests with watcher'
|
||||
},
|
||||
script: 'nx run core:test',
|
||||
description: '@nativescript/core: Unit tests'
|
||||
},
|
||||
},
|
||||
// @nativescript/core API Reference Docs
|
||||
|
||||
Reference in New Issue
Block a user