diff --git a/test/toml/netlify-example-1.toml b/test/toml/netlify-example-1.toml new file mode 100644 index 0000000..7ef467d --- /dev/null +++ b/test/toml/netlify-example-1.toml @@ -0,0 +1,17 @@ +[build] + base = "default-base" + publish = "default-publish" + functions = "default-functions" + command = "default-command" + +[context.master] + base = "master-base" + publish = "master-publish" + functions = "master-functions" + command = "master-command" + +[context.develop] + base = "develop-base" + publish = "develop-publish" + functions = "develop-functions" + command = "develop-command" diff --git a/test/ts/config.ts b/test/ts/config.ts new file mode 100644 index 0000000..1ba02cb --- /dev/null +++ b/test/ts/config.ts @@ -0,0 +1,24 @@ +import { describe, it } from "mocha"; +import * as assert from "assert"; + +import * as gitBranch from "git-branch"; + +import { parseNetlifyConfig, parseWebpackConfig } from "../../src/ts"; + +describe('Config', function() { + describe('parseNetlifyConfig', function() { + it('should throw when not found', function() { + const currentBranch = gitBranch.sync(); + assert.throws(() => parseNetlifyConfig("test/toml/netlify.toml" + Math.random())); + }); + it('should override build with context', function() { + const currentBranch = gitBranch.sync(); + const netlifyConfig = parseNetlifyConfig("test/toml/netlify-example-1.toml"); + + assert.equal(netlifyConfig.build.base, `${currentBranch}-base`); + assert.equal(netlifyConfig.build.publish, `${currentBranch}-publish`); + assert.equal(netlifyConfig.build.functions, `${currentBranch}-functions`); + assert.equal(netlifyConfig.build.command, `${currentBranch}-command`); + }); + }); +});