Skip to content

Commit 028e00d

Browse files
committed
feat: initial
0 parents  commit 028e00d

File tree

12 files changed

+347
-0
lines changed

12 files changed

+347
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
.DS_Store
3+
npm-debug.log
4+
cypress/videos

README.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# cypress-angularjs-unit-test BETA
2+
3+
> Unit test Angularjs code using Cypress.io test runner
4+
5+
[![NPM][npm-icon]][npm-url]
6+
7+
[![Build status][ci-image]][ci-url]
8+
[![semantic-release][semantic-image]][semantic-url]
9+
[![standard][standard-image]][standard-url]
10+
[![renovate-app badge][renovate-badge]][renovate-app]
11+
12+
## Install
13+
14+
Requires [Node](https://nodejs.org/en/) version 6 or above.
15+
16+
```sh
17+
npm install --save cypress-angularjs-unit-test cypress
18+
```
19+
20+
Requires `angular` peer dependency
21+
22+
## Use
23+
24+
```js
25+
import {mount} from 'cypress-angularjs-unit-test'
26+
// or const mount = require('cypress-angularjs-unit-test').mount
27+
import angular from 'angular'
28+
// prepare app
29+
it('works', () => {
30+
const template = '... HTML template ... '
31+
const modules = ['module1', 'module2', '...']
32+
mount(template, modules)
33+
})
34+
```
35+
36+
### Basic example
37+
38+
See [cypress/integration/basic.js](cypress/integration/basic.js)
39+
40+
```js
41+
import {mount} from 'cypress-angularjs-unit-test'
42+
import angular from 'angular'
43+
44+
angular.module('demo', [])
45+
.controller('WelcomeController', function($scope) {
46+
$scope.greeting = 'Welcome!';
47+
$scope.version = angular.version.full
48+
});
49+
50+
beforeEach(() => {
51+
const template = `
52+
<div ng-controller="WelcomeController">
53+
{{greeting}}
54+
ng {{version}}
55+
</div>
56+
`
57+
mount(template, ['demo'])
58+
})
59+
60+
it('shows hello', () => {
61+
cy.contains('div', 'Welcome!').should('be.visible')
62+
})
63+
```
64+
65+
### Small print
66+
67+
Author: Gleb Bahmutov &lt;gleb.bahmutov@gmail.com&gt; &copy; 2018
68+
69+
* [@bahmutov](https://twitter.com/bahmutov)
70+
* [glebbahmutov.com](https://glebbahmutov.com)
71+
* [blog](https://glebbahmutov.com/blog)
72+
73+
License: MIT - do anything with the code, but don't blame me if it does not work.
74+
75+
Support: if you find any problems with this module, email / tweet /
76+
[open issue](https://github.com/bahmutov/cypress-angularjs-unit-test/issues) on Github
77+
78+
## MIT License
79+
80+
Copyright (c) 2018 Gleb Bahmutov &lt;gleb.bahmutov@gmail.com&gt;
81+
82+
Permission is hereby granted, free of charge, to any person
83+
obtaining a copy of this software and associated documentation
84+
files (the "Software"), to deal in the Software without
85+
restriction, including without limitation the rights to use,
86+
copy, modify, merge, publish, distribute, sublicense, and/or sell
87+
copies of the Software, and to permit persons to whom the
88+
Software is furnished to do so, subject to the following
89+
conditions:
90+
91+
The above copyright notice and this permission notice shall be
92+
included in all copies or substantial portions of the Software.
93+
94+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
95+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
96+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
97+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
98+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
99+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
100+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
101+
OTHER DEALINGS IN THE SOFTWARE.
102+
103+
[npm-icon]: https://nodei.co/npm/cypress-angularjs-unit-test.svg?downloads=true
104+
[npm-url]: https://npmjs.org/package/cypress-angularjs-unit-test
105+
[ci-image]: https://travis-ci.org/bahmutov/cypress-angularjs-unit-test.svg?branch=master
106+
[ci-url]: https://travis-ci.org/bahmutov/cypress-angularjs-unit-test
107+
[semantic-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
108+
[semantic-url]: https://github.com/semantic-release/semantic-release
109+
[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg
110+
[standard-url]: http://standardjs.com/
111+
[renovate-badge]: https://img.shields.io/badge/renovate-app-blue.svg
112+
[renovate-app]: https://renovateapp.com/

cypress.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

cypress/fixtures/example.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Using fixtures to represent data",
3+
"email": "hello@cypress.io",
4+
"body": "Fixtures are a great way to mock data for responses to routes"
5+
}

cypress/integration/basic.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/// <reference types="cypress" />
2+
import {mount} from '../..'
3+
import angular from 'angular'
4+
5+
const app = angular.module('demo', [])
6+
.controller('WelcomeController', function($scope) {
7+
$scope.greeting = 'Welcome!';
8+
$scope.version = angular.version.full
9+
});
10+
11+
beforeEach(() => {
12+
const template = `
13+
<div ng-controller="WelcomeController">
14+
{{greeting}}
15+
ng {{version}}
16+
</div>
17+
`
18+
mount(template, ['demo'])
19+
})
20+
21+
it('shows hello', () => {
22+
cy.contains('div', 'Welcome!').should('be.visible')
23+
})

cypress/plugins/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// ***********************************************************
2+
// This example plugins/index.js can be used to load plugins
3+
//
4+
// You can change the location of this file or turn off loading
5+
// the plugins file with the 'pluginsFile' configuration option.
6+
//
7+
// You can read more here:
8+
// https://on.cypress.io/plugins-guide
9+
// ***********************************************************
10+
11+
// This function is called when a project is opened or re-opened (e.g. due to
12+
// the project's config changing)
13+
14+
module.exports = (on, config) => {
15+
// `on` is used to hook into various events Cypress emits
16+
// `config` is the resolved Cypress config
17+
}

cypress/support/commands.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// ***********************************************
2+
// This example commands.js shows you how to
3+
// create various custom commands and overwrite
4+
// existing commands.
5+
//
6+
// For more comprehensive examples of custom
7+
// commands please read more here:
8+
// https://on.cypress.io/custom-commands
9+
// ***********************************************
10+
//
11+
//
12+
// -- This is a parent command --
13+
// Cypress.Commands.add("login", (email, password) => { ... })
14+
//
15+
//
16+
// -- This is a child command --
17+
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
18+
//
19+
//
20+
// -- This is a dual command --
21+
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
22+
//
23+
//
24+
// -- This is will overwrite an existing command --
25+
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })

cypress/support/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// ***********************************************************
2+
// This example support/index.js is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
import './commands'
18+
19+
// Alternatively you can use CommonJS syntax:
20+
// require('./commands')

issue_template.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Thank you for taking time to open a new issue. Please answer a few questions to help us fix it faster. You can delete text that is irrelevant to the issue.
2+
3+
## Is this a bug report or a feature request?
4+
5+
If this is a bug report, please provide as much info as possible
6+
7+
- version
8+
- platform
9+
- expected behavior
10+
- actual behavior
11+
12+
If this is a new feature request, please describe it below

package.json

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{
2+
"name": "cypress-angularjs-unit-test",
3+
"description": "Unit test Angularjs code using Cypress.io test runner",
4+
"version": "1.0.0",
5+
"author": "Gleb Bahmutov <gleb.bahmutov@gmail.com>",
6+
"bugs": "https://github.com/bahmutov/cypress-angularjs-unit-test/issues",
7+
"config": {
8+
"pre-git": {
9+
"commit-msg": "simple",
10+
"pre-commit": [
11+
"npm prune",
12+
"echo skipped npm run deps",
13+
"npm test",
14+
"git add src/*.js",
15+
"npm run ban"
16+
],
17+
"pre-push": [
18+
"npm run unused-deps",
19+
"npm run secure",
20+
"npm run license",
21+
"npm run ban -- --all",
22+
"npm run size"
23+
],
24+
"post-commit": [],
25+
"post-merge": []
26+
}
27+
},
28+
"engines": {
29+
"node": ">=6"
30+
},
31+
"files": [
32+
"src/*.js",
33+
"!src/*-spec.js"
34+
],
35+
"homepage": "https://github.com/bahmutov/cypress-angularjs-unit-test#readme",
36+
"keywords": [
37+
"angularjs",
38+
"cypress",
39+
"cypress-io",
40+
"test",
41+
"testing"
42+
],
43+
"license": "MIT",
44+
"main": "src/",
45+
"private": false,
46+
"publishConfig": {
47+
"registry": "http://registry.npmjs.org/"
48+
},
49+
"release": {
50+
"analyzeCommits": {
51+
"preset": "angular",
52+
"releaseRules": [
53+
{
54+
"type": "break",
55+
"release": "major"
56+
}
57+
]
58+
}
59+
},
60+
"repository": {
61+
"type": "git",
62+
"url": "https://github.com/bahmutov/cypress-angularjs-unit-test.git"
63+
},
64+
"scripts": {
65+
"ban": "ban",
66+
"deps": "deps-ok && dependency-check --no-dev .",
67+
"issues": "git-issues",
68+
"license": "license-checker --production --onlyunknown --csv",
69+
"lint": "standard --verbose --fix src/*.js",
70+
"prelint": "npm run pretty",
71+
"pretest": "npm run lint",
72+
"pretty": "prettier-standard 'src/*.js'",
73+
"secure": "nsp check",
74+
"size": "t=\"$(npm pack .)\"; wc -c \"${t}\"; tar tvf \"${t}\"; rm \"${t}\";",
75+
"test": "cypress run",
76+
"cy": "cypress open",
77+
"unused-deps": "dependency-check --unused --no-dev ."
78+
},
79+
"devDependencies": {
80+
"ban-sensitive-files": "1.9.2",
81+
"dependency-check": "3.1.0",
82+
"deps-ok": "0.0.0-development",
83+
"git-issues": "1.3.1",
84+
"license-checker": "18.0.0",
85+
"nsp": "3.2.1",
86+
"pre-git": "3.17.1",
87+
"prettier-standard": "8.0.1",
88+
"standard": "11.0.1",
89+
"cypress": "2.1.0"
90+
},
91+
"dependencies": {
92+
"angular": "^1.6.9",
93+
"cypress": "^2.1.0"
94+
}
95+
}
96+

renovate.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": ["config:base"],
3+
"automerge": true,
4+
"major": {
5+
"automerge": false
6+
}
7+
}

src/index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/// <reference types="cypress" />
2+
import angular from 'angular'
3+
4+
/* global cy */
5+
export const mount = (template, modules = []) => {
6+
const html = `
7+
<head>
8+
<meta charset="UTF-8">
9+
</head>
10+
<body>
11+
${template}
12+
</body>
13+
`
14+
const document = cy.state('document')
15+
document.write(html)
16+
document.close()
17+
18+
cy.window().then(w => {
19+
// set the Angular library reference
20+
// into the test iframe
21+
w.angular = angular
22+
cy.log('Angular.js', angular.version.full)
23+
angular.bootstrap(document, modules)
24+
})
25+
}

0 commit comments

Comments
 (0)