|
1 |
| -import { shallow } from 'vue-test-utils' |
| 1 | +import { shallow, mount } from 'vue-test-utils' |
2 | 2 | import Coffee from './resources/Coffee.vue'
|
3 | 3 | import CoffeeScript from './resources/CoffeeScript.vue'
|
| 4 | +import CoffeeES6 from './resources/CoffeeES6.vue' |
| 5 | +import CoffeeScriptES6 from './resources/CoffeeScriptES6.vue' |
| 6 | +import jestVue from '../vue-jest' |
| 7 | +import { resolve } from 'path' |
| 8 | +import { |
| 9 | + readFileSync, |
| 10 | + writeFileSync, |
| 11 | + renameSync |
| 12 | +} from 'fs' |
| 13 | +import clearModule from 'clear-module' |
| 14 | +import cache from '../lib/cache' |
4 | 15 |
|
5 |
| -test('processes .vue file with lang set to coffeescript', () => { |
6 |
| - shallow(Coffee) |
7 |
| -}) |
| 16 | +describe('Test CoffeeScript - coffee.spec.js', () => { |
| 17 | + beforeEach(() => { |
| 18 | + cache.flushAll() |
| 19 | + clearModule.all() |
| 20 | + }) |
| 21 | + |
| 22 | + test('processes .vue file with lang set to coffee', () => { |
| 23 | + shallow(Coffee) |
| 24 | + }) |
| 25 | + |
| 26 | + test('processes .vue file with lang set to coffeescript', () => { |
| 27 | + shallow(CoffeeScript) |
| 28 | + }) |
| 29 | + |
| 30 | + test('processes .vue file with lang set to coffee (ES6)', () => { |
| 31 | + shallow(CoffeeES6) |
| 32 | + }) |
| 33 | + |
| 34 | + test('processes .vue file with lang set to coffeescript (ES6)', () => { |
| 35 | + shallow(CoffeeScriptES6) |
| 36 | + }) |
| 37 | + |
| 38 | + test('processes .vue file with lang set to coffeescript (ES6)', () => { |
| 39 | + const wrapper = mount(CoffeeScriptES6) |
| 40 | + expect(typeof wrapper).toBe('object') |
| 41 | + }) |
| 42 | + |
| 43 | + test('processes .vue files with lang set to coffeescript using .babelrc if there is no .babelrc', () => { |
| 44 | + const babelRcPath = resolve(__dirname, '../.babelrc') |
| 45 | + const tempPath = resolve(__dirname, '../.renamed') |
| 46 | + renameSync(babelRcPath, tempPath) |
| 47 | + const filePath = resolve(__dirname, './resources/CoffeeScriptES6.vue') |
| 48 | + const fileString = readFileSync(filePath, { encoding: 'utf8' }) |
| 49 | + try { |
| 50 | + jestVue.process(fileString, filePath) |
| 51 | + } catch (err) { |
| 52 | + renameSync(tempPath, babelRcPath) |
| 53 | + throw err |
| 54 | + } |
| 55 | + renameSync(tempPath, babelRcPath) |
| 56 | + }) |
| 57 | + |
| 58 | + test('processes .vue files with lang set to coffeescript, uses babelrc in package.json if none in .babelrc', () => { |
| 59 | + const babelRcPath = resolve(__dirname, '../.babelrc') |
| 60 | + const tempPath = resolve(__dirname, '../.renamed') |
| 61 | + const packagePath = resolve(__dirname, '../package.json') |
| 62 | + const packageOriginal = readFileSync(packagePath, { encoding: 'utf8' }) |
| 63 | + writeFileSync(packagePath, '{ "babel": {"presets": ["env"],"plugins": ["istanbul"]}}') |
| 64 | + renameSync(babelRcPath, tempPath) |
| 65 | + const filePath = resolve(__dirname, './resources/CoffeeScriptES6.vue') |
| 66 | + const fileString = readFileSync(filePath, { encoding: 'utf8' }) |
| 67 | + |
| 68 | + try { |
| 69 | + const output = jestVue.process(fileString, filePath) |
| 70 | + expect(output.code).toContain('coverageData.hash') |
| 71 | + } catch (err) { |
| 72 | + renameSync(tempPath, babelRcPath) |
| 73 | + writeFileSync(packagePath, packageOriginal) |
| 74 | + jest.resetModules() |
| 75 | + throw err |
| 76 | + } |
| 77 | + renameSync(tempPath, babelRcPath) |
| 78 | + writeFileSync(packagePath, packageOriginal) |
| 79 | + jest.resetModules() |
| 80 | + }) |
| 81 | + |
| 82 | + test('processes .vue files with lang set to coffeescript using .babelrc if it exists in route', () => { |
| 83 | + const babelRcPath = resolve(__dirname, '../.babelrc') |
| 84 | + const babelRcOriginal = readFileSync(babelRcPath, { encoding: 'utf8' }) |
| 85 | + writeFileSync(babelRcPath, '{"presets": ["env"],"plugins": ["istanbul"]}') |
| 86 | + const filePath = resolve(__dirname, './resources/CoffeeScriptES6.vue') |
| 87 | + const fileString = readFileSync(filePath, { encoding: 'utf8' }) |
8 | 88 |
|
9 |
| -test('processes .vue file with lang set to coffeescript', () => { |
10 |
| - shallow(CoffeeScript) |
| 89 | + const output = jestVue.process(fileString, filePath) |
| 90 | + writeFileSync(babelRcPath, babelRcOriginal) |
| 91 | + // coverageData.hash is added by babel-plugin-istanbul, added to root .babelrc for this test only |
| 92 | + expect(output.code).toContain('coverageData.hash') |
| 93 | + }) |
11 | 94 | })
|
0 commit comments