Skip to content

Commit 23392e4

Browse files
authored
Merge pull request #3 from emyann/feature/Setup-units-tests
Setup Unit Test
2 parents da06371 + 9f78fd8 commit 23392e4

File tree

11 files changed

+205
-89
lines changed

11 files changed

+205
-89
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ typings/**/*
66
~$*
77
*~
88
node_modules/
9+
src/build/
10+
coverage/

.travis.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,10 @@ language: node_js
77
node_js:
88
- '6.7'
99

10-
script: true
10+
before_install:
11+
- export CHROME_BIN=chromium-browser
12+
- export DISPLAY=:99.0
13+
- sh -e /etc/init.d/xvfb start
14+
15+
script:
16+
- npm run test

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
## Built upon
66

7-
- [x] [Webpack 2](https://webpack.github.io/docs/roadmap.html#2)
7+
- [x] [Webpack 3](https://webpack.js.org/)
88
- [x] [Typescript 2](https://blogs.msdn.microsoft.com/typescript/2016/07/11/announcing-typescript-2-0-beta/)
99
- [x] [Webpack Dashboard](https://github.com/FormidableLabs/webpack-dashboard)
1010
![Imgur](http://i.imgur.com/pETTX85.png)
@@ -51,7 +51,5 @@ After build phase, 3 files are generated into the `dist` folder:
5151

5252
## TODO
5353

54-
- [ ] Add TODO example
55-
- [ ] Setup VSCode debug to match webpack-dev-server
5654
- [ ] Setup a webpack common configuration and use webpack-merge
57-
- [ ] Setup unit tests with Jasmine / Karma
55+
- [ ] `create-ts-app` or `create-typescript-app` CLI instead of cloning the entire repository

jsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
// See https://go.microsoft.com/fwlink/?LinkId=759670
33
// for the documentation about the jsconfig.json format
4+
"sourceMap": true,
45
"compilerOptions": {
56
"target": "es6",
67
"module": "commonjs",

karma.conf.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
var webpackConf = require('./webpack.config.js');
2+
module.exports = function (config) {
3+
config.set({
4+
basePath:'',
5+
frameworks: ['jasmine'],
6+
files: [{ pattern: './tests/unit/spec-bundle.js', watched: false }],
7+
preprocessors: { './tests/unit/spec-bundle.js': ['coverage', 'webpack', 'sourcemap'] },
8+
webpack: {
9+
module: webpackConf.module,
10+
resolve: webpackConf.resolve
11+
},
12+
webpackMiddleware: {
13+
noInfo: true,
14+
stats: 'errors-only'
15+
},
16+
reporters: ['kjhtml', 'spec', 'coverage'],
17+
// optionally, configure the reporter
18+
coverageReporter: {
19+
// specify a common output directory
20+
dir: './tests/build/reports/coverage',
21+
reporters: [
22+
// reporters not supporting the `file` property
23+
{ type: 'html', subdir: 'report-html' },
24+
{ type: 'lcov', subdir: 'report-lcov' },
25+
// reporters supporting the `file` property, use `subdir` to directly
26+
// output them in the `dir` directory
27+
{ type: 'cobertura', subdir: '.', file: 'cobertura.txt' },
28+
{ type: 'lcovonly', subdir: '.', file: 'report-lcovonly.txt' },
29+
{ type: 'teamcity', subdir: '.', file: 'teamcity.txt' },
30+
{ type: 'text', subdir: '.', file: 'text.txt' },
31+
{ type: 'text-summary', subdir: '.', file: 'text-summary.txt' },
32+
]
33+
},
34+
specReporter: {
35+
maxLogLines: 5, // limit number of lines logged per test
36+
suppressErrorSummary: true, // do not print error summary
37+
suppressFailed: false, // do not print information about failed tests
38+
suppressPassed: false, // do not print information about passed tests
39+
suppressSkipped: true, // do not print information about skipped tests
40+
showSpecTiming: false // print the time elapsed for each spec
41+
},
42+
customLaunchers: {
43+
Chrome_travis_ci: {
44+
base: 'Chrome',
45+
flags: ['--no-sandbox']
46+
}
47+
},
48+
port: 9876,
49+
colors: true,
50+
logLevel: config.LOG_INFO,
51+
autoWatch: true,
52+
browsers: ['Chrome'],
53+
singleRun: true,
54+
concurrency: Infinity
55+
});
56+
57+
58+
if (process.env.TRAVIS) {
59+
config.browsers = ['Chrome_travis_ci'];
60+
}
61+
};

package.json

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
"scripts": {
77
"start": "npm run server:dev",
88
"server": "npm run server:dev",
9-
"server:dev": "webpack-dashboard -- webpack-dev-server --config ./webpack.config.js --port 3000 --host 0.0.0.0 --hot --inline --progress --profile --watch --content-base dist/",
10-
"server:prod": "cross-env NODE_ENV=production webpack-dashboard -- webpack-dev-server --config ./webpack.config.js --port 3000 --host 0.0.0.0 --hot --inline --progress --profile --watch --content-base dist/",
9+
"server:dev": "webpack-dashboard -- webpack-dev-server --config ./webpack.config.js --inline --progress --watch --open",
10+
"server:prod": "cross-env NODE_ENV=production webpack-dashboard -- webpack-dev-server --config ./webpack.config.js --port 3000 --host 0.0.0.0 --hot --inline --progress --profile --watch --open --content-base dist/",
1111
"build": "npm run build:dev",
1212
"build:dev": "webpack --config ./webpack.config.js --progress --profile --color --display-error-details --display-cached",
1313
"build:prod": "cross-env NODE_ENV=production webpack --config ./webpack.config.js --progress --profile --color --display-error-details --display-cached --bail",
1414
"clean": "npm cache clear && rimraf -- dist",
15-
"test": "echo \"Error: no test specified\" && exit 1"
15+
"test": "karma start"
1616
},
1717
"repository": {
1818
"type": "git",
@@ -21,25 +21,40 @@
2121
"author": "yrenaudin",
2222
"license": "ISC",
2323
"devDependencies": {
24-
"@types/lodash": "^4.14.50",
25-
"cross-env": "^3.1.4",
26-
"css-loader": "^0.26.1",
24+
"@types/jasmine": "^2.5.53",
25+
"@types/lodash": "^4.14.70",
26+
"awesome-typescript-loader": "^3.2.1",
27+
"cross-env": "^5.0.1",
28+
"css-loader": "^0.28.4",
2729
"ejs-loader": "^0.3.0",
28-
"eslint": "^3.14.0",
29-
"expose-loader": "^0.7.1",
30-
"html-loader": "^0.4.4",
31-
"html-webpack-plugin": "^2.26.0",
32-
"rimraf": "^2.5.4",
33-
"style-loader": "^0.13.1",
34-
"ts-loader": "^2.0.0",
35-
"tslint": "^4.3.1",
36-
"tslint-loader": "^3.3.0",
37-
"typescript": "^2.1.5",
38-
"webpack": "^2.1.0-beta.22",
39-
"webpack-dashboard": "^0.2.1",
40-
"webpack-dev-server": "2.2.0"
30+
"eslint": "^4.2.0",
31+
"expose-loader": "^0.7.3",
32+
"html-loader": "^0.4.5",
33+
"html-webpack-plugin": "^2.29.0",
34+
"jasmine": "^2.6.0",
35+
"jasmine-core": "^2.6.4",
36+
"karma": "^1.7.0",
37+
"karma-babel-preprocessor": "^6.0.1",
38+
"karma-chrome-launcher": "^2.2.0",
39+
"karma-coverage": "^1.1.1",
40+
"karma-firefox-launcher": "^1.0.1",
41+
"karma-jasmine": "^1.1.0",
42+
"karma-jasmine-html-reporter": "^0.2.2",
43+
"karma-phantomjs-launcher": "^1.0.4",
44+
"karma-sourcemap-loader": "^0.3.7",
45+
"karma-spec-reporter": "0.0.31",
46+
"karma-webpack": "^2.0.4",
47+
"rimraf": "^2.6.1",
48+
"source-map-loader": "^0.2.1",
49+
"style-loader": "^0.18.2",
50+
"tslint": "^5.5.0",
51+
"tslint-loader": "^3.5.3",
52+
"typescript": "^2.4.1",
53+
"webpack": "^3.3.0",
54+
"webpack-dashboard": "^0.4.0",
55+
"webpack-dev-server": "2.5.1"
4156
},
4257
"dependencies": {
4358
"lodash": "^4.17.4"
4459
}
45-
}
60+
}

src/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
</head>
1616

1717
<body>
18-
<div> You have successfully started your Typescript application using Webpack. By <a href="https://twitter.com/renaudin_yann">@renaudin_yann</a> </div>
18+
<div> You have successfully started your Typescript application using Webpack. Open your console to see your printed message from the index.ts file </div>
19+
<p>By <a href="https://twitter.com/renaudin_yann">@renaudin_yann</a> </p>
1920
</body>
2021

2122
</html>

src/index.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
describe('TypeScript WebPack Starter Tests', () => {
2+
it('A good way to start building an awesome lib is by doing Unit Tests 👌🏽', () => {
3+
expect(true).toBe(true);
4+
});
5+
})

tests/unit/spec-bundle.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Error.stackTraceLimit = Infinity;
2+
3+
var testContext = require.context('./../../src', true, /\.spec\.ts/);
4+
5+
function requireAll(requireContext) {
6+
return requireContext.keys().map(requireContext);
7+
}
8+
9+
var modules = requireAll(testContext);

tsconfig.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
{
22
"compilerOptions": {
33
"target": "es5",
4-
"module": "es6",
5-
"moduleResolution": "node",
6-
"sourceMap": true
4+
"module": "commonjs",
5+
"sourceMap": true,
6+
"emitDecoratorMetadata": true,
7+
"experimentalDecorators": true,
8+
"lib": [
9+
"es2015",
10+
"dom"
11+
],
12+
"noImplicitAny": true,
13+
"suppressImplicitAnyIndexErrors": true
714
},
815
"exclude": [
916
"node_modules",

0 commit comments

Comments
 (0)