-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(app-tools): init config can't handle moduleScopes as function (#4897
- Loading branch information
1 parent
83859a2
commit 957de56
Showing
3 changed files
with
101 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@modern-js/app-tools': patch | ||
--- | ||
|
||
fix(app-tools): init config can't handle moduleScopes as function | ||
fix(app-tools): 初始化 config 不能处理 moduleScopes 是 function 的情况 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { createBuilderModuleScope } from '../../src/config/initialize/inits'; | ||
import { AppNormalizedConfig } from '../../src/types'; | ||
|
||
describe('test createBuilderModuleScope', () => { | ||
it('should return undefined when moduleScope = undefined', () => { | ||
const config: AppNormalizedConfig = { | ||
source: {}, | ||
} as any; | ||
const moduleScopes = createBuilderModuleScope(config); | ||
|
||
expect(moduleScopes).toBeUndefined(); | ||
}); | ||
|
||
it('should merge config when moduleScope as a Array', () => { | ||
const config: AppNormalizedConfig = { | ||
source: { | ||
moduleScopes: ['hello', /abc/], | ||
}, | ||
} as any; | ||
|
||
const moduleScopes = createBuilderModuleScope(config); | ||
|
||
expect(moduleScopes).toEqual([ | ||
'./src', | ||
'./shared', | ||
/node_modules/, | ||
'hello', | ||
/abc/, | ||
]); | ||
}); | ||
|
||
it('should though function handle when moduleScopes as a function', () => { | ||
const config: AppNormalizedConfig = { | ||
source: { | ||
moduleScopes(module: Array<string>) { | ||
module.pop(); | ||
module.push('abc'); | ||
}, | ||
}, | ||
} as any; | ||
const moduleScopes = createBuilderModuleScope(config); | ||
expect(moduleScopes).toEqual(['./src', './shared', 'abc']); | ||
}); | ||
}); |