|
| 1 | +/* global describe, it, expect */ |
| 2 | + |
| 3 | +import {join} from 'path' |
| 4 | +import getConfig, {loadConfig} from '../../dist/server/config' |
| 5 | +import {PHASE_DEVELOPMENT_SERVER} from '../../dist/lib/constants' |
| 6 | + |
| 7 | +const pathToConfig = join(__dirname, '_resolvedata', 'without-function') |
| 8 | +const pathToConfigFn = join(__dirname, '_resolvedata', 'with-function') |
| 9 | + |
| 10 | +describe('config', () => { |
| 11 | + it('Should get the configuration', () => { |
| 12 | + const config = loadConfig(PHASE_DEVELOPMENT_SERVER, pathToConfig) |
| 13 | + expect(config.customConfig).toBe(true) |
| 14 | + }) |
| 15 | + |
| 16 | + it('Should pass the phase correctly', () => { |
| 17 | + const config = loadConfig(PHASE_DEVELOPMENT_SERVER, pathToConfigFn) |
| 18 | + expect(config.phase).toBe(PHASE_DEVELOPMENT_SERVER) |
| 19 | + }) |
| 20 | + |
| 21 | + it('Should pass the defaultConfig correctly', () => { |
| 22 | + const config = loadConfig(PHASE_DEVELOPMENT_SERVER, pathToConfigFn) |
| 23 | + expect(config.defaultConfig).toBeDefined() |
| 24 | + }) |
| 25 | + |
| 26 | + it('Should pass the customConfig correctly', () => { |
| 27 | + const config = loadConfig(PHASE_DEVELOPMENT_SERVER, null, {customConfig: true}) |
| 28 | + expect(config.customConfig).toBe(true) |
| 29 | + }) |
| 30 | + |
| 31 | + it('Should not pass the customConfig when it is null', () => { |
| 32 | + const config = loadConfig(PHASE_DEVELOPMENT_SERVER, null, null) |
| 33 | + expect(config.webpack).toBe(null) |
| 34 | + }) |
| 35 | + |
| 36 | + it('Should cache on getConfig', () => { |
| 37 | + const config = getConfig(PHASE_DEVELOPMENT_SERVER, pathToConfig) |
| 38 | + const config2 = getConfig(PHASE_DEVELOPMENT_SERVER, pathToConfig, {extraConfig: true}) // won't add extraConfig because it's cached. |
| 39 | + expect(config === config2).toBe(true) |
| 40 | + }) |
| 41 | +}) |
0 commit comments