|
1 | | -import { mockBundleAndRun, normalizeNewline } from './utils' |
| 1 | +import { mockBundleAndRun, normalizeNewline, genId } from './utils' |
2 | 2 |
|
3 | 3 | test('basic', async () => { |
4 | 4 | const { window, instance, componentModule } = await mockBundleAndRun({ |
@@ -61,12 +61,111 @@ test('pre-processors', async () => { |
61 | 61 | expect(componentModule.data().msg).toContain('Hello from Babel') |
62 | 62 |
|
63 | 63 | // style |
64 | | - const style = window.document.querySelector('style')!.textContent! |
| 64 | + const style = normalizeNewline( |
| 65 | + window.document.querySelector('style')!.textContent! |
| 66 | + ) |
65 | 67 | expect(style).toContain( |
66 | 68 | 'body {\n font: 100% Helvetica, sans-serif;\n color: #999;\n}' |
67 | 69 | ) |
68 | 70 | }) |
69 | 71 |
|
| 72 | +test('style import', async () => { |
| 73 | + const { window } = await mockBundleAndRun({ |
| 74 | + entry: 'style-import.vue', |
| 75 | + }) |
| 76 | + |
| 77 | + const styles = window.document.querySelectorAll('style') |
| 78 | + expect(styles[0].textContent).toContain('h1 { color: red;\n}') |
| 79 | + |
| 80 | + // import with scoped |
| 81 | + const id = 'data-v-' + genId('style-import.vue') |
| 82 | + expect(styles[1].textContent).toContain('h1[' + id + '] { color: green;\n}') |
| 83 | +}) |
| 84 | + |
| 85 | +test('style import for a same file twice', async () => { |
| 86 | + const { window } = await mockBundleAndRun({ |
| 87 | + entry: 'style-import-twice.vue', |
| 88 | + }) |
| 89 | + |
| 90 | + const styles = window.document.querySelectorAll('style') |
| 91 | + expect(styles.length).toBe(3) |
| 92 | + expect(styles[0].textContent).toContain('h1 { color: red;\n}') |
| 93 | + |
| 94 | + // import with scoped |
| 95 | + const id = 'data-v-' + genId('style-import-twice-sub.vue') |
| 96 | + expect(styles[1].textContent).toContain('h1[' + id + '] { color: green;\n}') |
| 97 | + const id2 = 'data-v-' + genId('style-import-twice.vue') |
| 98 | + expect(styles[2].textContent).toContain('h1[' + id2 + '] { color: green;\n}') |
| 99 | +}) |
| 100 | + |
| 101 | +test('template import', async () => { |
| 102 | + const { instance } = await mockBundleAndRun({ |
| 103 | + entry: 'template-import.vue', |
| 104 | + }) |
| 105 | + |
| 106 | + const el: Element = instance.$el |
| 107 | + // '<div><h1>hello</h1></div>' |
| 108 | + expect(el.children[0].tagName).toBe('H1') |
| 109 | + expect(el.children[0].textContent).toBe('hello') |
| 110 | +}) |
| 111 | + |
| 112 | +test('template import with pre-processors', async () => { |
| 113 | + const { instance } = await mockBundleAndRun({ |
| 114 | + entry: 'template-import-pre.vue', |
| 115 | + module: { |
| 116 | + rules: [ |
| 117 | + { |
| 118 | + test: /\.pug$/, |
| 119 | + loader: 'pug-plain-loader', |
| 120 | + }, |
| 121 | + ], |
| 122 | + }, |
| 123 | + }) |
| 124 | + |
| 125 | + const el: Element = instance.$el |
| 126 | + // '<div><h1>hello</h1></div>' |
| 127 | + expect(el.children[0].tagName).toBe('H1') |
| 128 | + expect(el.children[0].textContent).toBe('hello') |
| 129 | +}) |
| 130 | + |
| 131 | +test('script import', async () => { |
| 132 | + const { componentModule } = await mockBundleAndRun({ |
| 133 | + entry: 'script-import.vue', |
| 134 | + }) |
| 135 | + expect(componentModule.data().msg).toContain('Hello from Component A!') |
| 136 | +}) |
| 137 | + |
| 138 | +// #1620 |
| 139 | +test('cloned rules should not intefere with each other', async () => { |
| 140 | + await mockBundleAndRun({ |
| 141 | + entry: 'basic.vue', |
| 142 | + module: { |
| 143 | + rules: [ |
| 144 | + { |
| 145 | + test: /\.js$/, |
| 146 | + use: [ |
| 147 | + { |
| 148 | + loader: 'babel-loader', |
| 149 | + options: {}, |
| 150 | + }, |
| 151 | + ], |
| 152 | + }, |
| 153 | + { |
| 154 | + test: /\.some-random-extension$/, |
| 155 | + use: [ |
| 156 | + { |
| 157 | + loader: 'css-loader', |
| 158 | + options: { |
| 159 | + url: true, |
| 160 | + }, |
| 161 | + }, |
| 162 | + ], |
| 163 | + }, |
| 164 | + ], |
| 165 | + }, |
| 166 | + }) |
| 167 | +}) |
| 168 | + |
70 | 169 | test('script setup', async () => { |
71 | 170 | await mockBundleAndRun({ entry: 'ScriptSetup.vue' }) |
72 | 171 | }) |
|
0 commit comments