Skip to content

Commit 7c6927a

Browse files
authored
Merge branch 'canary' into feat/npm-start-scripts
2 parents e2bfff8 + 189adf9 commit 7c6927a

15 files changed

+120
-46
lines changed

Diff for: src/generators/app/index.js

+13
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,14 @@ export class Generator extends Base {
542542
// Convert HTML into Pug
543543
if(this.filters.pug) {
544544
let pugFilter = filter(['**/*.html', '!client/_index.html'], {restore: true});
545+
546+
function pugReplacer(contents) {
547+
return contents
548+
.replace('ngif', 'ngIf')
549+
.replace('ngfor', 'ngFor')
550+
.replace('ngmodel', 'ngModel');
551+
}
552+
545553
this.registerTransformStream([
546554
pugFilter,
547555
html2jade({
@@ -552,6 +560,11 @@ export class Generator extends Base {
552560
rename(path => {
553561
path.extname = '.pug';
554562
}),
563+
tap(function(file, t) {
564+
var contents = file.contents.toString();
565+
contents = pugReplacer(contents);
566+
file.contents = new Buffer(contents);
567+
}),
555568
pugFilter.restore
556569
]);
557570
}

Diff for: src/test/get-expected-files.js

+1
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ export function app(options) {
212212
/* WebSockets */
213213
if (options.ws) {
214214
files = files.concat([
215+
'client/components/socket/primus.mock.' + script,
215216
'client/components/socket/socket.service.' + script,
216217
'client/components/socket/socket.mock.' + script,
217218
'server/api/thing/thing.socket.js',

Diff for: src/test/main.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ describe('angular-fullstack:app', function() {
255255
}
256256
});
257257

258-
describe('with sequelize models, auth', function() {
258+
describe.only('with sequelize models, auth', function() {
259259
var dir;
260260
var lintResult;
261261
var clientTestResult;

Diff for: templates/app/_package.json

+1
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@
214214
},
215215
"scripts": {
216216
"test": "gulp test",
217+
"test:client": "karma start ./karma.conf.js --single-run",
217218
<%_ if(filters.flow) { -%>
218219
"flow": "flow",
219220
<%_ } -%>

Diff for: templates/app/client/app/main/main.component.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ export class MainComponent implements OnInit<% if(filters.ws) { %>, OnDestroy<%
2424
}
2525

2626
ngOnInit() {
27-
this.Http.get('/api/things')
28-
.map(res => {
29-
return res.json();
30-
})
31-
.catch(err => Observable.throw(err.json().error || 'Server error'))
27+
return this.Http.get('/api/things')
28+
.map(res => res.json())
29+
// .catch(err => Observable.throw(err.json().error || 'Server error'))
3230
.subscribe(things => {
3331
this.awesomeThings = things;
3432
<%_ if(filters.ws) { -%>

Diff for: templates/app/client/app/main/main.component.spec.js

+71-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,75 @@
11
'use strict';
2-
3-
// import main from './main.component';
4-
// import {MainController} from './main.component';
2+
import {
3+
async,
4+
ComponentFixture,
5+
inject,
6+
TestBed,
7+
} from '@angular/core/testing';
8+
import {
9+
BaseRequestOptions,
10+
ConnectionBackend,
11+
Http,
12+
HttpModule,
13+
Response,
14+
ResponseOptions,
15+
} from '@angular/http';
16+
import { MockBackend } from '@angular/http/testing';
17+
<%_ if(filters.mocha && filters.expect) { -%>
18+
import { expect } from 'chai';<% } %><% if(filters.uibootstrap) { %>
19+
import { TooltipModule } from 'ngx-bootstrap';<% } %>
20+
import { FormsModule } from '@angular/forms';
21+
import { SocketService } from '../../components/socket/socket.service';
22+
import { SocketServiceStub } from '../../components/socket/socket.mock';
23+
import { MainComponent } from './main.component';
524

625
describe('Component: MainComponent', function() {
7-
it('should attach a list of things to the controller', function() {});
26+
let comp: MainComponent;
27+
let fixture: ComponentFixture<MainComponent>;
28+
29+
beforeEach(async(() => {
30+
TestBed.configureTestingModule({
31+
imports: [
32+
FormsModule,<% if(filters.uibootstrap) { %>
33+
TooltipModule.forRoot(),<% } %>
34+
HttpModule,
35+
],
36+
declarations: [ MainComponent ], // declare the test component
37+
providers: [
38+
BaseRequestOptions,
39+
MockBackend,
40+
{
41+
provide: Http,
42+
useFactory: (backend: ConnectionBackend, defaultOptions: BaseRequestOptions) => {
43+
return new Http(backend, defaultOptions);
44+
},<%_ if(filters.ws) { %>
45+
deps: [MockBackend, BaseRequestOptions]<% } %>
46+
},
47+
{ provide: SocketService, useClass: SocketServiceStub },
48+
],
49+
}).compileComponents();
50+
}));
51+
<%_ if(filters.ws) { %>
52+
beforeEach(async(inject([MockBackend], (mockBackend) => {
53+
mockBackend.connections.subscribe(conn => {
54+
conn.mockRespond(new Response(new ResponseOptions({
55+
body: JSON.stringify(['HTML5 Boilerplate', 'AngularJS', 'Karma', 'Express'])
56+
})));
57+
});
58+
})));<% } %>
59+
60+
beforeEach(async(() => {
61+
fixture = TestBed.createComponent(MainComponent);
62+
// MainComponent test instance
63+
comp = fixture.componentInstance;
64+
65+
/**
66+
* Trigger initial data binding.
67+
*/
68+
fixture.detectChanges();
69+
}));
70+
71+
it('should attach a list of things to the controller', () => {<% if(filters.jasmine) { %>
72+
expect(comp.awesomeThings.length).toEqual(4);<% } else if(filters.mocha) { -%>
73+
<%= expect() %>comp.awesomeThings.length<%= to() %>.equal(4);<% } %>
74+
});
875
});

Diff for: templates/app/client/components/oauth-buttons(oauth)/oauth-buttons.component.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { ComponentFixture, TestBed } from '@angular/core/testing';
33
import { By } from '@angular/platform-browser';
44
import { DebugElement } from '@angular/core';
5-
<%_ if(filters.expect) { -%>
5+
<%_ if(filters.mocha && filters.expect) { -%>
66
import { expect } from 'chai';<% } %>
77

88
import { OauthButtonsComponent } from './oauth-buttons.component';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default class Primus {}
+4-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
'use strict';
2-
import { noop } from 'lodash-es';
32

4-
export class SocketServiceMock {
5-
socket = {
6-
connect: noop,
7-
on: noop,
8-
emit: noop,
9-
receive: noop
10-
};
11-
syncUpdates = noop;
12-
unsyncUpdates = noop;
3+
export class SocketServiceStub {
4+
constructor() {}
5+
syncUpdates() {}
6+
unsyncUpdates() {}
137
}

Diff for: templates/app/client/components/socket(ws)/socket.service.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
import Primus from './primus';
2+
import Primus from 'primus';
33
import primusEmit from 'primus-emit';
44
import { Injectable } from '@angular/core';
55
import { noop, find, remove } from 'lodash';

Diff for: templates/app/client/components/util.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { safeCb } from './util';
2-
<%_ if(filters.expect) { -%>
2+
<%_ if(filters.mocha && filters.expect) { -%>
33
import { expect } from 'chai';<% } %>
44

55
describe('Util', () => {

Diff for: templates/app/karma.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// http://karma-runner.github.io/0.13/config/configuration-file.html
33
/*eslint-env node*/
44

5-
import makeWebpackConfig from './webpack.make';
5+
const makeWebpackConfig = require('./webpack.make');
66

77
module.exports = function(config) {
88
config.set({

Diff for: templates/app/spec.js

+6-17
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,18 @@ import 'babel-polyfill';
55
import 'zone.js/dist/zone';
66
import 'zone.js/dist/long-stack-trace-zone';
77
import 'zone.js/dist/proxy';
8-
import 'zone.js/dist/sync-test';
9-
<%_ if (filters.jasmine) { -%>
10-
import 'zone.js/dist/jasmine-patch';
11-
<%_ } -%>
8+
import 'zone.js/dist/sync-test';<%_ if (filters.jasmine) { %>
9+
import 'zone.js/dist/jasmine-patch';<% } %><%_ if (filters.mocha) { %>
10+
import 'zone.js/dist/mocha-patch';<% } %>
1211
import 'zone.js/dist/async-test';
1312
import 'zone.js/dist/fake-async-test';
1413

1514
var testsContext = require.context('./client', true, /\.(spec|test)\.<%= scriptExt %>$/);
1615
// testsContext.keys().forEach(testsContext);
17-
// testsContext('./app/main/main.component.spec.<%= scriptExt %>');
16+
testsContext('./app/main/main.component.spec.<%= scriptExt %>');
1817
testsContext('./components/util.spec.<%= scriptExt %>');
19-
<%_ if(filters.oauth) { -%>
20-
testsContext('./components/oauth-buttons/oauth-buttons.component.spec.<%= scriptExt %>');
21-
<%_ } -%>
18+
<% if(filters.oauth) { -%>
19+
testsContext('./components/oauth-buttons/oauth-buttons.component.spec.<%= scriptExt %>');<% } %>
2220

2321
import { TestBed, getTestBed } from '@angular/core/testing';
2422
import {
@@ -28,12 +26,3 @@ import {
2826

2927
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
3028

31-
<%_ if (filters.mocha) { -%>
32-
var hook = new Mocha.Hook('Modified Angular beforeEach Hook', function() {
33-
getTestBed().resetTestingModule();
34-
});
35-
36-
hook.ctx = mocha.suite.ctx;
37-
hook.parent = mocha.suite;
38-
mocha.suite._beforeEach = [hook];
39-
<%_ } -%>

Diff for: templates/app/tsconfig(ts).json

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
"compilerOptions": {
33
"allowJs": true,
44
"allowSyntheticDefaultImports": true,
5+
"baseUrl": ".",
56
"experimentalDecorators": true,
67
"sourceMap": true,
78
"rootDir": "./",
89
"module": "es6",
9-
"outDir": ".tmp",
10+
"outDir": ".tmp",<% if(filters.ws) { %>
11+
"paths": {
12+
"primus": ["client/components/socket/primus.js"]
13+
},<% } %>
1014
"removeComments": false,
1115
"target": "es5",
1216
"skipLibCheck": true,

Diff for: templates/app/webpack.make.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,24 @@ module.exports = function makeWebpackConfig(options) {
7070
};
7171
}
7272

73-
<%_ if(filters.ts) { _%>
7473
config.resolve = {
7574
modules: ['node_modules'],
76-
extensions: ['.js', '.ts']
77-
};<% } %>
75+
extensions: ['.js', '.ts'],
76+
alias: {
77+
primus: path.resolve(__dirname, 'client/components/socket/primus.js'),
78+
}
79+
};
7880

7981
if(TEST) {
8082
config.resolve = {
8183
modules: [
8284
'node_modules'
8385
],
84-
extensions: ['.js', '.ts']
86+
extensions: ['.js', '.ts'],
87+
alias: {
88+
// for some reason the primus client and webpack don't get along in test
89+
primus: path.resolve(__dirname, 'client/components/socket/primus.mock.<%= scriptExt %>'),
90+
}
8591
};
8692
}
8793

0 commit comments

Comments
 (0)