File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import { TsJestGlobalOptions } from '../types' ;
1+ import { TsJestGlobalOptions , BabelConfig } from '../types' ;
22import { resolve } from 'path' ;
33
44export function filePath ( relPath : string ) : string {
@@ -29,7 +29,7 @@ describe('hello', function () {
2929export function htmlSource ( ) {
3030 return `
3131<div>
32- <span>some text with \`backtilt \`</span>
32+ <span>some text with \`backtick \`</span>
3333</div>
3434` ;
3535}
@@ -71,3 +71,11 @@ export function jestConfig<T extends jest.ProjectConfig>(
7171 }
7272 return res ;
7373}
74+
75+ export function babelConfig < T extends BabelConfig > ( options ?: BabelConfig ) : T {
76+ return {
77+ ...options ,
78+ presets : [ ...( options && options . presets ) ] ,
79+ plugins : [ ...( options && options . plugins ) ] ,
80+ } as any ;
81+ }
Original file line number Diff line number Diff line change 1+ import * as fakers from '../__helpers__/fakers' ;
2+ import * as babelCfg from './babel-config' ;
3+ import { BabelConfig } from '../types' ;
4+
5+ describe ( 'extend' , ( ) => {
6+ let base ! : BabelConfig ;
7+
8+ beforeEach ( ( ) => {
9+ base = fakers . babelConfig ( {
10+ presets : [ 'preset-1' ] ,
11+ plugins : [ 'plugin-1' ] ,
12+ minified : true ,
13+ } ) ;
14+ } ) ;
15+
16+ it ( 'should be a copy' , ( ) => {
17+ const extended = babelCfg . extend ( base ) ;
18+ expect ( extended ) . toEqual ( base ) ;
19+ expect ( extended ) . not . toBe ( base ) ;
20+ expect ( extended . presets ) . not . toBe ( base . presets ) ;
21+ expect ( extended . plugins ) . not . toBe ( base . plugins ) ;
22+ } ) ;
23+
24+ it ( 'should extend correctly' , ( ) => {
25+ const extension : BabelConfig = {
26+ minified : false ,
27+ envName : 'test' ,
28+ plugins : [ 'plugin-2' ] ,
29+ presets : [ 'preset-2' ] ,
30+ } ;
31+ const extended = babelCfg . extend ( base , extension ) ;
32+ expect ( extended ) . not . toBe ( base ) ;
33+ expect ( extended ) . not . toBe ( extension ) ;
34+ expect ( extended . presets ) . not . toBe ( base . presets ) ;
35+ expect ( extended . presets ) . not . toBe ( extension . presets ) ;
36+ expect ( extended . plugins ) . not . toBe ( base . plugins ) ;
37+ expect ( extended . plugins ) . not . toBe ( extension . plugins ) ;
38+ expect ( extended ) . toMatchInlineSnapshot ( `
39+ Object {
40+ "envName": "test",
41+ "minified": false,
42+ "plugins": Array [
43+ "plugin-1",
44+ "plugin-2",
45+ ],
46+ "presets": Array [
47+ "preset-1",
48+ "preset-2",
49+ ],
50+ }
51+ ` ) ;
52+ } ) ;
53+ } ) ;
Original file line number Diff line number Diff line change @@ -31,10 +31,13 @@ export function extend(
3131 // tslint:disable-next-line:trailing-comma
3232 ...others : BabelConfig [ ]
3333) : BabelConfig {
34- const res = Object . assign ( base , extend , ...others , {
34+ const res = {
35+ ...base ,
36+ ...extend ,
37+ ...others ,
3538 presets : base . presets ? base . presets . slice ( ) : [ ] ,
36- plugins : extend . plugins ? extend . plugins . slice ( ) : [ ] ,
37- } ) ;
39+ plugins : base . plugins ? base . plugins . slice ( ) : [ ] ,
40+ } ;
3841 others . unshift ( extend ) ;
3942 others . forEach ( other => {
4043 if ( other . presets ) {
You can’t perform that action at this time.
0 commit comments