|
| 1 | +import { expect, test } from 'vitest' |
| 2 | +import { runVitest } from '../../test-utils' |
| 3 | + |
| 4 | +test('correctly imports external dependencies with a development condition', async () => { |
| 5 | + // dev condition is the default |
| 6 | + const { stderr } = await runVitest({ |
| 7 | + root: 'fixtures/conditions-test', |
| 8 | + server: { |
| 9 | + deps: { |
| 10 | + external: [/conditions-pkg/], |
| 11 | + }, |
| 12 | + }, |
| 13 | + }, [], 'test', { |
| 14 | + define: { |
| 15 | + TEST_CONDITION: '"development"', |
| 16 | + }, |
| 17 | + }) |
| 18 | + |
| 19 | + expect(stderr).toBe('') |
| 20 | +}) |
| 21 | + |
| 22 | +test('correctly imports external dependencies with a production condition', async () => { |
| 23 | + // this is the only check in Vite for "isProduction" value |
| 24 | + process.env.NODE_ENV = 'production' |
| 25 | + |
| 26 | + const { stderr } = await runVitest({ |
| 27 | + root: 'fixtures/conditions-test', |
| 28 | + server: { |
| 29 | + deps: { |
| 30 | + external: [/conditions-pkg/], |
| 31 | + }, |
| 32 | + }, |
| 33 | + }, [], 'test', { |
| 34 | + define: { |
| 35 | + TEST_CONDITION: '"production"', |
| 36 | + }, |
| 37 | + }) |
| 38 | + |
| 39 | + expect(stderr).toBe('') |
| 40 | +}) |
| 41 | + |
| 42 | +test('correctly imports external dependencies with a custom condition', async () => { |
| 43 | + delete process.env.NODE_ENV |
| 44 | + |
| 45 | + const { stderr } = await runVitest({ |
| 46 | + root: 'fixtures/conditions-test', |
| 47 | + server: { |
| 48 | + deps: { |
| 49 | + external: [/conditions-pkg/], |
| 50 | + }, |
| 51 | + }, |
| 52 | + }, [], 'test', { |
| 53 | + resolve: { |
| 54 | + conditions: ['custom'], |
| 55 | + }, |
| 56 | + define: { |
| 57 | + TEST_CONDITION: '"custom"', |
| 58 | + }, |
| 59 | + }) |
| 60 | + |
| 61 | + expect(stderr).toBe('') |
| 62 | +}) |
0 commit comments