Skip to content

chore: add prettier #128

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

Merged
merged 3 commits into from
Nov 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
build:
docker:
- image: circleci/node:7.10
- image: circleci/node:8.10

working_directory: ~/repo

Expand Down
14 changes: 8 additions & 6 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"root": true,
"plugins": [
"vue"
],
"extends": [
"plugin:vue-libs/recommended",
]
}
"standard",
"prettier",
"prettier/standard"
],
"rules": {
"no-new": 0
}
}
55 changes: 25 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ A full config will look like this.
```json
{
"jest": {
"moduleFileExtensions": [
"js",
"json",
"vue"
],
"moduleFileExtensions": ["js", "json", "vue"],
"transform": {
"^.+\\.js$": "babel-jest",
"^.+\\.vue$": "vue-jest"
Expand Down Expand Up @@ -63,7 +59,7 @@ vue-jest compiles the script and template of SFCs into a JavaScript file that Je

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

> *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
> _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

#### babelConfig

Expand Down Expand Up @@ -112,14 +108,10 @@ Provide inline [Babel options](https://babeljs.io/docs/en/options):
}
]
],
"plugins": [
"syntax-dynamic-import"
],
"plugins": ["syntax-dynamic-import"],
"env": {
"test": {
"plugins": [
"dynamic-import-node"
]
"plugins": ["dynamic-import-node"]
}
}
}
Expand All @@ -132,8 +124,9 @@ Provide inline [Babel options](https://babeljs.io/docs/en/options):
##### String

If a string is provided, it will be an assumed path to a babel configuration file (e.g. `.babelrc`, `.babelrc.js`).

- Config file should export a Babel configuration object.
- 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.
- 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.

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

- **pug** (`lang="pug"`)

- To give options for the Pug compiler, enter them into the Jest configuration.
The options will be passed to pug.compile().
The options will be passed to pug.compile().

```json
{
"jest": {
"globals": {
"vue-jest": {
"pug": {
"basedir": "mybasedir"
}
{
"jest": {
"globals": {
"vue-jest": {
"pug": {
"basedir": "mybasedir"
}
}
}
}
}
```

- **jade** (`lang="jade"`)
Expand All @@ -242,6 +236,7 @@ If a string is provided, it will be an assumed path to a TypeScript configuratio
- **sass** (`lang="sass"`)
- 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.
- **scss** (`lang="scss"`)

- 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.
- To import globally included files (ie. variables, mixins, etc.), include them in the Jest configuration at `jest.globals['vue-jest'].resources.scss`:

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

```json
{
"jest": {
"globals": {
"vue-jest": {
"hideStyleWarn": true,
"experimentalCSSCompile": true
}
```json
{
"jest": {
"globals": {
"vue-jest": {
"hideStyleWarn": true,
"experimentalCSSCompile": true
}
}
}
```
}
```
8 changes: 5 additions & 3 deletions build/gen-release-note.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ const fileStream = require('fs').createWriteStream(file)
cc({
preset: 'angular',
pkg: {
transform (pkg) {
transform(pkg) {
pkg.version = `v${version}`
return pkg
}
}
}).pipe(fileStream).on('close', () => {
console.log(`Generated release note at ${file}`)
})
.pipe(fileStream)
.on('close', () => {
console.log(`Generated release note at ${file}`)
})
11 changes: 9 additions & 2 deletions lib/add-template-mapping.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
const splitRE = /\r?\n/g

module.exports = function addTemplateMapping (content, parts, output, map, beforeLines) {
module.exports = function addTemplateMapping(
content,
parts,
output,
map,
beforeLines
) {
var afterLines = output.split(splitRE).length
var templateLine = content.slice(0, parts.template.start).split(splitRE).length
var templateLine = content.slice(0, parts.template.start).split(splitRE)
.length
for (; beforeLines < afterLines; beforeLines++) {
map.addMapping({
source: map._hashedFilename,
Expand Down
2 changes: 1 addition & 1 deletion lib/compilers/coffee-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const ensureRequire = require('../ensure-require.js')
const throwError = require('../throw-error')
const loadBabelConfig = require('../load-babel-config.js')

module.exports = function (raw, config, filePath) {
module.exports = function(raw, config, filePath) {
ensureRequire('coffee', ['coffeescript'])
var coffee = require('coffeescript')
var compiled
Expand Down
2 changes: 1 addition & 1 deletion lib/compilers/haml-compiler.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var ensureRequire = require('../ensure-require.js')
const throwError = require('../throw-error')

module.exports = function (raw) {
module.exports = function(raw) {
var html
ensureRequire('hamljs', 'hamljs')
var haml = require('hamljs')
Expand Down
3 changes: 1 addition & 2 deletions lib/compilers/helpers/local-resolve-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ const path = require('path')
* @param {String} localPath - the local path
* @returns {String} path - path to the file to import
*/
module.exports = function localResolve (to, localPath) {
module.exports = function localResolve(to, localPath) {
if (localPath.startsWith('/')) {
return localPath
}
return path.join(path.dirname(to), localPath)
}

37 changes: 19 additions & 18 deletions lib/compilers/helpers/module-name-mapper-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,30 @@ const localResolve = require('./local-resolve-helper')
* @param {Object} jestConfig - the jestConfig holding the moduleNameMapper settings
* @returns {String} path - the final path to import (including replacements via moduleNameMapper)
*/
module.exports = function applyModuleNameMapper (source, filePath, jestConfig = {}) {
module.exports = function applyModuleNameMapper(
source,
filePath,
jestConfig = {}
) {
if (!jestConfig.moduleNameMapper) return source

// 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.
const module = Array.isArray(jestConfig.moduleNameMapper) ? jestConfig.moduleNameMapper : Object.entries(jestConfig.moduleNameMapper)
const module = Array.isArray(jestConfig.moduleNameMapper)
? jestConfig.moduleNameMapper
: Object.entries(jestConfig.moduleNameMapper)

const importPath = module
.reduce((acc, [regex, replacement]) => {
const matches = acc.match(regex)
const importPath = module.reduce((acc, [regex, replacement]) => {
const matches = acc.match(regex)

if (matches === null) {
return acc
}
if (matches === null) {
return acc
}

return replacement.replace(
/\$([0-9]+)/g,
(_, index) => matches[parseInt(index, 10)]
)
}, source)
return replacement.replace(
/\$([0-9]+)/g,
(_, index) => matches[parseInt(index, 10)]
)
}, source)

return localResolve(
filePath,
importPath
)
return localResolve(filePath, importPath)
}

2 changes: 1 addition & 1 deletion lib/compilers/jade-compiler.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var ensureRequire = require('../ensure-require.js')
const throwError = require('../throw-error')

module.exports = function (raw) {
module.exports = function(raw) {
var html
ensureRequire('jade', 'jade')
var jade = require('jade')
Expand Down
2 changes: 1 addition & 1 deletion lib/compilers/pug-compiler.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var ensureRequire = require('../ensure-require.js')
const throwError = require('../throw-error')

module.exports = function (templatePart, config) {
module.exports = function(templatePart, config) {
const options = (config && config['pug']) || {}
if (templatePart.filename) {
options.filename = templatePart.filename
Expand Down
24 changes: 17 additions & 7 deletions lib/compilers/sass-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,25 @@ module.exports = (content, filePath, jestConfig = {}) => {
const sass = require('node-sass')

try {
return sass.renderSync({
data: content,
outputStyle: 'compressed',
indentedSyntax: true,
importer: (url, prev, done) => ({ file: applyModuleNameMapper(url, prev === 'stdin' ? filePath : prev, jestConfig) })
}).css.toString()
return sass
.renderSync({
data: content,
outputStyle: 'compressed',
indentedSyntax: true,
importer: (url, prev, done) => ({
file: applyModuleNameMapper(
url,
prev === 'stdin' ? filePath : prev,
jestConfig
)
})
})
.css.toString()
} catch (err) {
if (!vueJestConfig.hideStyleWarn) {
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.`)
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.`
)
logger.warn(`Error while compiling styles: ${err}`)
}
}
Expand Down
22 changes: 16 additions & 6 deletions lib/compilers/scss-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,24 @@ module.exports = (content, filePath, jestConfig = {}) => {
}

try {
return sass.renderSync({
data: scssResources + content,
outputStyle: 'compressed',
importer: (url, prev, done) => ({ file: applyModuleNameMapper(url, prev === 'stdin' ? filePath : prev, jestConfig) })
}).css.toString()
return sass
.renderSync({
data: scssResources + content,
outputStyle: 'compressed',
importer: (url, prev, done) => ({
file: applyModuleNameMapper(
url,
prev === 'stdin' ? filePath : prev,
jestConfig
)
})
})
.css.toString()
} catch (err) {
if (!vueJestConfig.hideStyleWarn) {
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.`)
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.`
)
logger.warn(`Error while compiling styles: ${err}`)
}
}
Expand Down
7 changes: 3 additions & 4 deletions lib/compilers/stylus-compiler.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const stylus = require('stylus')
const path = require('path')

module.exports = (content, filePath, jestConfig) => stylus.render(
content, {
module.exports = (content, filePath, jestConfig) =>
stylus.render(content, {
paths: [path.dirname(filePath), process.cwd()]
}
)
})
25 changes: 12 additions & 13 deletions lib/compilers/typescript-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,31 @@ const { loadTypescriptConfig } = require('../load-typescript-config')
const babelJest = require('babel-jest')
const getVueJestConfig = require('../get-vue-jest-config')

module.exports = function compileTypescript (scriptContent, filePath, config) {
module.exports = function compileTypescript(scriptContent, filePath, config) {
ensureRequire('typescript', ['typescript'])
const vueJestConfig = getVueJestConfig(config)
const typescript = require('typescript')
const tsConfig = loadTypescriptConfig(vueJestConfig)

const res = typescript.transpileModule(scriptContent, tsConfig)
const inputSourceMap = (res.sourceMapText !== undefined)
? JSON.parse(res.sourceMapText)
: ''
const inputSourceMap =
res.sourceMapText !== undefined ? JSON.parse(res.sourceMapText) : ''

// handle ES modules in TS source code in case user uses non commonjs module
// output and there is no .babelrc.
let inlineBabelConfig = {}
if (tsConfig.compilerOptions.module !== 'commonjs' && !loadBabelConfig(vueJestConfig)) {
if (
tsConfig.compilerOptions.module !== 'commonjs' &&
!loadBabelConfig(vueJestConfig)
) {
inlineBabelConfig = {
plugins: [
require('babel-plugin-transform-es2015-modules-commonjs')
]
plugins: [require('babel-plugin-transform-es2015-modules-commonjs')]
}
}
const transformer = babelJest.createTransformer(Object.assign(
inlineBabelConfig,
{
const transformer = babelJest.createTransformer(
Object.assign(inlineBabelConfig, {
inputSourceMap
}
))
})
)
return transformer.process(res.outputText, filePath, config)
}
Loading