|
1 | 1 | import type { UserConfig } from 'vitest'
|
| 2 | +import type { UserConfig as ViteUserConfig } from 'vite' |
2 | 3 | import { describe, expect, it } from 'vitest'
|
3 | 4 | import { createVitest } from 'vitest/node'
|
| 5 | +import { extraInlineDeps } from 'vitest/config' |
4 | 6 |
|
5 |
| -async function config(cliOptions: UserConfig, configValue: UserConfig = {}) { |
6 |
| - const vitest = await createVitest('test', { ...cliOptions, watch: false }, { test: configValue }) |
7 |
| - return vitest.config |
| 7 | +async function vitest(cliOptions: UserConfig, configValue: UserConfig = {}, viteConfig: ViteUserConfig = {}) { |
| 8 | + const vitest = await createVitest('test', { ...cliOptions, watch: false }, { ...viteConfig, test: configValue as any }) |
| 9 | + return vitest |
| 10 | +} |
| 11 | + |
| 12 | +async function config(cliOptions: UserConfig, configValue: UserConfig = {}, viteConfig: ViteUserConfig = {}) { |
| 13 | + const v = await vitest(cliOptions, configValue, viteConfig) |
| 14 | + return v.config |
8 | 15 | }
|
9 | 16 |
|
10 | 17 | describe('correctly defines isolated flags', async () => {
|
@@ -102,3 +109,113 @@ describe('correctly defines isolated flags', async () => {
|
102 | 109 | expect(c.isolate).toBe(true)
|
103 | 110 | })
|
104 | 111 | })
|
| 112 | + |
| 113 | +describe('correctly defines inline and noExternal flags', async () => { |
| 114 | + it('both are true if inline is true', async () => { |
| 115 | + const v = await vitest({}, { |
| 116 | + server: { |
| 117 | + deps: { |
| 118 | + inline: true, |
| 119 | + }, |
| 120 | + }, |
| 121 | + }) |
| 122 | + expect(v.vitenode.options.deps?.inline).toBe(true) |
| 123 | + expect(v.vitenode.server.config.ssr.noExternal).toBe(true) |
| 124 | + }) |
| 125 | + |
| 126 | + it('both are true if noExternal is true', async () => { |
| 127 | + const v = await vitest({}, {}, { |
| 128 | + ssr: { |
| 129 | + noExternal: true, |
| 130 | + }, |
| 131 | + }) |
| 132 | + expect(v.vitenode.options.deps?.inline).toBe(true) |
| 133 | + expect(v.vitenode.server.config.ssr.noExternal).toBe(true) |
| 134 | + }) |
| 135 | + |
| 136 | + it('inline are added to noExternal', async () => { |
| 137 | + const regexp1 = /dep1/ |
| 138 | + const regexp2 = /dep2/ |
| 139 | + |
| 140 | + const v = await vitest({}, { |
| 141 | + server: { |
| 142 | + deps: { |
| 143 | + inline: ['dep1', 'dep2', regexp1, regexp2], |
| 144 | + }, |
| 145 | + }, |
| 146 | + }) |
| 147 | + |
| 148 | + expect(v.vitenode.options.deps?.inline).toEqual([ |
| 149 | + 'dep1', |
| 150 | + 'dep2', |
| 151 | + regexp1, |
| 152 | + regexp2, |
| 153 | + ...extraInlineDeps, |
| 154 | + ]) |
| 155 | + expect(v.server.config.ssr.noExternal).toEqual([ |
| 156 | + 'dep1', |
| 157 | + 'dep2', |
| 158 | + regexp1, |
| 159 | + regexp2, |
| 160 | + ...extraInlineDeps, |
| 161 | + ]) |
| 162 | + }) |
| 163 | + |
| 164 | + it('noExternal are added to inline', async () => { |
| 165 | + const regexp1 = /dep1/ |
| 166 | + const regexp2 = /dep2/ |
| 167 | + |
| 168 | + const v = await vitest({}, {}, { |
| 169 | + ssr: { |
| 170 | + noExternal: ['dep1', 'dep2', regexp1, regexp2], |
| 171 | + }, |
| 172 | + }) |
| 173 | + |
| 174 | + expect(v.vitenode.options.deps?.inline).toEqual([ |
| 175 | + ...extraInlineDeps, |
| 176 | + 'dep1', |
| 177 | + 'dep2', |
| 178 | + regexp1, |
| 179 | + regexp2, |
| 180 | + ]) |
| 181 | + expect(v.server.config.ssr.noExternal).toEqual([ |
| 182 | + 'dep1', |
| 183 | + 'dep2', |
| 184 | + regexp1, |
| 185 | + regexp2, |
| 186 | + ]) |
| 187 | + }) |
| 188 | + |
| 189 | + it('noExternal and inline don\'t have duplicates', async () => { |
| 190 | + const regexp1 = /dep1/ |
| 191 | + const regexp2 = /dep2/ |
| 192 | + |
| 193 | + const v = await vitest({}, { |
| 194 | + server: { |
| 195 | + deps: { |
| 196 | + inline: ['dep2', regexp1, 'dep3'], |
| 197 | + }, |
| 198 | + }, |
| 199 | + }, { |
| 200 | + ssr: { |
| 201 | + noExternal: ['dep1', 'dep2', regexp1, regexp2], |
| 202 | + }, |
| 203 | + }) |
| 204 | + |
| 205 | + expect(v.vitenode.options.deps?.inline).toEqual([ |
| 206 | + 'dep2', |
| 207 | + regexp1, |
| 208 | + 'dep3', |
| 209 | + ...extraInlineDeps, |
| 210 | + 'dep1', |
| 211 | + regexp2, |
| 212 | + ]) |
| 213 | + expect(v.server.config.ssr.noExternal).toEqual([ |
| 214 | + 'dep1', |
| 215 | + 'dep2', |
| 216 | + regexp1, |
| 217 | + regexp2, |
| 218 | + 'dep3', |
| 219 | + ]) |
| 220 | + }) |
| 221 | +}) |
0 commit comments