Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve template CI tests #1218

Merged
merged 43 commits into from
Jan 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
e10cb12
Batman!
LinusBorg Oct 3, 2017
0205c22
fix wrong job name
LinusBorg Oct 3, 2017
d38941d
fix working dir paths
LinusBorg Oct 3, 2017
124af6d
fix node_modules path
LinusBorg Oct 3, 2017
d9664a2
test other step order
LinusBorg Oct 3, 2017
9dc3f68
try other shell
LinusBorg Oct 3, 2017
520638d
...and another one
LinusBorg Oct 3, 2017
64e0906
rewrite test.sh
LinusBorg Oct 3, 2017
07aa3ff
try running a bash script instead
LinusBorg Oct 3, 2017
5a9afe9
and another attempt.
LinusBorg Oct 3, 2017
64e2cb3
make executable
LinusBorg Oct 3, 2017
e4518d2
anpother try...
LinusBorg Oct 9, 2017
60b1d9c
fix workflow errors
LinusBorg Oct 9, 2017
3c876d9
fix path
LinusBorg Oct 9, 2017
acab0ee
Batman!
LinusBorg Nov 14, 2017
36121bd
added scenarios and made it work!!
LinusBorg Nov 14, 2017
82298f7
refactors and comments
LinusBorg Nov 16, 2017
82d72dd
just fumbling around
LinusBorg Dec 4, 2017
37f60c9
adfda
LinusBorg Dec 10, 2017
96996da
adjust test scenarios for autoInstall
LinusBorg Dec 17, 2017
10fac73
x<vb<xb
LinusBorg Dec 17, 2017
8c60a52
first try since a long time
LinusBorg Dec 17, 2017
b31df03
small fix
LinusBorg Dec 17, 2017
d1ff81c
fix path to vue-cli
LinusBorg Dec 17, 2017
b2827f1
fix scenarios
LinusBorg Dec 17, 2017
1b8093b
fix persist paths
LinusBorg Dec 17, 2017
013616a
testing with quotes for the path
LinusBorg Dec 17, 2017
0c22cdf
removing unhelpful quotes
LinusBorg Dec 21, 2017
a071d5c
New Test
LinusBorg Jan 4, 2018
6768b24
fixed indentation
LinusBorg Jan 4, 2018
00f094a
test with full setup
LinusBorg Jan 4, 2018
4609707
2nd full test
LinusBorg Jan 4, 2018
d378e49
bump jest version
LinusBorg Jan 4, 2018
109eb26
other docker image
LinusBorg Jan 4, 2018
00d45b7
test with runinband
LinusBorg Jan 4, 2018
08f96ab
test with airbnb/karma as well
LinusBorg Jan 4, 2018
dd6dfad
remove superfluous checkout
LinusBorg Jan 4, 2018
40148b3
run unit and e2e individually.
LinusBorg Jan 4, 2018
ded7723
fix eslint paths for test subdirs
LinusBorg Jan 4, 2018
1ff7f68
adjust for airbnb preset
LinusBorg Jan 4, 2018
71a5224
only lint e2e specs, config differences are unfixable.
LinusBorg Jan 4, 2018
b1dec9b
adding a small readme
LinusBorg Jan 4, 2018
730f331
remove test.sh
LinusBorg Jan 13, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 137 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
version: 2
vm_settings: &vm_settings
docker:
- image: circleci/node:8.9.4-browsers

jobs:
install_template_deps:
<<: *vm_settings
working_directory: ~/project/webpack-template
steps:
- checkout
- restore_cache:
key: template-cache-{{ checksum "package.json" }}
- run:
name: Install npm dependencies
command: npm install
- save_cache:
key: template-cache-{{ checksum "package.json" }}
paths:
- node_modules
- run:
name: Rollout minimal scenario
command: VUE_TEMPL_TEST=minimal node_modules/.bin/vue init . test-minimal
- run:
name: Rollout full scenario
command: VUE_TEMPL_TEST=full node_modules/.bin/vue init . test-full
- run:
name: Rollout full-karma-airbnb scenario
command: VUE_TEMPL_TEST=full-karma-airbnb node_modules/.bin/vue init . test-full-karma-airbnb
- persist_to_workspace:
root: ~/project/webpack-template
paths:
- node_modules
- test-*

scenario_minimal:
<<: *vm_settings
environment:
- VUE_TEMPL_TEST: minimal
working_directory: ~/project/webpack-template/test-minimal
steps:
- attach_workspace:
at: '~/project/webpack-template'
- restore_cache:
key: template-cache-minimal-{{ checksum "package.json" }}
- run:
name: Install npm dependencies
command: npm install
- save_cache:
key: template-cache-minimal-{{ checksum "package.json" }}
paths:
- node_modules
- run:
name: Test build
command: npm run build

scenario_full:
<<: *vm_settings
working_directory: ~/project/webpack-template/test-full
environment:
- VUE_TEMPL_TEST: full
steps:
- attach_workspace:
at: '~/project/webpack-template'
- restore_cache:
key: template-cache-full-{{ checksum "package.json" }}
- run:
name: Install npm dependencies
command: npm install
- save_cache:
key: template-cache-full-{{ checksum "package.json" }}
paths:
- node_modules
- run:
name: Run Lint
command: npm run lint -- --fix
- run:
name: Run Unit tests
command: npm run unit
when: always
- run:
name: Run e2e tests
command: npm run e2e
when: always
- run:
name: Test build
command: npm run build
when: always

scenario_full-karma-airbnb:
<<: *vm_settings
working_directory: ~/project/webpack-template/test-full-karma-airbnb
environment:
- VUE_TEMPL_TEST: full-karma-airbnb
steps:
- attach_workspace:
at: '~/project/webpack-template'
- restore_cache:
key: template-cache-full-karma-airbnb-{{ checksum "package.json" }}
- run:
name: Install npm dependencies
command: npm install
- save_cache:
key: template-cache-full-karma-airbnb-{{ checksum "package.json" }}
paths:
- node_modules
- run:
name: Run Lint
command: npm run lint -- --fix
- run:
name: Run Unit tests
command: npm run unit
when: always
- run:
name: Run e2e tests
command: npm run e2e
when: always
- run:
name: Test build
command: npm run build
when: always


workflows:
version: 2
build_and_test:
jobs:
- install_template_deps
- scenario_minimal:
requires:
- install_template_deps
- scenario_full:
requires:
- install_template_deps
- scenario_full-karma-airbnb:
requires:
- install_template_deps
13 changes: 0 additions & 13 deletions circle.yml

This file was deleted.

21 changes: 19 additions & 2 deletions meta.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('path')
const fs = require('fs')

const {
sortDependencies,
installDependencies,
Expand All @@ -10,9 +11,16 @@ const pkg = require('./package.json')

const templateVersion = pkg.version

const { addTestAnswers } = require('./scenarios')

module.exports = {
metalsmith: {
// When running tests for the template, this adds answers for the selected scenario
before: addTestAnswers
},
helpers: {
if_or(v1, v2, options) {

if (v1 || v2) {
return options.fn(this)
}
Expand All @@ -26,21 +34,25 @@ module.exports = {

prompts: {
name: {
when: 'isNotTest',
type: 'string',
required: true,
message: 'Project name',
},
description: {
when: 'isNotTest',
type: 'string',
required: false,
message: 'Project description',
default: 'A Vue.js project',
},
author: {
when: 'isNotTest',
type: 'string',
message: 'Author',
},
build: {
when: 'isNotTest',
type: 'list',
message: 'Vue build',
choices: [
Expand All @@ -58,15 +70,17 @@ module.exports = {
],
},
router: {
when: 'isNotTest',
type: 'confirm',
message: 'Install vue-router?',
},
lint: {
when: 'isNotTest',
type: 'confirm',
message: 'Use ESLint to lint your code?',
},
lintConfig: {
when: 'lint',
when: 'isNotTest && lint',
type: 'list',
message: 'Pick an ESLint preset',
choices: [
Expand All @@ -88,11 +102,12 @@ module.exports = {
],
},
unit: {
when: 'isNotTest',
type: 'confirm',
message: 'Set up unit tests',
},
runner: {
when: 'unit',
when: 'isNotTest && unit',
type: 'list',
message: 'Pick a test runner',
choices: [
Expand All @@ -114,10 +129,12 @@ module.exports = {
],
},
e2e: {
when: 'isNotTest',
type: 'confirm',
message: 'Setup e2e tests with Nightwatch?',
},
autoInstall: {
when: 'isNotTest',
type: 'list',
message:
'Should we run `npm install` for you after the project has been created? (recommended)',
Expand Down
27 changes: 27 additions & 0 deletions scenarios/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## What is this folder?

This folder contains test scenarios for the automated tests of the template on CircleCI.

Each `.json`file contains an object that represents a set of answers to the questions that vue-cli asks the user when installing the template.

With the code from `index.js`, we insert those answers into the metalsmith metadata and skip the inquirer questions, thus allowing us to run different test scenarios in CI without having to actually provide any answers to inquirer or to mock it.

## The scenarios

We currently have 3 scenrios set up:

1. 'minimal': it basically answers "no" to ever choice, so no router, no elint, no tests
2. 'full': It answers "yes" to every choice. With router, with linting (standard), with full tests (jest & e2e)
3. 'full-airbnb-karma': like 'full', but using airbnb eslint config instead od standard and karma instead of jest for unnit tests.

Other permutations might be worth testing to secure against edge cases, but this gives us a decent level of security over common combinations.

## How to use it?

Choosing a scenario is done through setting an ENV variable named `VUE_TEMPL_TEST`.

You can run a scenario yourself by running this in your terminal:

````
VUE_TEMPL_TEST=minimal vue init webpack your-directory
```
14 changes: 14 additions & 0 deletions scenarios/full-karma-airbnb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"noEscape": true,
"name": "test",
"description": "A Vue.js project",
"author": "CircleCI",
"build": "standalone",
"router": false,
"lint": true,
"lintConfig": "airbnb",
"unit": true,
"runner": "karma",
"e2e": true,
"autoInstall": false
}
14 changes: 14 additions & 0 deletions scenarios/full.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"noEscape": true,
"name": "test",
"description": "A Vue.js project",
"author": "CircleCI",
"build": "runtime",
"router": false,
"lint": true,
"lintConfig": "standard",
"unit": true,
"runner": "jest",
"e2e": true,
"autoInstall": false
}
19 changes: 19 additions & 0 deletions scenarios/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const scenarios = [
'full',
'full-karma-airbnb',
'minimal'
]

const index = scenarios.indexOf(process.env.VUE_TEMPL_TEST)

const isTest = exports.isTest = index !== -1

const scenario = isTest && require(`./${scenarios[index]}.json`)

exports.addTestAnswers = (metalsmith, options, helpers) => {
Object.assign(metalsmith.metadata(), {
isNotTest: !isTest,
...(isTest ? scenario : undefined)
})
// console.log(metalsmith.metadata())
}
14 changes: 14 additions & 0 deletions scenarios/minimal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"noEscape": true,
"name": "test-minimal",
"description": "Testing the minimal template setup",
"author": "CircleCI",
"build": "standalone",
"router": false,
"lint": false,
"lintConfig": "standard",
"unit": false,
"runner": "jest",
"e2e": false,
"autoInstall": false
}
4 changes: 2 additions & 2 deletions template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"test": "{{#unit}}npm run unit{{/unit}}{{#unit}}{{#e2e}} && {{/e2e}}{{/unit}}{{#e2e}}npm run e2e{{/e2e}}",
{{/if_or}}
{{#lint}}
"lint": "eslint --ext .js,.vue src{{#unit}} test/unit/specs{{/unit}}{{#e2e}} test/e2e/specs{{/e2e}}",
"lint": "eslint --ext .js,.vue src{{#unit}} test/unit{{/unit}}{{#e2e}} test/e2e/specs{{/e2e}}",
{{/lint}}
"build": "node build/build.js"
},
Expand Down Expand Up @@ -52,7 +52,7 @@
"babel-jest": "^21.0.2",
"babel-plugin-dynamic-import-node": "^1.2.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
"jest": "^21.2.0",
"jest": "^22.0.4",
"jest-serializer-vue": "^0.3.0",
"vue-jest": "^1.0.2",
{{/if_eq}}
Expand Down
2 changes: 1 addition & 1 deletion template/test/unit/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

var webpackConfig = require('../../build/webpack.test.conf')

module.exports = function (config) {
module.exports = function karmaConfig (config) {
config.set({
// to run in additional browsers:
// 1. install corresponding karma launcher
Expand Down
9 changes: 0 additions & 9 deletions test.sh

This file was deleted.