Skip to content

Commit 52b2d1a

Browse files
authored
chore: add prettier (#128)
1 parent ce6ffa9 commit 52b2d1a

39 files changed

+1106
-403
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 2
22
jobs:
33
build:
44
docker:
5-
- image: circleci/node:7.10
5+
- image: circleci/node:8.10
66

77
working_directory: ~/repo
88

.eslintrc

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{
22
"root": true,
3-
"plugins": [
4-
"vue"
5-
],
63
"extends": [
7-
"plugin:vue-libs/recommended",
8-
]
9-
}
4+
"standard",
5+
"prettier",
6+
"prettier/standard"
7+
],
8+
"rules": {
9+
"no-new": 0
10+
}
11+
}

README.md

+25-30
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ A full config will look like this.
2828
```json
2929
{
3030
"jest": {
31-
"moduleFileExtensions": [
32-
"js",
33-
"json",
34-
"vue"
35-
],
31+
"moduleFileExtensions": ["js", "json", "vue"],
3632
"transform": {
3733
"^.+\\.js$": "babel-jest",
3834
"^.+\\.vue$": "vue-jest"
@@ -63,7 +59,7 @@ vue-jest compiles the script and template of SFCs into a JavaScript file that Je
6359

6460
You can change the behavior of `vue-jest` by using `jest.globals`.
6561

66-
> *Tip:* Need programmatic configuration? Use the [--config](https://jestjs.io/docs/en/cli.html#config-path) option in Jest CLI, and export a `.js` file
62+
> _Tip:_ Need programmatic configuration? Use the [--config](https://jestjs.io/docs/en/cli.html#config-path) option in Jest CLI, and export a `.js` file
6763

6864
#### babelConfig
6965

@@ -112,14 +108,10 @@ Provide inline [Babel options](https://babeljs.io/docs/en/options):
112108
}
113109
]
114110
],
115-
"plugins": [
116-
"syntax-dynamic-import"
117-
],
111+
"plugins": ["syntax-dynamic-import"],
118112
"env": {
119113
"test": {
120-
"plugins": [
121-
"dynamic-import-node"
122-
]
114+
"plugins": ["dynamic-import-node"]
123115
}
124116
}
125117
}
@@ -132,8 +124,9 @@ Provide inline [Babel options](https://babeljs.io/docs/en/options):
132124
##### String
133125

134126
If a string is provided, it will be an assumed path to a babel configuration file (e.g. `.babelrc`, `.babelrc.js`).
127+
135128
- Config file should export a Babel configuration object.
136-
- Should *not* point to a [project-wide configuration file (babel.config.js)](https://babeljs.io/docs/en/config-files#project-wide-configuration), which exports a function.
129+
- Should _not_ point to a [project-wide configuration file (babel.config.js)](https://babeljs.io/docs/en/config-files#project-wide-configuration), which exports a function.
137130

138131
```json
139132
{
@@ -216,21 +209,22 @@ If a string is provided, it will be an assumed path to a TypeScript configuratio
216209
### Supported template languages
217210

218211
- **pug** (`lang="pug"`)
212+
219213
- To give options for the Pug compiler, enter them into the Jest configuration.
220-
The options will be passed to pug.compile().
214+
The options will be passed to pug.compile().
221215

222216
```json
223-
{
224-
"jest": {
225-
"globals": {
226-
"vue-jest": {
227-
"pug": {
228-
"basedir": "mybasedir"
229-
}
217+
{
218+
"jest": {
219+
"globals": {
220+
"vue-jest": {
221+
"pug": {
222+
"basedir": "mybasedir"
230223
}
231224
}
232225
}
233226
}
227+
}
234228
```
235229

236230
- **jade** (`lang="jade"`)
@@ -242,6 +236,7 @@ If a string is provided, it will be an assumed path to a TypeScript configuratio
242236
- **sass** (`lang="sass"`)
243237
- The SASS compiler supports jest's [moduleNameMapper](https://facebook.github.io/jest/docs/en/configuration.html#modulenamemapper-object-string-string) which is the suggested way of dealing with Webpack aliases.
244238
- **scss** (`lang="scss"`)
239+
245240
- The SCSS compiler supports jest's [moduleNameMapper](https://facebook.github.io/jest/docs/en/configuration.html#modulenamemapper-object-string-string) which is the suggested way of dealing with Webpack aliases.
246241
- To import globally included files (ie. variables, mixins, etc.), include them in the Jest configuration at `jest.globals['vue-jest'].resources.scss`:
247242

@@ -268,15 +263,15 @@ If a string is provided, it will be an assumed path to a TypeScript configuratio
268263
`hideStyleWarn`: `Boolean` Default false. Hide warnings about CSS compilation
269264
`resources`:
270265

271-
```json
272-
{
273-
"jest": {
274-
"globals": {
275-
"vue-jest": {
276-
"hideStyleWarn": true,
277-
"experimentalCSSCompile": true
278-
}
266+
```json
267+
{
268+
"jest": {
269+
"globals": {
270+
"vue-jest": {
271+
"hideStyleWarn": true,
272+
"experimentalCSSCompile": true
279273
}
280274
}
281275
}
282-
```
276+
}
277+
```

build/gen-release-note.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ const fileStream = require('fs').createWriteStream(file)
66
cc({
77
preset: 'angular',
88
pkg: {
9-
transform (pkg) {
9+
transform(pkg) {
1010
pkg.version = `v${version}`
1111
return pkg
1212
}
1313
}
14-
}).pipe(fileStream).on('close', () => {
15-
console.log(`Generated release note at ${file}`)
1614
})
15+
.pipe(fileStream)
16+
.on('close', () => {
17+
console.log(`Generated release note at ${file}`)
18+
})

lib/add-template-mapping.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
const splitRE = /\r?\n/g
22

3-
module.exports = function addTemplateMapping (content, parts, output, map, beforeLines) {
3+
module.exports = function addTemplateMapping(
4+
content,
5+
parts,
6+
output,
7+
map,
8+
beforeLines
9+
) {
410
var afterLines = output.split(splitRE).length
5-
var templateLine = content.slice(0, parts.template.start).split(splitRE).length
11+
var templateLine = content.slice(0, parts.template.start).split(splitRE)
12+
.length
613
for (; beforeLines < afterLines; beforeLines++) {
714
map.addMapping({
815
source: map._hashedFilename,

lib/compilers/coffee-compiler.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const ensureRequire = require('../ensure-require.js')
22
const throwError = require('../throw-error')
33
const loadBabelConfig = require('../load-babel-config.js')
44

5-
module.exports = function (raw, config, filePath) {
5+
module.exports = function(raw, config, filePath) {
66
ensureRequire('coffee', ['coffeescript'])
77
var coffee = require('coffeescript')
88
var compiled

lib/compilers/haml-compiler.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var ensureRequire = require('../ensure-require.js')
22
const throwError = require('../throw-error')
33

4-
module.exports = function (raw) {
4+
module.exports = function(raw) {
55
var html
66
ensureRequire('hamljs', 'hamljs')
77
var haml = require('hamljs')

lib/compilers/helpers/local-resolve-helper.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ const path = require('path')
77
* @param {String} localPath - the local path
88
* @returns {String} path - path to the file to import
99
*/
10-
module.exports = function localResolve (to, localPath) {
10+
module.exports = function localResolve(to, localPath) {
1111
if (localPath.startsWith('/')) {
1212
return localPath
1313
}
1414
return path.join(path.dirname(to), localPath)
1515
}
16-

lib/compilers/helpers/module-name-mapper-helper.js

+19-18
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,30 @@ const localResolve = require('./local-resolve-helper')
88
* @param {Object} jestConfig - the jestConfig holding the moduleNameMapper settings
99
* @returns {String} path - the final path to import (including replacements via moduleNameMapper)
1010
*/
11-
module.exports = function applyModuleNameMapper (source, filePath, jestConfig = {}) {
11+
module.exports = function applyModuleNameMapper(
12+
source,
13+
filePath,
14+
jestConfig = {}
15+
) {
1216
if (!jestConfig.moduleNameMapper) return source
1317

1418
// Extract the moduleNameMapper settings from the jest config. TODO: In case of development via babel@7, somehow the jestConfig.moduleNameMapper might end up being an Array. After a proper upgrade to babel@7 we should probably fix this.
15-
const module = Array.isArray(jestConfig.moduleNameMapper) ? jestConfig.moduleNameMapper : Object.entries(jestConfig.moduleNameMapper)
19+
const module = Array.isArray(jestConfig.moduleNameMapper)
20+
? jestConfig.moduleNameMapper
21+
: Object.entries(jestConfig.moduleNameMapper)
1622

17-
const importPath = module
18-
.reduce((acc, [regex, replacement]) => {
19-
const matches = acc.match(regex)
23+
const importPath = module.reduce((acc, [regex, replacement]) => {
24+
const matches = acc.match(regex)
2025

21-
if (matches === null) {
22-
return acc
23-
}
26+
if (matches === null) {
27+
return acc
28+
}
2429

25-
return replacement.replace(
26-
/\$([0-9]+)/g,
27-
(_, index) => matches[parseInt(index, 10)]
28-
)
29-
}, source)
30+
return replacement.replace(
31+
/\$([0-9]+)/g,
32+
(_, index) => matches[parseInt(index, 10)]
33+
)
34+
}, source)
3035

31-
return localResolve(
32-
filePath,
33-
importPath
34-
)
36+
return localResolve(filePath, importPath)
3537
}
36-

lib/compilers/jade-compiler.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var ensureRequire = require('../ensure-require.js')
22
const throwError = require('../throw-error')
33

4-
module.exports = function (raw) {
4+
module.exports = function(raw) {
55
var html
66
ensureRequire('jade', 'jade')
77
var jade = require('jade')

lib/compilers/pug-compiler.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var ensureRequire = require('../ensure-require.js')
22
const throwError = require('../throw-error')
33

4-
module.exports = function (templatePart, config) {
4+
module.exports = function(templatePart, config) {
55
const options = (config && config['pug']) || {}
66
if (templatePart.filename) {
77
options.filename = templatePart.filename

lib/compilers/sass-compiler.js

+17-7
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,25 @@ module.exports = (content, filePath, jestConfig = {}) => {
1919
const sass = require('node-sass')
2020

2121
try {
22-
return sass.renderSync({
23-
data: content,
24-
outputStyle: 'compressed',
25-
indentedSyntax: true,
26-
importer: (url, prev, done) => ({ file: applyModuleNameMapper(url, prev === 'stdin' ? filePath : prev, jestConfig) })
27-
}).css.toString()
22+
return sass
23+
.renderSync({
24+
data: content,
25+
outputStyle: 'compressed',
26+
indentedSyntax: true,
27+
importer: (url, prev, done) => ({
28+
file: applyModuleNameMapper(
29+
url,
30+
prev === 'stdin' ? filePath : prev,
31+
jestConfig
32+
)
33+
})
34+
})
35+
.css.toString()
2836
} catch (err) {
2937
if (!vueJestConfig.hideStyleWarn) {
30-
logger.warn(`There was an error rendering the SASS in ${filePath}. SASS is fully supported by vue-jest. Still some features might throw errors. Webpack aliases are a common cause of errors. If you use Webpack aliases, please use jest's suggested way via moduleNameMapper which is supported.`)
38+
logger.warn(
39+
`There was an error rendering the SASS in ${filePath}. SASS is fully supported by vue-jest. Still some features might throw errors. Webpack aliases are a common cause of errors. If you use Webpack aliases, please use jest's suggested way via moduleNameMapper which is supported.`
40+
)
3141
logger.warn(`Error while compiling styles: ${err}`)
3242
}
3343
}

lib/compilers/scss-compiler.js

+16-6
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,24 @@ module.exports = (content, filePath, jestConfig = {}) => {
3030
}
3131

3232
try {
33-
return sass.renderSync({
34-
data: scssResources + content,
35-
outputStyle: 'compressed',
36-
importer: (url, prev, done) => ({ file: applyModuleNameMapper(url, prev === 'stdin' ? filePath : prev, jestConfig) })
37-
}).css.toString()
33+
return sass
34+
.renderSync({
35+
data: scssResources + content,
36+
outputStyle: 'compressed',
37+
importer: (url, prev, done) => ({
38+
file: applyModuleNameMapper(
39+
url,
40+
prev === 'stdin' ? filePath : prev,
41+
jestConfig
42+
)
43+
})
44+
})
45+
.css.toString()
3846
} catch (err) {
3947
if (!vueJestConfig.hideStyleWarn) {
40-
logger.warn(`There was an error rendering the SCSS in ${filePath}. SCSS is fully supported by vue-jest. Still some features might throw errors. Webpack aliases are a common cause of errors. If you use Webpack aliases, please use jest's suggested way via moduleNameMapper which is supported.`)
48+
logger.warn(
49+
`There was an error rendering the SCSS in ${filePath}. SCSS is fully supported by vue-jest. Still some features might throw errors. Webpack aliases are a common cause of errors. If you use Webpack aliases, please use jest's suggested way via moduleNameMapper which is supported.`
50+
)
4151
logger.warn(`Error while compiling styles: ${err}`)
4252
}
4353
}

lib/compilers/stylus-compiler.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
const stylus = require('stylus')
22
const path = require('path')
33

4-
module.exports = (content, filePath, jestConfig) => stylus.render(
5-
content, {
4+
module.exports = (content, filePath, jestConfig) =>
5+
stylus.render(content, {
66
paths: [path.dirname(filePath), process.cwd()]
7-
}
8-
)
7+
})

lib/compilers/typescript-compiler.js

+12-13
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,31 @@ const { loadTypescriptConfig } = require('../load-typescript-config')
44
const babelJest = require('babel-jest')
55
const getVueJestConfig = require('../get-vue-jest-config')
66

7-
module.exports = function compileTypescript (scriptContent, filePath, config) {
7+
module.exports = function compileTypescript(scriptContent, filePath, config) {
88
ensureRequire('typescript', ['typescript'])
99
const vueJestConfig = getVueJestConfig(config)
1010
const typescript = require('typescript')
1111
const tsConfig = loadTypescriptConfig(vueJestConfig)
1212

1313
const res = typescript.transpileModule(scriptContent, tsConfig)
14-
const inputSourceMap = (res.sourceMapText !== undefined)
15-
? JSON.parse(res.sourceMapText)
16-
: ''
14+
const inputSourceMap =
15+
res.sourceMapText !== undefined ? JSON.parse(res.sourceMapText) : ''
1716

1817
// handle ES modules in TS source code in case user uses non commonjs module
1918
// output and there is no .babelrc.
2019
let inlineBabelConfig = {}
21-
if (tsConfig.compilerOptions.module !== 'commonjs' && !loadBabelConfig(vueJestConfig)) {
20+
if (
21+
tsConfig.compilerOptions.module !== 'commonjs' &&
22+
!loadBabelConfig(vueJestConfig)
23+
) {
2224
inlineBabelConfig = {
23-
plugins: [
24-
require('babel-plugin-transform-es2015-modules-commonjs')
25-
]
25+
plugins: [require('babel-plugin-transform-es2015-modules-commonjs')]
2626
}
2727
}
28-
const transformer = babelJest.createTransformer(Object.assign(
29-
inlineBabelConfig,
30-
{
28+
const transformer = babelJest.createTransformer(
29+
Object.assign(inlineBabelConfig, {
3130
inputSourceMap
32-
}
33-
))
31+
})
32+
)
3433
return transformer.process(res.outputText, filePath, config)
3534
}

0 commit comments

Comments
 (0)