Skip to content

Commit d1b903a

Browse files
committed
v1.2.0
2 parents 504bcda + 626bc98 commit d1b903a

31 files changed

+336
-220
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
.DS_Store
33
docs/_book
4+
test/

README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@ The development server will run on port 8080 by default. If that port is already
3939
- Static assets compiled with version hashes for efficient long-term caching, and an auto-generated production `index.html` with proper URLs to these generated assets.
4040
- Use `npm run build --report`to build with bundle size analytics.
4141

42-
- `npm run unit`: Unit tests run in PhantomJS with [Karma](http://karma-runner.github.io/0.13/index.html) + [Mocha](http://mochajs.org/) + [karma-webpack](https://github.com/webpack/karma-webpack).
42+
- `npm run unit`: Unit tests run in [JSDOM](https://github.com/tmpvar/jsdom) with [Jest](https://facebook.github.io/jest/), or in PhantomJS with Karma + Mocha + karma-webpack.
4343
- Supports ES2015+ in test files.
44-
- Supports all webpack loaders.
45-
- Easy mock injection.
44+
- Easy mocking.
4645

4746
- `npm run e2e`: End-to-end tests with [Nightwatch](http://nightwatchjs.org/).
4847
- Run tests in multiple browsers in parallel.

docs/commands.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ All build commands are executed via [NPM Scripts](https://docs.npmjs.com/misc/sc
2323

2424
### `npm run unit`
2525

26-
> Run unit tests in PhantomJS with [Karma](https://karma-runner.github.io/). See [Unit Testing](unit.md) for more details.
26+
> Run unit tests in JSDOM with [Jest](https://facebook.github.io/jest/docs/getting-started.html). See [Unit Testing](unit.md) for more details.
2727
2828
- Supports ES2015+ in test files.
29-
- Supports all webpack loaders.
30-
- Easy [mock injection](http://vuejs.github.io/vue-loader/en/workflow/testing-with-mocks.html).
29+
- Easy [mocking](https://facebook.github.io/jest/docs/mock-functions.html).
3130

3231
### `npm run e2e`
3332

docs/e2e.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Let's take a look at the files in the `test/e2e` directory:
1010

1111
- `nightwatch.conf.js`
1212

13-
Nightwatch configuration file. See [Nightwatch's docs on configuration](http://nightwatchjs.org/guide#settings-file) for more details.
13+
Nightwatch configuration file. See [Nightwatch's docs on configuration](http://nightwatchjs.org/gettingstarted#settings-file) for more details.
1414

1515
- `custom-assertions/`
1616

docs/pre-processors.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Pre-Processors
22

3-
This boilerplate has pre-configured CSS extraction for most popular CSS pre-processors including LESS, SASS, Stylus, and PostCSS. To use a pre-processor, all you need to do is installing the appropriate webpack loader for it. For example, to use SASS:
3+
This boilerplate has pre-configured CSS extraction for most popular CSS pre-processors including LESS, SASS, Stylus, and PostCSS. To use a pre-processor, all you need to do is install the appropriate webpack loader for it. For example, to use SASS:
44

55
``` bash
66
npm install sass-loader node-sass --save-dev

docs/static.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ You will notice in the project structure we have two directories for static asse
66

77
To answer this question, we first need to understand how Webpack deals with static assets. In `*.vue` components, all your templates and CSS are parsed by `vue-html-loader` and `css-loader` to look for asset URLs. For example, in `<img src="./logo.png">` and `background: url(./logo.png)`, `"./logo.png"` is a relative asset path and will be **resolved by Webpack as a module dependency**.
88

9-
Because `logo.png` is not JavaScript, when treated as a module dependency, we need to use `url-loader` and `file-loader` to process it. This boilerplate has already configured these loaders for you, so you basically get features such as filename fingerprinting and conditional base64 inlining for free, while being able to use relative/module paths without worrying about deployment.
9+
Because `logo.png` is not JavaScript, when treated as a module dependency, we need to use `url-loader` and `file-loader` to process it. This template has already configured these loaders for you, so you get features such as filename fingerprinting and conditional base64 inlining for free, while being able to use relative/module paths without worrying about deployment.
1010

11-
Since these assets may be inlined/copied/renamed during build, they are essentially part of your source code. This is why it is recommended to place Webpack-processed static assets inside `/src`, along side other source files. In fact, you don't even have to put them all in `/src/assets`: you can organize them based on the module/component using them. For example, you can put each component in its own directory, with its static assets right next to it.
11+
Since these assets may be inlined/copied/renamed during build, they are essentially part of your source code. This is why it is recommended to place Webpack-processed static assets inside `/src`, alongside other source files. In fact, you don't even have to put them all in `/src/assets`: you can organize them based on the module/component using them. For example, you can put each component in its own directory, with its static assets right next to it.
1212

1313
### Asset Resolving Rules
1414

docs/structure.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
├── static/ # pure static assets (directly copied)
1818
├── test/
1919
│ └── unit/ # unit tests
20-
│ │   ├── specs/ # test spec files
21-
│ │   ├── index.js # test build entry file
22-
│ │   └── karma.conf.js # test runner config file
20+
│ │ ├── specs/ # test spec files
21+
│ │ ├── setup.js # file that runs before Jest tests
22+
│ │ ├── index.js # test build entry file
23+
│ │ └── karma.conf.js # test runner config file
2324
│ └── e2e/ # e2e tests
2425
│ │   ├── specs/ # test spec files
2526
│ │   ├── custom-assertions/ # custom assertions for e2e tests

docs/unit.md

+25-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
# Unit Testing
22

3-
An overview of the tools used by this boilerplate for unit testing:
3+
This project offers two options for unit testing:
4+
5+
1. Jest
6+
2. Karma and Mocha.
7+
8+
9+
## Jest
10+
11+
- [Jest](https://facebook.github.io/jest/): the test runner that launches JSDOM runs the tests and reports the results to us.
12+
13+
### Files
14+
15+
- `setup.js`
16+
17+
Jest runs this file before it runs the unit tests. It sets the Vue production tip to false.
18+
19+
### Mocking Dependencies
20+
21+
The Jest boilerplate comes with the ability to mock dependencies. See the [mock functions guide](https://facebook.github.io/jest/docs/mock-functions.html) for more details.
22+
23+
## Karma and Mocha
424

525
- [Karma](https://karma-runner.github.io/): the test runner that launches browsers, runs the tests and reports the results to us.
626
- [karma-webpack](https://github.com/webpack/karma-webpack): the plugin for Karma that bundles our tests using Webpack.
@@ -10,7 +30,7 @@ An overview of the tools used by this boilerplate for unit testing:
1030

1131
Chai and Sinon are integrated using [karma-sinon-chai](https://github.com/kmees/karma-sinon-chai), so all Chai interfaces (`should`, `expect`, `assert`) and `sinon` are globally available in test files.
1232

13-
And the files:
33+
### Files
1434

1535
- `index.js`
1636

@@ -24,10 +44,10 @@ And the files:
2444

2545
This is the Karma configuration file. See [Karma docs](https://karma-runner.github.io/) for more details.
2646

27-
## Running Tests in More Browsers
47+
### Running Tests in More Browsers
2848

2949
You can run the tests in multiple real browsers by installing more [karma launchers](https://karma-runner.github.io/1.0/config/browsers.html) and adjusting the `browsers` field in `test/unit/karma.conf.js`.
3050

31-
## Mocking Dependencies
51+
### Mocking Dependencies
3252

33-
This boilerplate comes with [inject-loader](https://github.com/plasticine/inject-loader) installed by default. For usage with `*.vue` components, see [vue-loader docs on testing with mocks](http://vue-loader.vuejs.org/en/workflow/testing-with-mocks.html).
53+
The Karma unit test boilerplate comes with [inject-loader](https://github.com/plasticine/inject-loader) installed by default. For usage with `*.vue` components, see [vue-loader docs on testing with mocks](http://vue-loader.vuejs.org/en/workflow/testing-with-mocks.html).

meta.js

+28-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ module.exports = {
5454
"message": "Pick an ESLint preset",
5555
"choices": [
5656
{
57-
"name": "Standard (https://github.com/feross/standard)",
57+
"name": "Standard (https://github.com/standard/standard)",
5858
"value": "standard",
5959
"short": "Standard"
6060
},
@@ -72,7 +72,29 @@ module.exports = {
7272
},
7373
"unit": {
7474
"type": "confirm",
75-
"message": "Setup unit tests with Karma + Mocha?"
75+
"message": "Setup unit tests"
76+
},
77+
"runner": {
78+
"when": "unit",
79+
"type": "list",
80+
"message": "Pick a test runner",
81+
"choices": [
82+
{
83+
"name": "Jest",
84+
"value": "jest",
85+
"short": "jest"
86+
},
87+
{
88+
"name": "Karma and Mocha",
89+
"value": "karma",
90+
"short": "karma"
91+
},
92+
{
93+
"name": "none (configure it yourself)",
94+
"value": "noTest",
95+
"short": "noTest"
96+
}
97+
]
7698
},
7799
"e2e": {
78100
"type": "confirm",
@@ -84,7 +106,10 @@ module.exports = {
84106
".eslintignore": "lint",
85107
"config/test.env.js": "unit || e2e",
86108
"test/unit/**/*": "unit",
87-
"build/webpack.test.conf.js": "unit",
109+
"test/unit/index.js": "unit && runner === 'karma'",
110+
"test/unit/karma.conf.js": "unit && runner === 'karma'",
111+
"test/unit/specs/index.js": "unit && runner === 'karma'",
112+
"test/unit/setup.js": "unit && runner === 'jest'",
88113
"test/e2e/**/*": "e2e",
89114
"src/router/**/*": "router"
90115
},

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-cli-template-webpack",
3-
"version": "2.0.0",
3+
"version": "1.2.0",
44
"license": "MIT",
55
"description": "A full-featured Webpack setup with hot-reload, lint-on-save, unit testing & css extraction.",
66
"scripts": {

template/.babelrc

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
{
22
"presets": [
33
["env", {
4-
"modules": false,
5-
"targets": {
6-
"browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
7-
}
4+
"modules": false
85
}],
96
"stage-2"
107
],
118
"plugins": ["transform-runtime"],
129
"env": {
1310
"test": {
14-
"presets": ["env", "stage-2"],
11+
"presets": ["env", "stage-2"]{{#if_eq runner "karma"}},
1512
"plugins": ["istanbul"]
13+
{{/if_eq}}
1614
}
1715
}
1816
}

template/.eslintignore

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
build/*.js
2-
config/*.js
1+
/build/
2+
/config/
3+
/dist/
4+
/*.js
5+
{{#unit}}
6+
/test/unit/coverage/
7+
{{/unit}}

template/.gitignore

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
.DS_Store
22
node_modules/
3-
dist/
3+
/dist/
44
npm-debug.log*
55
yarn-debug.log*
66
yarn-error.log*
77
{{#unit}}
8-
test/unit/coverage
8+
/test/unit/coverage/
99
{{/unit}}
1010
{{#e2e}}
11-
test/e2e/reports
11+
/test/e2e/reports/
1212
selenium-debug.log
1313
{{/e2e}}
1414

template/build/dev-client.js

-10
This file was deleted.

template/build/dev-server.js

-107
This file was deleted.

template/build/logo.png

6.69 KB
Loading

0 commit comments

Comments
 (0)