Skip to content

Commit

Permalink
Merge pull request #41 from briebug/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
schuchard authored Sep 25, 2020
2 parents 428774f + 599664e commit 64f8377
Show file tree
Hide file tree
Showing 94 changed files with 18,138 additions and 1,108 deletions.
65 changes: 55 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,60 @@ jobs:
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

- run: yarn install
# when lock file changes, use increasingly general patterns to restore cache
- yarn-packages-v1-{{ .Branch }}-{{ checksum "yarn.lock" }}
- yarn-packages-v1-{{ .Branch }}-
- yarn-packages-v1-
# https://circleci.com/docs/2.0/caching/#yarn-node
- run: yarn --frozen-lockfile --cache-folder ~/.cache/yarn
- run: yarn build
- save_cache:
paths:
- node_modules
- sandbox/node_modules
key: v1-dependencies-{{ checksum "package.json" }}
# run tests!
- run: yarn test
- ~/.cache/yarn
key: yarn-packages-v1-{{ .Branch }}-{{ checksum "yarn.lock" }}

test-single-app:
docker:
- image: 'circleci/node:12.9.1-browsers'
steps:
- checkout
# Download and cache dependencies
- restore_cache:
keys:
# when lock file changes, use increasingly general patterns to restore cache
- yarn-packages-v1-{{ .Branch }}-{{ checksum "yarn.lock" }}
- yarn-packages-v1-{{ .Branch }}-
- yarn-packages-v1-
- run: yarn --frozen-lockfile --cache-folder ~/.cache/yarn
- run: yarn test single

test-workspace-app-lib:
docker:
- image: 'circleci/node:12.9.1-browsers'
steps:
- checkout
# Download and cache dependencies
- restore_cache:
keys:
# when lock file changes, use increasingly general patterns to restore cache
- yarn-packages-v1-{{ .Branch }}-{{ checksum "yarn.lock" }}
- yarn-packages-v1-{{ .Branch }}-
- yarn-packages-v1-
- run: yarn --frozen-lockfile --cache-folder ~/.cache/yarn
- run: yarn test workspace


workflows:
version: 2

build-and-test:
jobs:
- build

- test-single-app:
requires:
- build

- test-workspace-app-lib:
requires:
- build
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Outputs
src/**/*.js
!src/**/files/**/*.js
!src/**/workspace-files/**/*.js
src/**/*.js.map
src/**/*.d.ts

Expand Down
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018-present Briebug and Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
96 changes: 28 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Jest Angular Schematic

This schematic will configure Angular to execute unit tests with Jest for single projects or workspaces.

[![npm (scoped)](https://img.shields.io/npm/v/@briebug/jest-schematic.svg)](https://www.npmjs.com/package/@briebug/jest-schematic)

## Usage 🚀
Expand All @@ -8,13 +10,11 @@
ng add @briebug/jest-schematic
```

This schematic will add [Jest](https://facebook.github.io/jest/) to an Angular project:

- install Jest, it's dependencies, and new scripts
- add necessary files for Jest to work with Angular
- remove unnecessary Karma files and configuration
- install [Jest](https://facebook.github.io/jest/), types and a [builder](/~https://github.com/just-jeb/angular-builders/tree/master/packages/jest)
- add Jest configuration files
- remove Karma & Jasmine along with their configuration files

#### Optionally: install globally
### Optionally: install globally

```shell
npm install -g @briebug/jest-schematic
Expand All @@ -30,9 +30,9 @@ ng g @briebug/jest-schematic:add

## Issues 🧐

If you're experiencing issues when trying to run your tests with Jest, please view the troubleshooting section for [jest-preset-angular](/~https://github.com/thymikee/jest-preset-angular#troubleshooting) which this schematic utilizes.
If you're experiencing issues when trying to run your tests with Jest, please view the documentation for the [builder](/~https://github.com/just-jeb/angular-builders/tree/master/packages/jest) which uses [jest-preset-angular](/~https://github.com/thymikee/jest-preset-angular#troubleshooting).

A common issues revolves around library dependencies. For example if your app depends on `NgRx` you'll need to tell Jest to compile the sources [explicitly](/~https://github.com/thymikee/jest-preset-angular#adjust-your-transformignorepatterns-whitelist) by appending it to the `transformIgnorePatterns` property in the `jest.config.js` file.
A common issues involves library dependencies. For example if your app depends on `NgRx` you'll need to tell Jest to compile the sources [explicitly](/~https://github.com/thymikee/jest-preset-angular#adjust-your-transformignorepatterns-whitelist) by appending it to the `transformIgnorePatterns` property in the `jest.config.js` file.

```js
module.exports = {
Expand All @@ -50,24 +50,36 @@ Issues with this schematic can be filed [here](/~https://github.com/briebug/jest-s

### Getting started

Clone or fork the repo and install the dependencies with Yarn

```shell
yarn && yarn link:sandbox
yarn
```

### Test schematic changes against this repositories Angular CLI sandbox
### Test schematic changes against a sandbox app

When running locally, schematic changes will be applied to the test app in the `./sandbox` directory. The sandbox is a bare CLI app allows for testing schematics changes.
When running locally, schematic changes will be applied to a test app in the `/sandboxes` directory. `/sandboxes` contain a single app repo and a workspace repo with an application and library.

Run the following when a schematic change is made:
Run the following when a schematic change is made to test:

```shell
yarn build:clean:launch
```
```bash
// runs against /sandboxes/single-app
yarn test single

`build:clean:launch` will compile the Typescript, reset the sandbox to is current version controlled state removing un-tracked files, and run the schematic against the sandbox. This will be your main development command.
// runs against /sandboxes/workspace
yarn test workspace
```

**Be careful not to check in changes to the sandbox directory unless necessary.**

### Reset sandboxes to their version controlled state

This will reset the sandboxes to their `HEAD` commit and remove un-tracked files.

```shell
yarn reset
```

### Test schematics against a local project

- run `yarn build` to compile the schematic in watch mode
Expand All @@ -82,55 +94,3 @@ For faster developing, find and comment out the following line to avoid npm inst
```ts
context.addTask(new NodePackageInstallTask());
```

### Reset sandbox to its version controlled state

This will reset the sandbox folder to its `HEAD` commit and remove un-tracked files.

```shell
yarn clean
```

### Compile the schematics

Compile the typescript files in watch mode

```shell
yarn build:watch
```

Compile the typescript files once

```shell
yarn build
```

## Testing

### Test local sandbox for regressions

Run a series of standard tests to ensure the `./sandbox` continues to function normally

```shell
yarn test
```

### Publishing

Publishing is handled by [np](/~https://github.com/sindresorhus/np#usage). Ensure you have push access to this repo and are a [@briebug](https://www.npmjs.com/settings/briebug/packages) NPM contributor. Several [options](/~https://github.com/sindresorhus/np#usage) are available for releases such as `npm run release --no-publish`.

Once all features are merged into `master`:

1. on your machine, checkout `master`
2. pull latest
3. `npm run release`
4. select the next appropriate version given the changes being added
5. copy the `Commits:` displayed in your shell
6. ![release-commits](./docs/np-release.png)
7. edit the new release tag, and paste in the change notes and supply a title if appropriate
8. ![edit-github-release](./docs/edit-github-release.png)

## Documentation

- [Schematics README](/~https://github.com/angular/angular-cli/blob/master/packages/angular_devkit/schematics/README.md)
- [Angular CLI schematic examples](/~https://github.com/angular/angular-cli/blob/master/packages/schematics/angular/app-shell/index.ts)
57 changes: 43 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
{
"name": "@briebug/jest-schematic",
"version": "2.2.0",
"description": "Add jest to an Angular CLI project",
"version": "3.0.0-0",
"description": "Schematic to add jest to an Angular CLI project",
"repository": "briebug/jest-schematic",
"bugs": "/~https://github.com/briebug/jest-schematic/issues",
"homepage": "/~https://github.com/briebug/jest-schematic",
"main": "src/jest/index.js",
"scripts": {
"build": "tsc -p tsconfig.json",
"build:watch": "tsc -p tsconfig.json -watch",
"clean": "git checkout HEAD -- sandbox && git clean -f -d sandbox",
"build:clean:launch": "yarn build && yarn clean && yarn launch",
"launch": "yarn link:sandbox && cd sandbox && yarn && ./node_modules/.bin/ng g @briebug/jest-schematic:jest",
"test": "yarn build:clean:launch && yarn test:sandbox && yarn clean",
"test:unit": "yarn build:watch && jasmine src/**/*_spec.js",
"test:sandbox": "cd sandbox && yarn lint && yarn test --no-cache && yarn build",
"link:sandbox": "yarn link && cd sandbox && yarn link @briebug/jest-schematic",
"debug": "echo \"debug not setup with @angular/schematics\n> node --inspect-brk $(which schematics) .:addJest\"",
"reset": "ts-node --project=./scripts/tsconfig.json ./scripts/e2e.ts",
"test": "ts-node --project=./scripts/tsconfig.json ./scripts/e2e.ts",
"test:single": "yarn test single",
"test:workspace": "yarn test workspace",
"test:reset": "yarn test reset",
"release": "np"
},
"keywords": [
"schematics"
"schematics",
"jest-schematic",
"jest",
"angular"
],
"author": "Briebug",
"license": "MIT",
Expand All @@ -29,7 +28,7 @@
"@angular-devkit/core": "^10.0.6",
"@angular-devkit/schematics": "^10.0.6",
"@schematics/angular": "^10.0.6",
"@schuchard/schematics-core": "0.4.0",
"@schuchard/schematics-core": "^0.4.0",
"rxjs": "6.5.5"
},
"publishConfig": {
Expand All @@ -38,8 +37,38 @@
"devDependencies": {
"@types/jasmine": "^3.3.16",
"@types/node": "^12.6.9",
"@types/shelljs": "^0.8.8",
"husky": "^4.2.5",
"jasmine": "^3.4.0",
"lint-staged": "^10.2.13",
"np": "^5.0.3",
"typescript": "^3.5.3"
"prettier": "^2.1.1",
"shelljs": "^0.8.4",
"ts-node": "^9.0.0",
"typescript": "^4.0.2"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,json,md,ts}": [
"prettier --write",
"git add"
]
},
"prettier": {
"printWidth": 100,
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"trailingComma": "es5",
"bracketSpacing": true,
"arrowParens": "always"
},
"np": {
"anyBranch": true,
"test-script": "yarn test single && yarn test workspace"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
31 changes: 8 additions & 23 deletions sandbox/angular.json → sandboxes/single-app/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,8 @@
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": true,
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.scss"
],
"assets": ["src/favicon.ico", "src/assets"],
"styles": ["src/styles.scss"],
"scripts": []
},
"configurations": {
Expand Down Expand Up @@ -87,27 +82,16 @@
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.scss"
],
"assets": ["src/favicon.ico", "src/assets"],
"styles": ["src/styles.scss"],
"scripts": []
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"tsconfig.app.json",
"tsconfig.spec.json",
"e2e/tsconfig.json"
],
"exclude": [
"**/node_modules/**"
]
"tsConfig": ["tsconfig.app.json", "tsconfig.spec.json", "e2e/tsconfig.json"],
"exclude": ["**/node_modules/**"]
}
},
"e2e": {
Expand All @@ -123,6 +107,7 @@
}
}
}
}},
}
},
"defaultProject": "sandbox"
}
Loading

0 comments on commit 64f8377

Please sign in to comment.