Skip to content

Commit ea45492

Browse files
author
Vamsi Kalyan A
committed
add unit test cases, remove ts-jest dependency
1 parent 78b1551 commit ea45492

File tree

10 files changed

+50
-115
lines changed

10 files changed

+50
-115
lines changed
File renamed without changes.

e2e/__projects__/tsconfig/test.js renamed to __tests__/utils.spec.js

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { getTSConfig } from 'vue-jest/lib/utils'
1+
import { getTSConfig } from '../lib/utils'
2+
import { resolve } from 'path'
23
import ts from 'typescript'
34

45
describe('tsconfig options', () => {
@@ -14,17 +15,6 @@ describe('tsconfig options', () => {
1415
expect(compilerOptions.module).toBe(ts.ModuleKind.ES2015)
1516
})
1617

17-
test('should read tsconfig from ts-jest when used in jest config', () => {
18-
const { compilerOptions } = getTSConfig({
19-
globals: {
20-
'ts-jest': {
21-
tsConfig: './tsconfig.json'
22-
}
23-
}
24-
})
25-
expect(compilerOptions.outDir).toBe('$$ts-jest$$')
26-
})
27-
2818
test('should read from tsConfig object when specified in vue-jest config', () => {
2919
const { compilerOptions } = getTSConfig({
3020
globals: {
@@ -44,7 +34,7 @@ describe('tsconfig options', () => {
4434
const { compilerOptions } = getTSConfig({
4535
globals: {
4636
'vue-jest': {
47-
tsConfig: './config/base-tsconfig.json'
37+
tsConfig: resolve(__dirname, '../__mocks__/config/base-tsconfig.json')
4838
}
4939
}
5040
})

e2e/__projects__/tsconfig/package.json

-37
This file was deleted.

lib/index.js

-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const crypto = require('crypto')
22
const babelJest = require('babel-jest')
3-
const tsJest = require('ts-jest')
43

54
module.exports = {
65
process: require('./process'),
@@ -20,13 +19,6 @@ module.exports = {
2019
}),
2120
'hex'
2221
)
23-
.update(
24-
tsJest.getCacheKey(fileData, filename, configString, {
25-
instrument,
26-
rootDir
27-
}),
28-
'hex'
29-
)
3022
.digest('hex')
3123
}
3224
}

lib/typescript-transformer.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
const ensureRequire = require('./ensure-require')
21
const babelJest = require('babel-jest')
32
const getBabelOptions = require('./utils').getBabelOptions
43
const getTSConfig = require('./utils').getTSConfig
54
const stripInlineSourceMap = require('./utils').stripInlineSourceMap
65
const getCustomTransformer = require('./utils').getCustomTransformer
76
const getVueJestConfig = require('./utils').getVueJestConfig
7+
const getTSCInstance = require('./utils').getTSCInstance()
88

99
module.exports = {
1010
process(scriptContent, filePath, config) {
11-
ensureRequire('typescript', ['typescript'])
12-
const typescript = require('typescript')
11+
const typescript = getTSCInstance()
1312
const vueJestConfig = getVueJestConfig(config)
1413
const tsconfig = getTSConfig(config)
1514
const babelOptions = getBabelOptions(filePath)
16-
15+
1716
const res = typescript.transpileModule(scriptContent, tsconfig)
1817

1918
res.outputText = stripInlineSourceMap(res.outputText)

lib/utils.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
const loadPartialConfig = require('@babel/core').loadPartialConfig
2-
const createTransformer = require('ts-jest').createTransformer
32
const chalk = require('chalk')
43
const fs = require('fs')
5-
const ts = require('typescript')
4+
const ensureRequire = require('./ensure-require')
65
const path = require('path')
76

87
const fetchTransformer = function fetchTransformer(key, obj) {
@@ -70,12 +69,6 @@ const getTSConfig = function getTSConfig(config = {}) {
7069
return parseTSConfigFile(vueTsConfig.tsConfig)
7170
} else if (typeof vueTsConfig.tsConfig === 'object') {
7271
return vueTsConfig.tsConfig
73-
} else if (config.globals && config.globals['ts-jest']) {
74-
const tr = createTransformer()
75-
const {
76-
typescript: { options: compilerOptions }
77-
} = tr.configsFor(config)
78-
return { compilerOptions }
7972
} else {
8073
// auto pick tsconfig from the root folder
8174
return parseTSConfigFile()
@@ -85,6 +78,7 @@ const getTSConfig = function getTSConfig(config = {}) {
8578
const parseTSConfigFile = function parseTSConfigFile(
8679
pathToConfig = path.resolve(process.cwd(), './tsconfig.json')
8780
) {
81+
const ts = getTSCInstance()
8882
if (!fs.existsSync(pathToConfig)) {
8983
return {
9084
compilerOptions: {}
@@ -152,6 +146,11 @@ const logResultErrors = result => {
152146
}
153147
}
154148

149+
const getTSCInstance = function getTSCInstance() {
150+
ensureRequire('typescript', ['typescript'])
151+
return require('typescript')
152+
}
153+
155154
module.exports = {
156155
stripInlineSourceMap,
157156
throwError,
@@ -164,5 +163,6 @@ module.exports = {
164163
info,
165164
warn,
166165
resolvePath,
167-
fetchTransformer
166+
fetchTransformer,
167+
getTSCInstance
168168
}

package.json

+26-4
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
"lint": "eslint --ignore-path .gitignore '{,!(node_modules)/**/}*.js'",
2424
"lint:fix": "npm run lint --fix",
2525
"release": "semantic-release",
26-
"test": "npm run lint && npm run format:check && npm run test:e2e",
27-
"test:e2e": "node e2e/test-runner"
26+
"test": "npm run lint && npm run format:check && npm run test:e2e && npm run test:unit",
27+
"test:e2e": "node e2e/test-runner",
28+
"test:unit": "jest --no-cache --coverage"
2829
},
2930
"author": "Edd Yerburgh",
3031
"license": "MIT",
@@ -71,8 +72,7 @@
7172
"@vue/component-compiler-utils": "^2.4.0",
7273
"chalk": "^2.1.0",
7374
"extract-from-css": "^0.4.4",
74-
"source-map": "^0.5.6",
75-
"ts-jest": "^23.10.5"
75+
"source-map": "^0.5.6"
7676
},
7777
"repository": {
7878
"type": "git",
@@ -88,5 +88,27 @@
8888
"npm run format",
8989
"git add"
9090
]
91+
},
92+
"jest": {
93+
"testPathIgnorePatterns": [
94+
"<rootDir>/e2e"
95+
],
96+
"coveragePathIgnorePatterns": [
97+
"<rootDir>/e2e",
98+
"<rootDir>/__mocks__"
99+
],
100+
"moduleFileExtensions": [
101+
"js",
102+
"json",
103+
"vue"
104+
],
105+
"transform": {
106+
"^.+\\.js$": "babel-jest"
107+
}
108+
},
109+
"babel": {
110+
"presets": [
111+
"@babel/env"
112+
]
91113
}
92114
}

tsconfig.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "./__mocks__/tsconfig.json"
3+
}

yarn.lock

+6-40
Original file line numberDiff line numberDiff line change
@@ -1428,13 +1428,6 @@ browserslist@^4.3.4:
14281428
electron-to-chromium "^1.3.92"
14291429
node-releases "^1.1.1"
14301430

1431-
1432-
version "0.2.6"
1433-
resolved "https://registry.yarnpkg.com/bs-logger/-/bs-logger-0.2.6.tgz#eb7d365307a72cf974cc6cda76b68354ad336bd8"
1434-
integrity sha512-pd8DCoxmbgc7hyPKOvxtqNcjYoOsABPQdcCUjGp3d42VR2CX1ORhk2A87oqqu5R1kk+76nsxZupkmyd+MVtCog==
1435-
dependencies:
1436-
fast-json-stable-stringify "2.x"
1437-
14381431
bser@^2.0.0:
14391432
version "2.0.0"
14401433
resolved "https://registry.yarnpkg.com/bser/-/bser-2.0.0.tgz#9ac78d3ed5d915804fd87acb158bc797147a1719"
@@ -1447,7 +1440,7 @@ btoa-lite@^1.0.0:
14471440
resolved "https://registry.yarnpkg.com/btoa-lite/-/btoa-lite-1.0.0.tgz#337766da15801210fdd956c22e9c6891ab9d0337"
14481441
integrity sha1-M3dm2hWAEhD92VbCLpxokaudAzc=
14491442

1450-
buffer-from@1.x, buffer-from@^1.0.0:
1443+
buffer-from@^1.0.0:
14511444
version "1.1.1"
14521445
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
14531446
integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==
@@ -3125,7 +3118,7 @@ fast-glob@^2.0.2:
31253118
merge2 "^1.2.3"
31263119
micromatch "^3.1.10"
31273120

3128-
fast-json-stable-stringify@2.x, fast-json-stable-stringify@^2.0.0:
3121+
fast-json-stable-stringify@^2.0.0:
31293122
version "2.0.0"
31303123
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2"
31313124
integrity sha1-1RQsDK7msRifh9OnYREGT4bIu/I=
@@ -4991,7 +4984,7 @@ json-stringify-safe@^5.0.1, json-stringify-safe@~5.0.1:
49914984
resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb"
49924985
integrity sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=
49934986

4994-
json5@2.x, json5@^2.1.0:
4987+
json5@^2.1.0:
49954988
version "2.1.0"
49964989
resolved "https://registry.yarnpkg.com/json5/-/json5-2.1.0.tgz#e7a0c62c48285c628d20a10b85c89bb807c32850"
49974990
integrity sha512-8Mh9h6xViijj36g7Dxi+Y4S6hNGV96vcJZr/SrlHh1LR/pEn/8j/+qIBbs44YKl69Lrfctp4QD+AdWLTMqEZAQ==
@@ -5507,11 +5500,6 @@ make-dir@^1.0.0, make-dir@^1.3.0:
55075500
dependencies:
55085501
pify "^3.0.0"
55095502

5510-
5511-
version "1.3.5"
5512-
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.5.tgz#efe4e81f6db28cadd605c70f29c831b58ef776c8"
5513-
integrity sha512-c3sIjNUow0+8swNwVpqoH4YCShKNFkMaw6oH1mNS2haDZQqkeZFlHS3dhoeEbKKmJB4vXpJucU6oH75aDYeE9g==
5514-
55155503
"make-fetch-happen@^2.5.0 || 3 || 4", make-fetch-happen@^4.0.1:
55165504
version "4.0.1"
55175505
resolved "https://registry.yarnpkg.com/make-fetch-happen/-/make-fetch-happen-4.0.1.tgz#141497cb878f243ba93136c83d8aba12c216c083"
@@ -5836,7 +5824,7 @@ mixin-deep@^1.2.0:
58365824
for-in "^1.0.2"
58375825
is-extendable "^1.0.1"
58385826

5839-
[email protected], [email protected], "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1:
5827+
[email protected], "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1:
58405828
version "0.5.1"
58415829
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
58425830
integrity sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=
@@ -7561,7 +7549,7 @@ [email protected]:
75617549
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b"
75627550
integrity sha1-IDEU2CrSxe2ejgQRs5ModeiJ6Xs=
75637551

7564-
resolve@1.x, resolve@^1.1.6, resolve@^1.3.2, resolve@^1.5.0, resolve@^1.6.0, resolve@^1.8.1:
7552+
resolve@^1.1.6, resolve@^1.3.2, resolve@^1.5.0, resolve@^1.6.0, resolve@^1.8.1:
75657553
version "1.9.0"
75667554
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.9.0.tgz#a14c6fdfa8f92a7df1d996cb7105fa744658ea06"
75677555
integrity sha512-TZNye00tI67lwYvzxCxHGjwTNlUV70io54/Ed4j6PscB8xVfuBJpRenI/o6dVk0cY0PYTY27AgCoGGxRnYuItQ==
@@ -7754,7 +7742,7 @@ semver-regex@^2.0.0:
77547742
resolved "https://registry.yarnpkg.com/semver-regex/-/semver-regex-2.0.0.tgz#a93c2c5844539a770233379107b38c7b4ac9d338"
77557743
integrity sha512-mUdIBBvdn0PLOeP3TEkMH7HHeUP3GjsXCwKarjv/kGmUFOYg1VqEemKhoQpWMu6X2I8kHeuVdGibLGkVK+/5Qw==
77567744

7757-
"semver@2 >=2.2.1 || 3.x || 4 || 5", "semver@2 || 3 || 4 || 5", "[email protected] || 3.x || 4 || 5", "semver@^2.3.0 || 3.x || 4 || 5", semver@^5.0.3, semver@^5.1.0, semver@^5.3.0, semver@^5.4.1, semver@^5.5, semver@^5.5.0, semver@^5.5.1:
7745+
"semver@2 >=2.2.1 || 3.x || 4 || 5", "semver@2 || 3 || 4 || 5", "[email protected] || 3.x || 4 || 5", "semver@^2.3.0 || 3.x || 4 || 5", semver@^5.0.3, semver@^5.1.0, semver@^5.3.0, semver@^5.4.1, semver@^5.5.0, semver@^5.5.1:
77587746
version "5.6.0"
77597747
resolved "https://registry.yarnpkg.com/semver/-/semver-5.6.0.tgz#7e74256fbaa49c75aa7c7a205cc22799cac80004"
77607748
integrity sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg==
@@ -8530,21 +8518,6 @@ trim-right@^1.0.1:
85308518
dependencies:
85318519
glob "^7.1.2"
85328520

8533-
ts-jest@^23.10.5:
8534-
version "23.10.5"
8535-
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-23.10.5.tgz#cdb550df4466a30489bf70ba867615799f388dd5"
8536-
integrity sha512-MRCs9qnGoyKgFc8adDEntAOP64fWK1vZKnOYU1o2HxaqjdJvGqmkLCPCnVq1/If4zkUmEjKPnCiUisTrlX2p2A==
8537-
dependencies:
8538-
bs-logger "0.x"
8539-
buffer-from "1.x"
8540-
fast-json-stable-stringify "2.x"
8541-
json5 "2.x"
8542-
make-error "1.x"
8543-
mkdirp "0.x"
8544-
resolve "1.x"
8545-
semver "^5.5"
8546-
yargs-parser "10.x"
8547-
85488521
tslib@^1.9.0:
85498522
version "1.9.3"
85508523
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286"
@@ -9074,13 +9047,6 @@ yallist@^3.0.0, yallist@^3.0.2:
90749047
resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.0.3.tgz#b4b049e314be545e3ce802236d6cd22cd91c3de9"
90759048
integrity sha512-S+Zk8DEWE6oKpV+vI3qWkaK+jSbIK86pCwe2IF/xwIpQ8jEuxpw9NyaGjmp9+BoJv5FV2piqCDcoCtStppiq2A==
90769049

9077-
9078-
version "10.1.0"
9079-
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-10.1.0.tgz#7202265b89f7e9e9f2e5765e0fe735a905edbaa8"
9080-
integrity sha512-VCIyR1wJoEBZUqk5PA+oOBF6ypbwh5aNB3I50guxAL/quggdfs4TtNHQrSazFA3fYZ+tEqfs0zIGlv0c/rgjbQ==
9081-
dependencies:
9082-
camelcase "^4.1.0"
9083-
90849050
yargs-parser@^11.1.1:
90859051
version "11.1.1"
90869052
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-11.1.1.tgz#879a0865973bca9f6bab5cbdf3b1c67ec7d3bcf4"

0 commit comments

Comments
 (0)