Skip to content

implements a custom typescript config possibility in compilers/typesc… #53

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
wants to merge 3 commits into from
Closed
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
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# vue-jest
# vue-jest-kn
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have you changed the package name?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had to change it temporarily to have an npm with it to integrate.
Will be changed back once I have the time to refactor to jest-globals.
Should have made another fork .. my bad ;)


Jest Vue transformer with source map support<br />
custom tsconfig support - temporary npm, please avoid usage as it will be deleted sooner than later

Jest Vue transformer with source map support

## Usage

```
npm install --save-dev vue-jest
npm install --save-dev vue-jest-kn
```

## Setup
Expand All @@ -14,7 +16,7 @@ To define vue-jest as a transformer for your .vue files, you need to map .vue fi

```
"transform": {
".*\\.(vue)$": "<rootDir>/node_modules/vue-jest"
".*\\.(vue)$": "<rootDir>/node_modules/vue-jest-kn"
},
```

Expand All @@ -30,7 +32,7 @@ To use source maps, you need to set `mapCoverage` to `true`. A full config will
],
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
".*\\.(vue)$": "<rootDir>/node_modules/vue-jest"
".*\\.(vue)$": "<rootDir>/node_modules/vue-jest-kn"
},
"mapCoverage": true
}
Expand Down
8 changes: 7 additions & 1 deletion lib/compilers/typescript-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const compileBabel = require('./babel-compiler')
const loadBabelConfig = require('../load-babel-config.js')
const cache = require('../cache')
const logger = require('../logger')
const fs = require('fs')

const defaultTypescriptConfig = {
'compilerOptions': {
Expand Down Expand Up @@ -34,7 +35,12 @@ function getTypescriptConfig () {
if (cachedConfig) {
return cachedConfig
} else {
const { config } = tsconfig.loadSync(process.cwd())
const tscPath = process.cwd()
let tscFile = 'tsconfig.jest.json'
if (!fs.existsSync(tscPath+ '/'+ tscFile)){
tscFile = false
}
const { config } = tsconfig.loadSync(tscPath, tscFile)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use a jest global to get the file name, similarly to how ts-jest does it—https://github.com/kulshekhar/ts-jest/blob/master/src/preprocessor.ts#L17

You can pass a global in in the Jest config object:

{
  "jest": {
    "globals": {
      "vue-jest": {
        "tsConfigFile": "my-tsconfig.json"
      }
    }
  }
}


if (!config) {
logger.info('no tsconfig.json found, defaulting to default typescript options')
Expand Down
16 changes: 12 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vue-jest",
"name": "vue-jest-kn",
"version": "2.0.1",
"description": "Jest Vue transform",
"description": "Jest Vue transform that loads a custom tsconfig - temporary",
"main": "vue-jest.js",
"files": [
"vue-jest.js",
Expand All @@ -27,7 +27,7 @@
"unit": "./test.sh",
"unit:run": "jest test --no-cache --runInBand --coverage --coverageDirectory test/coverage"
},
"author": "Edd Yerburgh",
"author": "Edd Yerburgh, Lars Eggert",
"license": "MIT",
"devDependencies": {
"babel-core": "^6.25.0",
Expand Down Expand Up @@ -82,6 +82,14 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/eddyerburgh/vue-jest.git"
"url": "git+https://github.com/webforgeeu/vue-jest"
},
"bugs": {
"url": "https://github.com/webforgeeu/vue-jest/issues"
},
"homepage": "https://github.com/webforgeeu/vue-jest#readme",
"directories": {
"lib": "lib",
"test": "test"
}
}