This repository has been archived by the owner on Mar 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: config file support extends (#11)
* feat: config file support extends * test: add cases for config extends * test: correct config case
- Loading branch information
1 parent
e89f575
commit edf71ee
Showing
19 changed files
with
194 additions
and
3 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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,77 @@ | ||
import path from 'path'; | ||
import { mockProcessExit } from 'jest-mock-process'; | ||
import { distToMap } from './utils'; | ||
import * as cli from '../src/cli/cli'; | ||
|
||
jest.mock('@umijs/utils', () => { | ||
const originalModule = jest.requireActual('@umijs/utils'); | ||
|
||
return { | ||
__esModule: true, | ||
...originalModule, | ||
|
||
// workaround for watch config file change in jest | ||
// ref: | ||
// - https://github.com/facebook/jest/issues/6034 | ||
// - https://github.com/umijs/umi-next/blob/e46748deab90807c8504dfe11f3bb554f4f27ac3/packages/core/src/config/config.ts#L172 | ||
// TODO: remove this when umi ready | ||
register: { | ||
...originalModule.register, | ||
getFiles: () => (global.TMP_CASE_CONFIG ? [global.TMP_CASE_CONFIG] : []), | ||
}, | ||
}; | ||
}); | ||
|
||
const mockExit = mockProcessExit(); | ||
const CASES_DIR = path.join(__dirname, 'fixtures/config'); | ||
|
||
afterAll(() => { | ||
delete process.env.APP_ROOT; | ||
mockExit.mockRestore(); | ||
}); | ||
test('config: cyclic extends', async () => { | ||
// execute build | ||
process.env.APP_ROOT = path.join(CASES_DIR, 'config-cyclic-extends'); | ||
|
||
// workaround for get config file path | ||
global.TMP_CASE_CONFIG = path.join(process.env.APP_ROOT, '.fatherrc.ts'); | ||
|
||
await cli.run({ | ||
args: { _: ['build'], $0: 'node' }, | ||
}); | ||
|
||
// expect process.exit(1) called | ||
expect(mockExit).toHaveBeenCalledWith(1); | ||
|
||
// restore mock | ||
jest.unmock('@umijs/utils'); | ||
delete global.TMP_CASE_CONFIG; | ||
}); | ||
|
||
test('config: nonexistent extends', async () => { | ||
// execute build | ||
process.env.APP_ROOT = path.join(CASES_DIR, 'config-nonexistent-extends'); | ||
|
||
await cli.run({ | ||
args: { _: ['build'], $0: 'node' }, | ||
}); | ||
|
||
// expect process.exit(1) called | ||
expect(mockExit).toHaveBeenCalledWith(1); | ||
}); | ||
|
||
test('config: nested extends', async () => { | ||
// execute build | ||
process.env.APP_ROOT = path.join(CASES_DIR, 'config-nested-extends'); | ||
await cli.run({ | ||
args: { _: ['build'], $0: 'node' }, | ||
}); | ||
|
||
// prepare file map | ||
const fileMap = distToMap( | ||
path.join(CASES_DIR, 'config-nested-extends', 'dist'), | ||
); | ||
|
||
// check result | ||
require(`${process.env.APP_ROOT}/expect`).default(fileMap); | ||
}); |
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
4 changes: 4 additions & 0 deletions
4
tests/fixtures/config/config-cyclic-extends/.fatherrc.base.ts
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,4 @@ | ||
export default { | ||
extends: './.fatherrc.ts', | ||
esm: {}, | ||
}; |
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,4 @@ | ||
export default { | ||
extends: './.fatherrc.base.ts', | ||
esm: { transformer: 'babel' }, | ||
}; |
4 changes: 4 additions & 0 deletions
4
tests/fixtures/config/config-nested-extends/.fatherrc.base.ts
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,4 @@ | ||
export default { | ||
extends: './.fatherrc.common.ts', | ||
esm: {}, | ||
}; |
3 changes: 3 additions & 0 deletions
3
tests/fixtures/config/config-nested-extends/.fatherrc.common.ts
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,3 @@ | ||
export default { | ||
platform: 'node', | ||
}; |
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,4 @@ | ||
export default { | ||
extends: './.fatherrc.base.ts', | ||
esm: { transformer: 'babel' }, | ||
}; |
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,7 @@ | ||
export default (files: Record<string, string>) => { | ||
// expect node platform | ||
expect(files['esm/index.js']).toContain("from 'fs';"); | ||
|
||
// expect not esbuild | ||
expect(files['esm/index.js']).not.toContain(' as default'); | ||
}; |
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,3 @@ | ||
import * as fs from 'fs'; | ||
|
||
export default fs; |
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 @@ | ||
{} |
3 changes: 3 additions & 0 deletions
3
tests/fixtures/config/config-nonexistent-extends/.fatherrc.ts
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,3 @@ | ||
export default { | ||
extends: './.fatherrc.nonexistent.ts', | ||
}; |