-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Config extension/resolution mechanism for plugins (#325)
* First iteration of config resolution extensions * Use DeepReadOnly in ConfigExtender * Add tests and improve freezing mechanisim * Update resetBuidlerContext
- Loading branch information
1 parent
719f110
commit 3d920db
Showing
10 changed files
with
153 additions
and
6 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
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
9 changes: 9 additions & 0 deletions
9
packages/buidler-core/test/fixture-projects/config-extensions/buidler.config.js
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,9 @@ | ||
extendConfig((config, userConfig) => { | ||
config.values = [1]; | ||
}); | ||
|
||
extendConfig((config, userConfig) => { | ||
config.values.push(2); | ||
}); | ||
|
||
module.exports = {}; |
5 changes: 5 additions & 0 deletions
5
packages/buidler-core/test/fixture-projects/invalid-config-extension/buidler.config.js
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,5 @@ | ||
extendConfig((config, userConfig) => { | ||
userConfig.networks.asd = 123; | ||
}); | ||
|
||
module.exports = { networks: {} }; |
54 changes: 54 additions & 0 deletions
54
packages/buidler-core/test/internal/core/config/config-extensions.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,54 @@ | ||
// extendConfig must be available | ||
// extendConfig shouldn't let me modify th user config | ||
// config extenders must run in order | ||
// config extensions must be visible | ||
|
||
import { assert } from "chai"; | ||
|
||
import { BuidlerContext } from "../../../../src/internal/context"; | ||
import { loadConfigAndTasks } from "../../../../src/internal/core/config/config-loading"; | ||
import { ERRORS } from "../../../../src/internal/core/errors"; | ||
import { resetBuidlerContext } from "../../../../src/internal/reset"; | ||
import { useEnvironment } from "../../../helpers/environment"; | ||
import { expectBuidlerError } from "../../../helpers/errors"; | ||
import { useFixtureProject } from "../../../helpers/project"; | ||
|
||
describe("Config extensions", function() { | ||
describe("Valid extenders", function() { | ||
useFixtureProject("config-extensions"); | ||
useEnvironment(); | ||
|
||
it("Should expose the new values", function() { | ||
const config: any = this.env.config; | ||
assert.isDefined(config.values); | ||
}); | ||
|
||
it("Should execute extenders in order", function() { | ||
const config: any = this.env.config; | ||
assert.deepEqual(config.values, [1, 2]); | ||
}); | ||
}); | ||
|
||
describe("Invalid extensions", function() { | ||
useFixtureProject("invalid-config-extension"); | ||
|
||
beforeEach(function() { | ||
BuidlerContext.createBuidlerContext(); | ||
}); | ||
|
||
afterEach(function() { | ||
resetBuidlerContext(); | ||
}); | ||
|
||
it("Should throw the right error when trying to modify the user config", function() { | ||
expectBuidlerError( | ||
() => loadConfigAndTasks(), | ||
ERRORS.GENERAL.USER_CONFIG_MODIFIED | ||
); | ||
}); | ||
|
||
it("Should have the right property path", function() { | ||
assert.throws(() => loadConfigAndTasks(), "userConfig.networks.asd"); | ||
}); | ||
}); | ||
}); |