Skip to content
This repository was archived by the owner on Sep 24, 2020. It is now read-only.

Commit 4b0b043

Browse files
author
Matt Levy
authored
Merge pull request #12 from ducksoupdev/dev2
Add chrome test debugging
2 parents 5c967a8 + 501681e commit 4b0b043

File tree

12 files changed

+120
-42
lines changed

12 files changed

+120
-42
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Change log
22

3+
## [v0.6.0] (2017-04-07)
4+
5+
**Features**
6+
7+
* Implement chrome test debugging
8+
* Update chai and sinon assertions
9+
310
## [v0.5.1] (2017-03-23)
411

512
**Fixes**
@@ -8,7 +15,6 @@
815

916
## [v0.5.0] (2017-03-23)
1017

11-
1218
**Features**
1319

1420
* Implement mocha for unit testing

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ $ npm run dev
1919
### What's Included
2020

2121
- `npm run dev`: Webpack + Typescript with proper config for source maps & hot-reload.
22-
- `npm test`: Mocha-based unit tests
23-
- `npm run test:watch`: Mocha-based unit tests with hot-reload
22+
- `npm test`: Mocha unit tests
23+
- `npm run test:debug`: Debug Mocha unit tests in Chrome
24+
- `npm run test:watch`: Fast feedback Mocha unit tests with hot-reload
2425
- `npm run coverage`: Karma coverage reporter
2526
- `npm run lint`: Lint all Typescript files
2627
- `npm run build`: build with HTML/CSS/JS minification.
Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,31 @@
1-
module.exports = require("./webpack.config.base");
1+
var webpack = require('webpack'),
2+
webpackConfig = require('./webpack.config.base');
3+
4+
webpackConfig.module.rules = [{
5+
test: /\.ts$/,
6+
exclude: /node_modules/,
7+
loader: 'awesome-typescript-loader',
8+
query: {
9+
compilerOptions: {
10+
inlineSourceMap: true,
11+
sourceMap: false
12+
}
13+
}
14+
},
15+
{
16+
test: /\.html$/,
17+
loader: 'raw-loader',
18+
exclude: ['./src/index.html']
19+
}
20+
];
21+
22+
webpackConfig.plugins = [
23+
new webpack.SourceMapDevToolPlugin({
24+
filename: null, // if no value is provided the sourcemap is inlined
25+
test: /\.(ts|js)($|\?)/i
26+
})
27+
];
28+
29+
webpackConfig.devtool = 'inline-source-map';
30+
31+
module.exports = webpackConfig;

template/karma.debug.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
var webpackConfig = require('./config/webpack.config.test');
2+
3+
module.exports = function (config) {
4+
config.set({
5+
basePath: '',
6+
frameworks: ['source-map-support', 'mocha', 'chai', 'sinon'],
7+
files: [
8+
'node_modules/es6-promise/dist/es6-promise.auto.js',
9+
{
10+
pattern: "node_modules/es6-promise/dist/es6-promise.auto.map",
11+
watched: false,
12+
included: false,
13+
served: true
14+
},
15+
'src/test.ts'
16+
],
17+
reporters: ['mocha'],
18+
preprocessors: {
19+
'src/test.ts': ['webpack']
20+
},
21+
webpack: webpackConfig,
22+
webpackServer: {
23+
noInfo: true
24+
},
25+
mime: {
26+
'text/x-typescript': ['ts']
27+
},
28+
port: 9876,
29+
colors: true,
30+
logLevel: config.LOG_INFO,
31+
autoWatch: true,
32+
browsers: ["Chrome_with_debugging"],
33+
customLaunchers: {
34+
Chrome_with_debugging: {
35+
base: "Chrome",
36+
flags: ["--remote-debugging-port=9222"],
37+
debug: true
38+
}
39+
},
40+
singleRun: false
41+
});
42+
};

template/karma.unit.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ module.exports = function(config) {
2121
colors: true,
2222
logLevel: config.LOG_INFO,
2323
autoWatch: false,
24-
browsers: ['PhantomJS'],
24+
browsers: ['Chrome'],
25+
mime: {
26+
'text/x-typescript': ['ts']
27+
},
2528
singleRun: true
2629
});
2730
};

template/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"sass": "node-sass --output ./src/css ./src/sass",
2828
"serve": "http-server dist/ -o",
2929
"test": "cross-env NODE_ENV=development karma start karma.unit.js",
30+
"test:debug": "cross-env NODE_ENV=development karma start karma.debug.js",
3031
"test:watch": "cross-env NODE_ENV=development karma start karma.unit.js --singleRun=false --auto-watch"
3132
},
3233
"dependencies": {
@@ -79,7 +80,6 @@
7980
"remap-istanbul": "~0.9.1",
8081
"rimraf": "~2.6.1",
8182
"sinon": "~2.1.0",
82-
"ts-loader": "~2.0.2",
8383
"tslint": "~4.5.1",
8484
"tslint-loader": "~3.4.3",
8585
"typescript": "~2.2.1",

template/src/components/about/about.spec.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import Sinon from 'sinon';
2-
import {expect} from 'chai';
1+
import { spy, assert } from 'sinon';
2+
import { expect } from 'chai';
33
import Component from 'vue-class-component';
44
import { ComponentTest, MockLogger } from '../../util/component-test';
55
import { AboutComponent } from './about';
66

7-
let loggerSpy = Sinon.spy();
7+
let loggerSpy = spy();
88

99
@Component({
1010
template: require('./about.html')
@@ -24,11 +24,12 @@ describe('About component', () => {
2424
});
2525

2626
it('should render correct contents', async () => {
27+
debugger;
2728
directiveTest.createComponent();
2829

2930
await directiveTest.execute((vm) => {
30-
expect(vm.$el.querySelector('.repo-link').getAttribute('href')).toBe('https://github.com/ducksoupdev/vue-webpack-typescript');
31-
expect(loggerSpy).toHaveBeenCalledWith('about is ready!');
31+
expect(vm.$el.querySelector('.repo-link').getAttribute('href')).to.equal('https://github.com/ducksoupdev/vue-webpack-typescript');
32+
assert.calledWith(loggerSpy, 'about is ready!');
3233
});
3334
});
3435
});
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {expect} from 'chai';
2-
import {HomeComponent} from './home';
3-
import {ComponentTest} from '../../util/component-test';
1+
import { expect } from 'chai';
2+
import { HomeComponent } from './home';
3+
import { ComponentTest } from '../../util/component-test';
44

55
describe('Home component', () => {
66
let directiveTest: ComponentTest;
@@ -12,7 +12,8 @@ describe('Home component', () => {
1212
it('should render correct contents', async () => {
1313
directiveTest.createComponent();
1414
await directiveTest.execute((vm) => {
15-
expect(vm.$el.querySelector('.package').textContent).toBe('vue-webpack-typescript');
15+
debugger;
16+
expect(vm.$el.querySelector('.package').textContent).to.equal('vue-webpack-typescript');
1617
});
1718
});
1819
});

template/src/components/list/list.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Component from 'vue-class-component';
2-
import {expect} from 'chai';
2+
import { expect } from 'chai';
33
import { ComponentTest } from '../../util/component-test';
44
import { ListComponent } from './list';
55

@@ -28,7 +28,9 @@ describe('List component', () => {
2828
directiveTest.createComponent();
2929

3030
await directiveTest.execute((vm) => { // ensure Vue has bootstrapped/run change detection
31-
expect(vm.$el.querySelectorAll('ul li').length).toBe(3);
31+
debugger;
32+
console.log(vm.$el.querySelectorAll('.content ul li'));
33+
expect(vm.$el.querySelectorAll('.content ul li').length).to.equal(3);
3234
});
3335
});
3436
});

template/src/components/navbar/navbar.spec.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import Vue from 'vue';
22
import VueRouter from 'vue-router';
33
import Component from 'vue-class-component';
4-
import Sinon from 'sinon';
5-
import {expect} from 'chai';
6-
import {ComponentTest, MockLogger} from '../../util/component-test';
4+
import { spy, assert } from 'sinon';
5+
import { expect } from 'chai';
6+
import { ComponentTest, MockLogger } from '../../util/component-test';
77
import { NavbarComponent } from './navbar';
88

9-
let loggerSpy = Sinon.spy();
9+
let loggerSpy = spy();
1010

1111
@Component({
1212
template: require('./navbar.html')
@@ -32,9 +32,9 @@ describe('Navbar component', () => {
3232

3333
router = new VueRouter({
3434
routes: [
35-
{path: '/', component: homeComponent},
36-
{path: '/about', component: aboutComponent},
37-
{path: '/list', component: listComponent}
35+
{ path: '/', component: homeComponent },
36+
{ path: '/about', component: aboutComponent },
37+
{ path: '/list', component: listComponent }
3838
]
3939
});
4040
});
@@ -43,8 +43,9 @@ describe('Navbar component', () => {
4343
directiveTest.createComponent({ router: router });
4444

4545
await directiveTest.execute((vm) => { // ensure Vue has bootstrapped/run change detection
46-
expect(loggerSpy).toHaveBeenCalledWith('Default object property!');
47-
expect(vm.$el.querySelectorAll('ul.nav li').length).toBe(3);
46+
debugger;
47+
assert.calledWith(loggerSpy, 'Default object property!');
48+
expect(vm.$el.querySelectorAll('ul.nav li').length).to.equal(3);
4849
});
4950
});
5051

@@ -60,7 +61,7 @@ describe('Navbar component', () => {
6061

6162
it('should render correct about contents', async () => {
6263
await directiveTest.execute((vm) => {
63-
expect(vm.$el.querySelector('div.about').textContent).toEqual('About');
64+
expect(vm.$el.querySelector('div.about').textContent).to.equal('About');
6465
});
6566
});
6667
});
@@ -77,7 +78,7 @@ describe('Navbar component', () => {
7778

7879
it('should render correct about contents', async () => {
7980
await directiveTest.execute((vm) => {
80-
expect(vm.$el.querySelector('div.list').textContent).toEqual('List');
81+
expect(vm.$el.querySelector('div.list').textContent).to.equal('List');
8182
});
8283
});
8384
});

0 commit comments

Comments
 (0)