-
Notifications
You must be signed in to change notification settings - Fork 157
fix(ts-config): remove dependency on ts-jest and configure tsconfif w… #161
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "ES2015", | ||
"isolatedModules": false, | ||
"experimentalDecorators": true, | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strictNullChecks": true, | ||
"removeComments": true, | ||
"emitDecoratorMetadata": true, | ||
"suppressImplicitAnyIndexErrors": true, | ||
"allowSyntheticDefaultImports": true, | ||
"sourceMap": true | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "babel-in-package", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"private": true, | ||
"scripts": { | ||
"test": "jest --no-cache test.js" | ||
}, | ||
"dependencies": { | ||
"vue": "^2.5.21", | ||
"vue-template-compiler": "^2.5.21" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.2.2", | ||
"@babel/preset-env": "^7.2.3", | ||
"@vue/test-utils": "^1.0.0-beta.28", | ||
"jest": "^24.0.0", | ||
"vue-jest": "file:../../../" | ||
}, | ||
"jest": { | ||
"moduleFileExtensions": [ | ||
"js", | ||
"json", | ||
"vue" | ||
], | ||
"transform": { | ||
"^.+\\.js$": "babel-jest", | ||
"^.+\\.vue$": "vue-jest" | ||
} | ||
}, | ||
"babel": { | ||
"presets": [ | ||
"@babel/env" | ||
] | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { getTSConfig } from 'vue-jest/lib/utils' | ||
import ts from 'typescript' | ||
|
||
describe('tsconfig options', () => { | ||
test('should extend the tsconfig when extends options is used', () => { | ||
const { compilerOptions } = getTSConfig() | ||
expect(compilerOptions.strictNullChecks).toBeTruthy() | ||
expect(compilerOptions.module).toBe(ts.ModuleKind.ES2015) | ||
}) | ||
|
||
test('should read tsconfig from root when not assigned', () => { | ||
const { compilerOptions } = getTSConfig() | ||
expect(compilerOptions.strictNullChecks).toBeTruthy() | ||
expect(compilerOptions.module).toBe(ts.ModuleKind.ES2015) | ||
}) | ||
|
||
test('should read tsconfig from ts-jest when used in jest config', () => { | ||
const { compilerOptions } = getTSConfig({ | ||
globals: { | ||
'ts-jest': { | ||
tsConfig: './tsconfig.json' | ||
} | ||
} | ||
}) | ||
expect(compilerOptions.outDir).toBe('$$ts-jest$$') | ||
}) | ||
|
||
test('should read from tsConfig object when specified in vue-jest config', () => { | ||
const { compilerOptions } = getTSConfig({ | ||
globals: { | ||
'vue-jest': { | ||
tsConfig: { | ||
compilerOptions: { | ||
target: 'ES2016' | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
expect(compilerOptions.target).toBe(ts.ScriptTarget[ts.ScriptTarget.ES2016]) | ||
}) | ||
|
||
test('should read user configured file path when specified in vue-jest config', () => { | ||
const { compilerOptions } = getTSConfig({ | ||
globals: { | ||
'vue-jest': { | ||
tsConfig: './config/base-tsconfig.json' | ||
} | ||
} | ||
}) | ||
expect(compilerOptions.module).toBe(ts.ModuleKind.ES2015) | ||
expect(compilerOptions.moduleResolution).toBeUndefined() | ||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "./config/base-tsconfig.json", | ||
"compilerOptions": { | ||
"target": "ES2017", | ||
"lib": ["dom", "es6"], | ||
"moduleResolution": "node", | ||
"types": ["vue-typescript-import-dts", "node"] | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
const loadPartialConfig = require('@babel/core').loadPartialConfig | ||
const createTransformer = require('ts-jest').createTransformer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will still error if users don't have TypeScript installed, can you move the require to inside the |
||
const chalk = require('chalk') | ||
const fs = require('fs') | ||
const ts = require('typescript') | ||
const path = require('path') | ||
|
||
const fetchTransformer = function fetchTransformer(key, obj) { | ||
|
@@ -62,10 +64,46 @@ const getBabelOptions = function loadBabelOptions(filename, options = {}) { | |
return loadPartialConfig(opts).options | ||
} | ||
|
||
const getTsJestConfig = function getTsJestConfig(config) { | ||
const tr = createTransformer() | ||
const { typescript } = tr.configsFor(config) | ||
return { compilerOptions: typescript.options } | ||
const getTSConfig = function getTSConfig(config = {}) { | ||
const vueTsConfig = getVueJestConfig(config) | ||
if (typeof vueTsConfig.tsConfig === 'string') { | ||
return parseTSConfigFile(vueTsConfig.tsConfig) | ||
} else if (typeof vueTsConfig.tsConfig === 'object') { | ||
return vueTsConfig.tsConfig | ||
} else if (config.globals && config.globals['ts-jest']) { | ||
const tr = createTransformer() | ||
const { | ||
typescript: { options: compilerOptions } | ||
} = tr.configsFor(config) | ||
return { compilerOptions } | ||
} else { | ||
// auto pick tsconfig from the root folder | ||
return parseTSConfigFile() | ||
} | ||
} | ||
|
||
const parseTSConfigFile = function parseTSConfigFile( | ||
pathToConfig = path.resolve(process.cwd(), './tsconfig.json') | ||
) { | ||
if (!fs.existsSync(pathToConfig)) { | ||
return { | ||
compilerOptions: {} | ||
} | ||
} | ||
const configJson = ts.parseConfigFileTextToJson( | ||
pathToConfig, | ||
ts.sys.readFile(pathToConfig) | ||
) | ||
const { options: compilerOptions } = ts.parseJsonConfigFileContent( | ||
configJson.config, | ||
ts.sys, | ||
ts.getDirectoryPath(pathToConfig), | ||
{}, | ||
pathToConfig | ||
) | ||
return { | ||
compilerOptions | ||
} | ||
} | ||
|
||
function isValidTransformer(transformer) { | ||
|
@@ -119,7 +157,7 @@ module.exports = { | |
throwError, | ||
logResultErrors, | ||
getCustomTransformer, | ||
getTsJestConfig, | ||
getTSConfig, | ||
getBabelOptions, | ||
getVueJestConfig, | ||
transformContent, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This directory is intended for e2e tests