Skip to content

Commit

Permalink
Merge pull request #1 from bahmutov/master
Browse files Browse the repository at this point in the history
sync with upstream
  • Loading branch information
meDavid authored Jan 14, 2019
2 parents fd9e930 + f9ab929 commit 7912306
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ testem.log
# System Files
.DS_Store
Thumbs.db
cypress/videos
16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
language: node_js
cache:
directories:
- ~/.npm
- ~/.cache
notifications:
email: true
node_js:
- '10'
script:
- npm run cy:run
# after_success:
# - npm run travis-deploy-once "npm run semantic-release"
branches:
except:
- /^v\d+\.\d+\.\d+$/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## NOT WORKING YET
## NOT WORKING YET [![Build Status](https://travis-ci.org/bahmutov/cypress-angular-unit-test.svg?branch=master)](https://travis-ci.org/bahmutov/cypress-angular-unit-test)

If you run `$(npm bin)/cypress open` and click on "spec.ts" it does not show any errors, meaning a component has been bootstrapped. Not the HTML looks very weird and nothing is running. I assume the Angular code is running in the spec iframe and cannot cross into the app iframe where the component has been mounted.

Expand Down
38 changes: 23 additions & 15 deletions cypress/integration/spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { AppComponent } from '../../src/app/app.component'
import 'zone.js';
/// <reference types="cypress" />

import { ApplicationRef, NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { Component, NgModule, ViewContainerRef, ApplicationRef } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import 'zone.js';
import { AppComponent } from '../../src/app/app.component';

// dynamic loading based on blog post
// https://blog.angularindepth.com/how-to-manually-bootstrap-an-angular-application-9a36ccf86429
Expand All @@ -18,9 +20,9 @@ import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
entryComponents: [AppComponent]
})
class AppModule {
app: ApplicationRef
app: ApplicationRef;
ngDoBootstrap(app: ApplicationRef) {
this.app = app
this.app = app;
}
}

Expand All @@ -35,19 +37,25 @@ describe('AppComponent', () => {
<body>
<app-root></app-root>
</body>
`
const document = (cy as any).state('document')
document.write(html)
document.close()
`;
const document = (cy as any).state('document');
document.write(html);
document.close();

cy.get('app-root').then(el$ => {
platformBrowserDynamic()
.bootstrapModule(AppModule)
.then(function (moduleRef) {
moduleRef.instance.app.bootstrap(AppComponent, el$.get(0))
})
})
})
moduleRef.instance.app.bootstrap(AppComponent, el$.get(0));
});
});
});

it('works', () => {})
})
it('works', () => {
cy.contains('Welcome to app').should('be.visible');
});

it('works again', () => {
cy.contains('Welcome to app').should('be.visible');
});
});
15 changes: 10 additions & 5 deletions cypress/plugins/cy-ts-preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ const webpackOptions = {
rules: [
{
test: /\.ts$/,
loaders: ['ts-loader', 'angular2-template-loader'],
exclude: [/node_modules/],
use: [
{
loader: 'ts-loader'
}
]
},
{
test: /\.(html|css)$/,
loader: 'raw-loader',
exclude: /\.async\.(html|css)$/
},
{
test: /\.async\.(html|css)$/,
loaders: ['file?name=[name].[hash].[ext]', 'extract']
}
]
}
Expand Down
34 changes: 29 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
{
"name": "ng-mount",
"version": "0.0.0",
"name": "cypress-angular-unit-test",
"version": "0.0.0-development",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build --prod",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
"e2e": "ng e2e",
"cy:open": "cypress open",
"cy:run": "cypress run",
"travis-deploy-once": "travis-deploy-once",
"semantic-release": "semantic-release"
},
"private": true,
"homepage": "https://github.com/bahmutov/cypress-angular-unit-test#readme",
"dependencies": {
"@angular/animations": "^5.2.0",
"@angular/common": "^5.2.0",
Expand All @@ -33,8 +38,9 @@
"@types/jasmine": "~2.8.3",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"angular2-template-loader": "^0.6.2",
"codelyzer": "^4.0.1",
"cypress": "^1.4.1",
"cypress": "3.0.2",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~2.0.0",
Expand All @@ -44,8 +50,26 @@
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"raw-loader": "^0.5.1",
"ts-node": "~4.1.0",
"tslint": "~5.9.1",
"typescript": "~2.5.3"
"typescript": "~2.5.3",
"travis-deploy-once": "^5.0.1",
"semantic-release": "^15.8.1"
},
"repository": {
"type": "git",
"url": "https://github.com/bahmutov/cypress-angular-unit-test.git"
},
"release": {
"analyzeCommits": {
"preset": "angular",
"releaseRules": [
{
"type": "break",
"release": "major"
}
]
}
}
}

0 comments on commit 7912306

Please sign in to comment.