Skip to content

Commit

Permalink
Merge pull request #18 from nightwatchjs/refacotr/fix-formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaibhav Singh authored Aug 23, 2022
2 parents 879130b + b3c9894 commit 2006584
Show file tree
Hide file tree
Showing 17 changed files with 394 additions and 362 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ on:

jobs:
build:

runs-on: ubuntu-latest

strategy:
Expand All @@ -34,7 +33,7 @@ jobs:
run: |
npm ci
npm run build
npm run test:unit
npm run test:unit
- name: npm install, build, test for v10 angular app
run: |
npm ci
Expand Down
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
*.ts
!*.d.ts
!src/**/files/**/*.ts
test
sandbox
sandbox-v10
sandbox-v12
sandbox-v14
4 changes: 3 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*.lock
sandbox
sandbox-v10
sandbox-v12
sandbox-v14
46 changes: 21 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
[![Node CI](https://github.com/nightwatchjs/nightwatch-schematics/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/nightwatchjs/nightwatch-schematics/actions/workflows/build.yml)
[![npm package](https://img.shields.io/npm/v/@nightwatch/schematics)](https://www.npmjs.com/package/@nightwatch/schematics)

> Fast and easy installation of [Nightwatch][NightwatchLink] into your projects
> Fast and easy installation of [Nightwatch][nightwatchlink] into your projects
Framework & Language Supported: [Angular](#angular)

<p align="center">
<img alt="Nightwatch.js Schematic Logo" src=".github/assets/nightwatch-logo.svg" width=300 />
</p>

This project is a Schematics implementation that allows you to easily integrate [Nightwatch][NightwatchLink] into your Angular projects.
This project is a Schematics implementation that allows you to easily integrate [Nightwatch][nightwatchlink] into your Angular projects.

**This Schematic will:**

🏗️ Install Nightwatch, and it's dependencies
⚙️ Add NPM scripts for running Nightwatch tests
⚙️ Add NPM scripts for running Nightwatch tests
📦 Scaffold base Nightwatch config and test files
❓ Prompt for removal of Protractor files and configuration
❓ Prompt for removal of Protractor files and configuration

## Angular

Expand All @@ -35,7 +35,7 @@ ng add @nightwatch/schematics
```

One can provide following options:
| Option | Description |
| Option | Description |
|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| noBuilder | This will skip the builder addition, leaving the angular.json file unmodified and requiring you to run Nightwatch from the command line or through your IDE. Include --noBuilder in your ng add command. |

Expand All @@ -51,22 +51,21 @@ ng run {your-project-name}:nightwatch-run

These two commands do the same thing. They will run nightwatch e2e tests.

Once Nightwatch is added to your project, all [Nightwatch CLI options][NightwatchCliOptionsLink] will be available when triggering e2e tests. E.g.: `--verbose`, `--retries` etc.

Once Nightwatch is added to your project, all [Nightwatch CLI options][nightwatchclioptionslink] will be available when triggering e2e tests. E.g.: `--verbose`, `--retries` etc.

### ✨ Demo

![Nightwatch Schematics Demo](.github/assets/typescript-demo.gif)

### 🚀 Usage

Install [Schematics CLI][SchematicsCliLink] globally
Install [Schematics CLI][schematicsclilink] globally

```bash
npm install -g @angular-devkit/schematics-cli
```

Install [Nightwatch-schematics][NightwatchSchematicsLink] in your project
Install [Nightwatch-schematics][nightwatchschematicslink] in your project

```bash
npm install @nightwatch/schematics
Expand All @@ -78,7 +77,7 @@ Run following command to install Nightwatch in your project:
schematics @nightwatch/schematics:ng-add
```

Once Nightwatch is added to your project, all [Nightwatch CLI options][NightwatchCliOptionsLink] will be available when triggering e2e tests. E.g.: `--verbose`, `--retries` etc. One can update `e2e:test` to include cli options.
Once Nightwatch is added to your project, all [Nightwatch CLI options][nightwatchclioptionslink] will be available when triggering e2e tests. E.g.: `--verbose`, `--retries` etc. One can update `e2e:test` to include cli options.

## 🐛 Issues

Expand All @@ -98,9 +97,9 @@ npm update @nightwatch/schematics

### Where can I ask for help and report bugs?

The best way to ask for help and to report bugs is to [open an issue][GithubIssueLink].
The best way to ask for help and to report bugs is to [open an issue][githubissuelink].

[Gitter][GitterLink] is another option.
[Gitter][gitterlink] is another option.

### I created new angular project, how do I remove Protractor and install Nightwatch?

Expand Down Expand Up @@ -141,22 +140,19 @@ All you have to do is install the relevant drivers, and replace `env` value (Che
}
```



### How to run e2e tests using npm?

| Projects | command |
|--------------------|------------------|
| ------------------ | ---------------- |
| Angular App | npm run e2e |
| Typescript Project | npm run e2e:test |


## Drivers

### Drivers available to install

| Name | driver | command |
|-----------------|-----------------|------------------------------------------|
| --------------- | --------------- | ---------------------------------------- |
| chrome | chromedriver | `npm install chromedriver --save-dev` |
| firefox | geckodriver | `npm install geckodriver --save-dev` |
| selenium-server | selenium-server | `npm install selenium-server --save-dev` |
Expand Down Expand Up @@ -214,11 +210,11 @@ npm run clean

These projects: [@briebug/cypress-schematic](https://github.com/briebug/cypress-schematic/), [schuchard/prettier-schematic](https://github.com/schuchard/prettier-schematic) helped us in development of this project. Thank you!

[NightwatchLink]:https://nightwatchjs.org/
[NightwatchCliOptionsLink]:https://nightwatchjs.org/guide/running-tests/command-line-options.html
[NightwatchGetStartedLink]:https://nightwatchjs.org/gettingstarted/
[NightwatchSchematicsLink]:https://github.com/nightwatchjs/nightwatch-schematics
[VueNightwatchPluginLink]:https://cli.vuejs.org/core-plugins/e2e-nightwatch.html
[SchematicsCliLink]:https://www.npmjs.com/package/@angular-devkit/schematics-cli
[GithubIssueLink]:https://github.com/nightwatchjs/nightwatch-schematics/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc
[GitterLink]:https://gitter.im/nightwatchjs/nightwatch
[nightwatchlink]: https://nightwatchjs.org/
[nightwatchclioptionslink]: https://nightwatchjs.org/guide/running-tests/command-line-options.html
[nightwatchgetstartedlink]: https://nightwatchjs.org/gettingstarted/
[nightwatchschematicslink]: https://github.com/nightwatchjs/nightwatch-schematics
[vuenightwatchpluginlink]: https://cli.vuejs.org/core-plugins/e2e-nightwatch.html
[schematicsclilink]: https://www.npmjs.com/package/@angular-devkit/schematics-cli
[githubissuelink]: https://github.com/nightwatchjs/nightwatch-schematics/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc
[gitterlink]: https://gitter.im/nightwatchjs/nightwatch
24 changes: 23 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 15 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,36 @@
"description": "Adds Nightwatch to an existing Angular CLI project",
"scripts": {
"build": "tsc -p tsconfig.json",
"build:test": "tsc -p tsconfig.spec.json",
"build:watch": "tsc -p tsconfig.json -w",
"build:test:watch": "tsc -p tsconfig.spec.json -w",
"build:clean:launch:v10": "npm run build && npm run clean:launch:v10",
"build:clean:launch:v12": "npm run build && npm run clean:launch:v12",
"build:clean:launch:v14": "npm run build && npm run clean:launch:v14",
"build:test": "tsc -p tsconfig.spec.json",
"build:test:watch": "tsc -p tsconfig.spec.json -w",
"build:watch": "tsc -p tsconfig.json -w",
"clean": "rm -rf src/**/*.{js,js.map,d.ts} && rm -rf test/**/*.{js,js.map,d.ts}",
"clean:launch:v10": "npm run clean:v10 && npm run launch:v10",
"clean:launch:v12": "npm run clean:v12 && npm run launch:v12",
"clean:launch:v14": "npm run clean:v14 && npm run launch:v14",
"clean:v10": "git checkout HEAD -- sandbox-v10 && git clean -f -d sandbox-v10",
"clean:v12": "git checkout HEAD -- sandbox-v12 && git clean -f -d sandbox-v12",
"clean:v14": "git checkout HEAD -- sandbox-v14 && git clean -f -d sandbox-v14",
"dev:build": "cd sandbox && npm link ../ && ng run sandbox:nightwatch-run",
"execute": "npm run build && schematics .:ng-add",
"execute:prod": "npm run build && schematics .:ng-add --dry-run=false",
"format": "prettier --write .",
"launch:v10": "npm run link:sandbox:v10 && cd sandbox-v10 && ng add $npm_package_name --remove-protractor --environment='chrome' --no-cucumber-runner && npm link ../",
"launch:v12": "npm run link:sandbox:v12 && cd sandbox-v12 && ng add $npm_package_name --remove-protractor --environment='chrome' --no-cucumber-runner && npm link ../",
"launch:v14": "npm run link:sandbox:v14 && cd sandbox-v14 && ng add $npm_package_name --remove-protractor --environment='chrome' --no-cucumber-runner && npm link ../",
"test:v10": "cd sandbox-v10 && ng run sandbox-v10:nightwatch-run --headless",
"test:v12": "cd sandbox-v12 && ng run sandbox-v12:nightwatch-run --headless",
"test:v14": "cd sandbox-v14 && ng run sandbox-v14:nightwatch-run --headless",
"link:sandbox:v10": "npm link && cd sandbox-v10 && npm link $npm_package_name",
"link:sandbox:v12": "npm link && cd sandbox-v12 && npm link $npm_package_name",
"link:sandbox:v14": "npm link && cd sandbox-v14 && npm link $npm_package_name",
"unlink:sandbox": "cd sandbox && npm unlink $npm_package_name && cd .. && npm unlink",
"execute": "npm run build && schematics .:ng-add",
"execute:prod": "npm run build && schematics .:ng-add --dry-run=false",
"dev:build": "cd sandbox && npm link ../ && ng run sandbox:nightwatch-run",
"test": "npm run build:clean:launch && npm run test:sandbox:v14 && npm run clean",
"test:sandbox:v14": "cd sandbox-14 && npm run lint && npm run test && npm run build && npm run e2e",
"test:unit": "mocha test/**/*_spec.js"
"test:unit": "mocha test/**/*_spec.js",
"test:v10": "cd sandbox-v10 && ng run sandbox-v10:nightwatch-run --headless",
"test:v12": "cd sandbox-v12 && ng run sandbox-v12:nightwatch-run --headless",
"test:v14": "cd sandbox-v14 && ng run sandbox-v14:nightwatch-run --headless",
"unlink:sandbox": "cd sandbox && npm unlink $npm_package_name && cd .. && npm unlink"
},
"keywords": [
"schematics",
Expand Down Expand Up @@ -72,6 +74,7 @@
"@types/node": "^18.7.6",
"chai": "^4.3.6",
"mocha": "^10.0.0",
"nightwatch": "^2.3.0"
"nightwatch": "^2.3.0",
"prettier": "^2.7.1"
}
}
8 changes: 2 additions & 6 deletions src/schematics/nightwatch/files/nightwatch/tsconfig.e2e.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
"outDir": "../out-tsc/nightwatch",
"module": "commonjs",
"target": "es5",
"types": [
"node"
],
"types": ["node"]
},
"include": [
"src/**/*"
]
"include": ["src/**/*"]
}
10 changes: 3 additions & 7 deletions src/schematics/nightwatch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ import { map, concatMap } from 'rxjs/operators';
import { Observable, of, concat } from 'rxjs';
import { NodeDependencyType } from './enums';
import { NodePackage, SchematicsOptions, ScriptHash } from './interfaces';
import {
addPropertyToPackageJson,
getAngularVersion,
getLatestNodeVersion,
} from './utility/util';
import { addPropertyToPackageJson, getAngularVersion, getLatestNodeVersion } from './utility/util';
import { addPackageJsonDependency, removePackageJsonDependency } from './utility/dependencies';
import getFramework from './utility/framework';
import { normalize, strings } from '@angular-devkit/core';
Expand All @@ -33,7 +29,7 @@ export default function (_options: SchematicsOptions): Rule {
return (tree: Tree, _context: SchematicContext) => {
_options = { ..._options, __version__: getAngularVersion(tree) };

if(_options.__version__ === 0) {
if (_options.__version__ === 0) {
throw new SchematicsException('Angular project not found');
}

Expand Down Expand Up @@ -126,7 +122,7 @@ function updateDependencies(options: SchematicsOptions): Rule {

removePackageJsonDependency(tree, {
type: NodeDependencyType.Dev,
name: packageName
name: packageName,
});

return tree;
Expand Down
12 changes: 2 additions & 10 deletions src/schematics/nightwatch/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@
"environment": {
"description": "The browser you want to run your e2e tests",
"type": "string",
"enum": [
"chrome",
"firefox",
"safari",
"selenium"
],
"enum": ["chrome", "firefox", "safari", "selenium"],
"$default": {
"$source": "argv",
"index": 2
Expand All @@ -46,8 +41,5 @@
"type": "boolean"
}
},
"required": [
"environment",
"cucumberRunner"
]
"required": ["environment", "cucumberRunner"]
}
Loading

0 comments on commit 2006584

Please sign in to comment.