11import Vue from 'vue'
22import Basic from './resources/Basic.vue'
33import BasicSrc from './resources/BasicSrc.vue'
4- import jestVue from '../vue-jest'
5- import { resolve } from 'path'
6- import {
7- readFileSync ,
8- writeFileSync ,
9- renameSync
10- } from 'fs'
114import clearModule from 'clear-module'
125import cache from '../lib/cache'
136
@@ -25,99 +18,5 @@ test('processes .vue files', () => {
2518test ( 'processes .vue files using src attributes' , ( ) => {
2619 const vm = new Vue ( BasicSrc ) . $mount ( )
2720 expect ( typeof vm . $el ) . toBe ( 'object' )
28- } )
29-
30- test ( 'skip processing if there is no .babelrc' , ( ) => {
31- const babelRcPath = resolve ( __dirname , '../.babelrc' )
32- const babelRcPath2 = resolve ( __dirname , '../../.babelrc' )
33- const tempPath = resolve ( __dirname , '../.renamed' )
34- const tempPath2 = resolve ( __dirname , '../../.renamed' )
35- renameSync ( babelRcPath , tempPath )
36- renameSync ( babelRcPath2 , tempPath2 )
37- const filePath = resolve ( __dirname , './resources/Basic.vue' )
38- const fileString = readFileSync ( filePath , { encoding : 'utf8' } )
39- try {
40- jestVue . process ( fileString , filePath )
41- } catch ( err ) {
42- renameSync ( tempPath , babelRcPath )
43- renameSync ( tempPath2 , babelRcPath2 )
44- throw err
45- }
46- renameSync ( tempPath , babelRcPath )
47- renameSync ( tempPath2 , babelRcPath2 )
48- } )
49-
50- test ( 'logs info when there is no .babelrc' , ( ) => {
51- const babelRcPath = resolve ( __dirname , '../.babelrc' )
52- const babelRcPath2 = resolve ( __dirname , '../../.babelrc' )
53- const tempPath = resolve ( __dirname , '../.renamed' )
54- const tempPath2 = resolve ( __dirname , '../../.renamed' )
55- renameSync ( babelRcPath , tempPath )
56- renameSync ( babelRcPath2 , tempPath2 )
57- const info = jest . spyOn ( global . console , 'info' )
58- const filePath = resolve ( __dirname , './resources/Basic.vue' )
59- const fileString = readFileSync ( filePath , { encoding : 'utf8' } )
60-
61- jestVue . process ( fileString , filePath )
62- try {
63- expect ( info ) . toHaveBeenCalledWith ( '\n[vue-jest]: no .babelrc found, skipping babel compilation\n' )
64- } catch ( err ) {
65- renameSync ( tempPath , babelRcPath )
66- renameSync ( tempPath2 , babelRcPath2 )
67- throw err
68- }
69- renameSync ( tempPath , babelRcPath )
70- renameSync ( tempPath2 , babelRcPath2 )
71- jest . resetModules ( )
72- } )
73-
74- test ( 'uses babelrc in package.json if none in .babelrc' , ( ) => {
75- const babelRcPath = resolve ( __dirname , '../.babelrc' )
76- const tempPath = resolve ( __dirname , '../.renamed' )
77- const packagePath = resolve ( __dirname , '../package.json' )
78- const packageOriginal = readFileSync ( packagePath , { encoding : 'utf8' } )
79- writeFileSync ( packagePath , '{ "babel": {"presets": ["env"],"plugins": ["istanbul"]}}' )
80- renameSync ( babelRcPath , tempPath )
81- const filePath = resolve ( __dirname , './resources/Basic.vue' )
82- const fileString = readFileSync ( filePath , { encoding : 'utf8' } )
83-
84- try {
85- const output = jestVue . process ( fileString , filePath )
86- expect ( output . code ) . toContain ( 'coverageData.hash' )
87- } catch ( err ) {
88- renameSync ( tempPath , babelRcPath )
89- writeFileSync ( packagePath , packageOriginal )
90- jest . resetModules ( )
91- throw err
92- }
93- renameSync ( tempPath , babelRcPath )
94- writeFileSync ( packagePath , packageOriginal )
95- jest . resetModules ( )
96- } )
97-
98- test ( 'processes .vue files using .babelrc if it exists in route' , ( ) => {
99- const babelRcPath = resolve ( __dirname , '../.babelrc' )
100- const babelRcOriginal = readFileSync ( babelRcPath , { encoding : 'utf8' } )
101- writeFileSync ( babelRcPath , '{"presets": ["env"],"plugins": ["istanbul"]}' )
102- const filePath = resolve ( __dirname , './resources/Basic.vue' )
103- const fileString = readFileSync ( filePath , { encoding : 'utf8' } )
104-
105- const output = jestVue . process ( fileString , filePath )
106- writeFileSync ( babelRcPath , babelRcOriginal )
107- // coverageData.hash is added by babel-plugin-istanbul, added to root .babelrc for this test only
108- expect ( output . code ) . toContain ( 'coverageData.hash' )
109- } )
110-
111- test ( 'generates inline sourcemap' , ( ) => {
112- const filePath = resolve ( __dirname , './resources/Basic.vue' )
113- const fileString = readFileSync ( filePath , { encoding : 'utf8' } )
114- const output = jestVue . process ( fileString , filePath )
115- expect ( output . code ) . toMatchSnapshot ( )
116- } )
117-
118- test ( 'generates inline sourcemap for .vue files using src attributes' , ( ) => {
119- const filePath = resolve ( __dirname , './resources/BasicSrc.vue' )
120- const fileString = readFileSync ( filePath , { encoding : 'utf8' } )
121- const output = jestVue . process ( fileString , filePath )
122- expect ( output . code ) . toMatchSnapshot ( )
21+ vm . toggleClass ( )
12322} )
0 commit comments