|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | +import { isMFFormat } from '../../src/cli'; |
| 3 | +import type { Rspack } from '@rsbuild/core'; |
| 4 | + |
| 5 | +describe('isMFFormat', () => { |
| 6 | + it('should return true when library config is not present', () => { |
| 7 | + const config: Partial<Rspack.Configuration> = { |
| 8 | + output: {}, |
| 9 | + }; |
| 10 | + expect(isMFFormat(config as Rspack.Configuration)).toBe(true); |
| 11 | + }); |
| 12 | + |
| 13 | + it('should return true when library is not an object', () => { |
| 14 | + const config: Partial<Rspack.Configuration> = { |
| 15 | + output: { |
| 16 | + library: 'myLib', |
| 17 | + }, |
| 18 | + }; |
| 19 | + expect(isMFFormat(config as Rspack.Configuration)).toBe(true); |
| 20 | + }); |
| 21 | + |
| 22 | + it('should return true when library is an array', () => { |
| 23 | + const config: Partial<Rspack.Configuration> = { |
| 24 | + output: { |
| 25 | + library: ['myLib'], |
| 26 | + }, |
| 27 | + }; |
| 28 | + expect(isMFFormat(config as Rspack.Configuration)).toBe(true); |
| 29 | + }); |
| 30 | + |
| 31 | + it('should return false when library.type is commonjs', () => { |
| 32 | + const config: Partial<Rspack.Configuration> = { |
| 33 | + output: { |
| 34 | + library: { |
| 35 | + type: 'commonjs', |
| 36 | + }, |
| 37 | + }, |
| 38 | + }; |
| 39 | + expect(isMFFormat(config as Rspack.Configuration)).toBe(false); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should return false when library.type is umd', () => { |
| 43 | + const config: Partial<Rspack.Configuration> = { |
| 44 | + output: { |
| 45 | + library: { |
| 46 | + type: 'umd', |
| 47 | + }, |
| 48 | + }, |
| 49 | + }; |
| 50 | + expect(isMFFormat(config as Rspack.Configuration)).toBe(false); |
| 51 | + }); |
| 52 | + |
| 53 | + it('should return false when library.type is modern-module', () => { |
| 54 | + const config: Partial<Rspack.Configuration> = { |
| 55 | + output: { |
| 56 | + library: { |
| 57 | + type: 'modern-module', |
| 58 | + }, |
| 59 | + }, |
| 60 | + }; |
| 61 | + expect(isMFFormat(config as Rspack.Configuration)).toBe(false); |
| 62 | + }); |
| 63 | + |
| 64 | + it('should return false when library.type contains commonjs', () => { |
| 65 | + const config: Partial<Rspack.Configuration> = { |
| 66 | + output: { |
| 67 | + library: { |
| 68 | + type: 'commonjs-static', |
| 69 | + }, |
| 70 | + }, |
| 71 | + }; |
| 72 | + expect(isMFFormat(config as Rspack.Configuration)).toBe(false); |
| 73 | + }); |
| 74 | + |
| 75 | + it('should return true when library.type is other value', () => { |
| 76 | + const config: Partial<Rspack.Configuration> = { |
| 77 | + output: { |
| 78 | + library: { |
| 79 | + type: 'var', |
| 80 | + }, |
| 81 | + }, |
| 82 | + }; |
| 83 | + expect(isMFFormat(config as Rspack.Configuration)).toBe(true); |
| 84 | + }); |
| 85 | +}); |
0 commit comments