|
1 | 1 | import { mockBundleAndRun, normalizeNewline } from './utils'
|
2 | 2 |
|
3 | 3 | test('basic', async () => {
|
4 |
| - const { window, instance } = await mockBundleAndRun({ entry: 'basic.vue' }) |
| 4 | + const { window, instance, componentModule } = await mockBundleAndRun({ |
| 5 | + entry: 'basic.vue', |
| 6 | + }) |
5 | 7 |
|
6 | 8 | // <h2 class="red">{{msg}}</h2>
|
7 | 9 | expect(instance.$el.tagName).toBe('H2')
|
8 | 10 | expect(instance.$el.className).toBe('red')
|
9 | 11 | expect(instance.$el.textContent).toBe('Hello from Component A!')
|
10 | 12 |
|
| 13 | + // @ts-ignore |
| 14 | + expect(componentModule.data().msg).toContain('Hello from Component A!') |
| 15 | + |
11 | 16 | const style = normalizeNewline(
|
12 | 17 | window.document.querySelector('style')!.textContent!
|
13 | 18 | )
|
14 | 19 | expect(style).toContain('comp-a h2 {\n color: #f00;\n}')
|
15 | 20 | })
|
16 | 21 |
|
| 22 | +test('pre-processors', async () => { |
| 23 | + // @ts-ignore |
| 24 | + const { window, instance, code, componentModule } = await mockBundleAndRun({ |
| 25 | + entry: 'pre.vue', |
| 26 | + module: { |
| 27 | + rules: [ |
| 28 | + { |
| 29 | + test: /\.js$/, |
| 30 | + exclude: /node_modules/, |
| 31 | + loader: 'babel-loader', |
| 32 | + options: { |
| 33 | + presets: ['@babel/preset-env'], |
| 34 | + }, |
| 35 | + }, |
| 36 | + { |
| 37 | + test: /\.pug$/, |
| 38 | + loader: 'pug-plain-loader', |
| 39 | + }, |
| 40 | + { |
| 41 | + test: /\.stylus$/, |
| 42 | + use: ['style-loader', 'css-loader', 'stylus-loader'], |
| 43 | + }, |
| 44 | + ], |
| 45 | + }, |
| 46 | + }) |
| 47 | + |
| 48 | + // make sure babel is actually applied |
| 49 | + expect(code).toMatch('data: function data()') |
| 50 | + |
| 51 | + // div |
| 52 | + // h1 This is the app |
| 53 | + // comp-a |
| 54 | + // comp-b |
| 55 | + expect(instance.$el.children[0].tagName).toBe('H1') |
| 56 | + expect(instance.$el.children[1].tagName).toBe('COMP-A') |
| 57 | + expect(instance.$el.children[2].tagName).toBe('COMP-B') |
| 58 | + |
| 59 | + // script |
| 60 | + // @ts-ignore |
| 61 | + expect(componentModule.data().msg).toContain('Hello from Babel') |
| 62 | + |
| 63 | + // style |
| 64 | + const style = window.document.querySelector('style')!.textContent! |
| 65 | + expect(style).toContain( |
| 66 | + 'body {\n font: 100% Helvetica, sans-serif;\n color: #999;\n}' |
| 67 | + ) |
| 68 | +}) |
| 69 | + |
17 | 70 | test('script setup', async () => {
|
18 | 71 | await mockBundleAndRun({ entry: 'ScriptSetup.vue' })
|
19 | 72 | })
|
|
0 commit comments