Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

feat: use ts-jest for TypeScript config resolution #139

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 18 commits into from
Jan 5, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Strip comments from TS
  • Loading branch information
eddyerburgh committed Jan 5, 2019
commit 74c67ce80ff00d233a74c7af2f72c9523f990198
7 changes: 4 additions & 3 deletions 7 lib/compilers/typescript-compiler.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
const ensureRequire = require('../ensure-require')
const babelJest = require('babel-jest')
const getVueJestConfig = require('../utils').getVueJestConfig
const getBabelOptions = require('../utils').getBabelOptions
const createTransformer = require('ts-jest').createTransformer
const getTsJestConfig = require('../utils').getTsJestConfig
const stripInlineSourceMapComment = require('../utils')
.stripInlineSourceMapComment

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

const { tsconfig } = getTsJestConfig(config)
const babelConfig = getBabelOptions(filePath)

const res = typescript.transpileModule(scriptContent, tsconfig)

res.outputText = stripInlineSourceMapComment(res.outputText)

const inputSourceMap =
res.sourceMapText !== undefined ? JSON.parse(res.sourceMapText) : ''

Expand Down
7 changes: 3 additions & 4 deletions 7 lib/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const join = path.join
const getVueJestConfig = require('./utils').getVueJestConfig
const throwError = require('./utils').throwError
const warn = require('./utils').warn
const stripInlineSourceMapComment = require('./utils')
.stripInlineSourceMapComment
const splitRE = /\r?\n/g
const babelJest = require('babel-jest')
const compilerUtils = require('@vue/component-compiler-utils')
Expand Down Expand Up @@ -54,10 +56,7 @@ module.exports = function(src, filePath, config) {

const result = processScript(parts.script, filePath, config)
let compiledScriptContent = result.code
compiledScriptContent = compiledScriptContent.slice(
0,
compiledScriptContent.indexOf('//# sourceMappingURL')
)
compiledScriptContent = stripInlineSourceMapComment(compiledScriptContent)
const inputMap = result.map

const map = generateSourceMap(
Expand Down
4 changes: 4 additions & 0 deletions 4 lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ module.exports.warn = function warn(msg) {
module.exports.throwError = function error(msg) {
throw new Error('\n[vue-jest] Error: ' + msg + '\n')
}

module.exports.stripInlineSourceMapComment = function(str) {
return str.slice(0, str.indexOf('//# sourceMappingURL'))
}
9 changes: 4 additions & 5 deletions 9 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@
"release:note": "node build/gen-release-note.js",
"test": "npm run lint && npm run test:unit",
"test:unit": "./test.sh",
"test:unit:run": "jest test/coffee.spec.js --no-cache --runInBand --coverage --coverageDirectory test/coverage"
"test:unit:run": "jest test --no-cache --runInBand --coverage --coverageDirectory test/coverage"
},
"author": "Edd Yerburgh",
"license": "MIT",
"devDependencies": {
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.2.3",
"@vue/test-utils": "^1.0.0-beta.25",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^24.0.0-alpha.9",
"babel-plugin-istanbul": "^5.1.0",
"clear-module": "^2.1.0",
Expand All @@ -56,7 +55,7 @@
"prettier": "^1.15.2",
"pug": "^2.0.3",
"stylus": "^0.54.5",
"typescript": "^2.5.2",
"typescript": "^3.2.2",
"vue": "^2.4.2",
"vue-template-compiler": "^2.4.2"
},
Expand All @@ -81,8 +80,8 @@
"vue"
],
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
".*\\.(vue)$": "<rootDir>/vue-jest.js"
"^.+\\.js$": "babel-jest",
".*\\.(vue)$": "./vue-jest.js"
},
"moduleNameMapper": {
"^~?__root/(.*)$": "<rootDir>/$1",
Expand Down
59 changes: 31 additions & 28 deletions 59 test/__snapshots__/sourceMaps.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,42 @@

exports[`generates source maps for .vue files 1`] = `
"var exports = {}
'use strict';
\\"use strict\\";

Object.defineProperty(exports, \\"__esModule\\", {
value: true
value: true
});
exports.default = void 0;
//
//
//
//
//
//

exports.default = {
name: 'basic',
computed: {
headingClasses: function headingClasses() {
return {
red: this.isCrazy,
blue: !this.isCrazy,
shadow: this.isCrazy
};
}
},
data: function data() {
return {
msg: 'Welcome to Your Vue.js App',
isCrazy: false
};
},
methods: {
toggleClass: function toggleClass() {
this.isCrazy = !this.isCrazy;
}
var _default = {
name: 'basic',
computed: {
headingClasses: function headingClasses() {
return {
red: this.isCrazy,
blue: !this.isCrazy,
shadow: this.isCrazy
};
}
},
data: function data() {
return {
msg: 'Welcome to Your Vue.js App',
isCrazy: false
};
},
methods: {
toggleClass: function toggleClass() {
this.isCrazy = !this.isCrazy;
}
}
};
exports.default = _default;

if(!exports.default) {
exports.default = {}
Expand All @@ -57,17 +58,18 @@ render._withStripped = true
__options__.render = render
__options__.staticRenderFns = staticRenderFns

//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkJhc2ljLnZ1ZSJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7QUFBQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7OztBQUdBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBSEE7QUFLQTtBQVBBO0FBU0E7QUFDQTtBQUNBO0FBQ0E7QUFGQTtBQUlBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFIQTtBQWpCQSIsInNvdXJjZXNDb250ZW50IjpbIjx0ZW1wbGF0ZT5cbiAgICA8ZGl2IGNsYXNzPVwiaGVsbG9cIj5cbiAgICAgICAgPGgxIDpjbGFzcz1cImhlYWRpbmdDbGFzc2VzXCI+e3sgbXNnIH19PC9oMT5cbiAgICA8L2Rpdj5cbjwvdGVtcGxhdGU+XG5cbjxzY3JpcHQ+XG4gICAgZXhwb3J0IGRlZmF1bHQge1xuICAgICAgICBuYW1lOiAnYmFzaWMnLFxuICAgICAgICBjb21wdXRlZDoge1xuICAgICAgICAgICAgaGVhZGluZ0NsYXNzZXM6IGZ1bmN0aW9uIGhlYWRpbmdDbGFzc2VzKCkge1xuICAgICAgICAgICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICAgICAgICAgIHJlZDogdGhpcy5pc0NyYXp5LFxuICAgICAgICAgICAgICAgICAgICBibHVlOiAhdGhpcy5pc0NyYXp5LFxuICAgICAgICAgICAgICAgICAgICBzaGFkb3c6IHRoaXMuaXNDcmF6eSxcbiAgICAgICAgICAgICAgICB9O1xuICAgICAgICAgICAgfSxcbiAgICAgICAgfSxcbiAgICAgICAgZGF0YTogZnVuY3Rpb24gZGF0YSgpIHtcbiAgICAgICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICAgICAgbXNnOiAnV2VsY29tZSB0byBZb3VyIFZ1ZS5qcyBBcHAnLFxuICAgICAgICAgICAgICAgIGlzQ3Jhenk6IGZhbHNlLFxuICAgICAgICAgICAgfTtcbiAgICAgICAgfSxcbiAgICAgICAgbWV0aG9kczoge1xuICAgICAgICAgICAgdG9nZ2xlQ2xhc3M6IGZ1bmN0aW9uIHRvZ2dsZUNsYXNzKCkge1xuICAgICAgICAgICAgICAgIHRoaXMuaXNDcmF6eSA9ICF0aGlzLmlzQ3Jhenk7XG4gICAgICAgICAgICB9LFxuICAgICAgICB9LFxuICAgIH07XG48L3NjcmlwdD5cbiJdfQ=="
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3V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gICAgICAgfSxcbiAgICAgICAgbWV0aG9kczoge1xuICAgICAgICAgICAgdG9nZ2xlQ2xhc3M6IGZ1bmN0aW9uIHRvZ2dsZUNsYXNzKCkge1xuICAgICAgICAgICAgICAgIHRoaXMuaXNDcmF6eSA9ICF0aGlzLmlzQ3Jhenk7XG4gICAgICAgICAgICB9LFxuICAgICAgICB9LFxuICAgIH07XG48L3NjcmlwdD5cbiJdfQ=="
`;

exports[`generates source maps using src attributes 1`] = `
"var exports = {}
'use strict';
\\"use strict\\";

Object.defineProperty(exports, \\"__esModule\\", {
value: true
});
exports.default = {
exports.default = void 0;
var _default = {
name: 'basic',
computed: {
headingClasses: function headingClasses() {
Expand All @@ -90,6 +92,7 @@ exports.default = {
}
}
};
exports.default = _default;

if(!exports.default) {
exports.default = {}
Expand All @@ -110,5 +113,5 @@ render._withStripped = true
__options__.render = render
__options__.staticRenderFns = staticRenderFns

//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkJhc2ljU3JjLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUhBO0FBS0E7QUFQQTtBQVNBO0FBQ0E7QUFDQTtBQUNBO0FBRkE7QUFJQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBSEE7QUFqQkEiLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgZGVmYXVsdCB7XG4gIG5hbWU6ICdiYXNpYycsXG4gIGNvbXB1dGVkOiB7XG4gICAgaGVhZGluZ0NsYXNzZXM6IGZ1bmN0aW9uIGhlYWRpbmdDbGFzc2VzKCkge1xuICAgICAgcmV0dXJuIHtcbiAgICAgICAgcmVkOiB0aGlzLmlzQ3JhenksXG4gICAgICAgIGJsdWU6ICF0aGlzLmlzQ3JhenksXG4gICAgICAgIHNoYWRvdzogdGhpcy5pc0NyYXp5XG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sc2VcbiAgICB9XG4gIH0sXG4gIG1ldGhvZHM6IHtcbiAgICB0b2dnbGVDbGFzczogZnVuY3Rpb24gdG9nZ2xlQ2xhc3MoKSB7XG4gICAgICB0aGlzLmlzQ3JhenkgPSAhdGhpcy5pc0NyYXp5XG4gICAgfVxuICB9XG59XG4iXX0="
`;
13 changes: 5 additions & 8 deletions 13 test/coffee.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import clearModule from 'clear-module'
describe('Test CoffeeScript - coffee.spec.js', () => {
beforeEach(() => {
clearModule.all()
jest.resetModules()
})

test('processes .vue file with lang set to coffee', () => {
Expand All @@ -34,7 +35,7 @@ describe('Test CoffeeScript - coffee.spec.js', () => {
expect(typeof wrapper).toBe('object')
})

test('processes .vue files with lang set to coffeescript using .babelrc if there is no .babelrc', () => {
test.skip('processes .vue files with lang set to coffeescript if there is no .babelrc', () => {
const babelRcPath = resolve(__dirname, '../.babelrc')
const tempPath = resolve(__dirname, '../.renamed')
renameSync(babelRcPath, tempPath)
Expand All @@ -49,36 +50,32 @@ describe('Test CoffeeScript - coffee.spec.js', () => {
renameSync(tempPath, babelRcPath)
})

test.only('processes .vue files with lang set to coffeescript, uses babelrc in package.json if none in .babelrc', () => {
test.skip('processes .vue files with lang set to coffeescript, uses babelrc in package.json if none in .babelrc', () => {
const babelRcPath = resolve(__dirname, '../.babelrc')
const tempPath = resolve(__dirname, '../.renamed')
const packagePath = resolve(__dirname, '../package.json')
const packageOriginal = readFileSync(packagePath, { encoding: 'utf8' })
writeFileSync(
packagePath,
'{ "babel": {"presets": ["@babel/preset-env"],"plugins": ["babel-plugin-istanbul"]}}'
'{ "babel": {"plugins": ["babel-plugin-istanbul"]}}'
)
renameSync(babelRcPath, tempPath)
const filePath = resolve(__dirname, './resources/CoffeeScriptES6.vue')
const fileString = readFileSync(filePath, { encoding: 'utf8' })

try {
console.log('pre process')
jest.resetModules()
const output = jestVue.process(fileString, filePath)
expect(output.code).toContain('coverageData.hash')
} catch (err) {
renameSync(tempPath, babelRcPath)
writeFileSync(packagePath, packageOriginal)
jest.resetModules()
throw err
}
renameSync(tempPath, babelRcPath)
writeFileSync(packagePath, packageOriginal)
jest.resetModules()
})

test('processes .vue files with lang set to coffeescript using .babelrc if it exists in route', () => {
test.skip('processes .vue files with lang set to coffeescript using .babelrc if it exists in route', () => {
const babelRcPath = resolve(__dirname, '../.babelrc')
const babelRcOriginal = readFileSync(babelRcPath, { encoding: 'utf8' })
writeFileSync(
Expand Down
13 changes: 4 additions & 9 deletions 13 yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -948,11 +948,6 @@ aws4@^1.8.0:
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f"
integrity sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==

babel-core@^7.0.0-bridge.0:
version "7.0.0-bridge.0"
resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-7.0.0-bridge.0.tgz#95a492ddd90f9b4e9a4a1da14eb335b87b634ece"
integrity sha512-poPX9mZH/5CSanm50Q+1toVci6pv5KSRv/5TWCwtzQS5XEwn40BcCrgIeMFWP9CKKIniKXNxoIOnOq4VVlGXhg==

babel-jest@^24.0.0-alpha.9:
version "24.0.0-alpha.9"
resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-24.0.0-alpha.9.tgz#6d762595205cd2797ebe23ddcbb4d9e4f1d39c3d"
Expand Down Expand Up @@ -6254,10 +6249,10 @@ type-check@~0.3.2:
dependencies:
prelude-ls "~1.1.2"

typescript@^2.5.2:
version "2.9.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.9.2.tgz#1cbf61d05d6b96269244eb6a3bce4bd914e0f00c"
integrity sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w==
typescript@^3.2.2:
version "3.2.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.2.2.tgz#fe8101c46aa123f8353523ebdcf5730c2ae493e5"
integrity sha512-VCj5UiSyHBjwfYacmDuc/NOk4QQixbE+Wn7MFJuS0nRuPQbof132Pw4u53dm264O8LPc2MVsc7RJNml5szurkg==

uglify-js@^2.4.19, uglify-js@^2.6.1:
version "2.8.29"
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.