From cdf420d4d89d3289d35700321c5010019fc776b7 Mon Sep 17 00:00:00 2001 From: Logan Smyth Date: Sat, 25 Nov 2017 18:25:20 -0800 Subject: [PATCH] Rewrite config chain tests to use public loadOptions API. (#6909) --- .../babel-core/src/config/option-manager.js | 2 + packages/babel-core/test/config-chain.js | 1236 ++++------------- .../test/fixtures/config/.babelignore | 1 - .../babel-core/test/fixtures/config/.babelrc | 4 - .../config/complex-plugin-config/.babelignore | 3 +- .../config-identity/babelrc-js/.babelrc.js | 4 +- .../config-identity/babelrc-js/plugin.js | 3 + .../config-identity/babelrc/.babelrc | 2 +- .../config-identity/babelrc/plugin.js | 3 + .../config-identity/pkg/package.json | 2 +- .../config-identity/pkg/plugin.js | 3 + .../fixtures/config/config-files/.babelignore | 1 + .../config-files/babelignore/.babelignore | 1 + .../config-files/babelrc-error/.babelrc | 1 + .../config-files/babelrc-js-error/.babelrc.js | 3 + .../config-files/babelrc-js/.babelrc.js | 3 + .../config/config-files/babelrc/.babelrc | 3 + .../both-babelrc/.babelrc} | 0 .../config-files/both-babelrc/.babelrc.js | 1 + .../config-files/pkg-babelrc-js/.babelrc.js | 1 + .../pkg-babelrc-js}/package.json | 0 .../config/config-files/pkg-babelrc/.babelrc | 1 + .../pkg-babelrc}/package.json | 0 .../config-files/pkg-error/package.json | 3 + .../config/config-files/pkg-ignored/.babelrc | 3 + .../config-files/pkg-ignored/package.json | 1 + .../config/config-files/pkg/package.json | 5 + .../test/fixtures/config/dir1/src.js | 1 - .../test/fixtures/config/dir2/.babelrc | 5 - .../test/fixtures/config/dir2/src.js | 1 - .../test/fixtures/config/dir3/package.json | 5 - .../test/fixtures/config/dir3/src.js | 1 - .../test/fixtures/config/env/.babelrc | 11 - .../test/fixtures/config/env/src.js | 1 - .../fixtures/config/extended.babelrc.json | 5 - .../config/ignore-negate-folder/.babelrc | 6 - .../ignore-negate-folder/folder/.gitignore | 2 - .../fixtures/config/ignore-negate/.babelrc | 6 - .../config/js-config-default/.babelrc.js | 10 - .../fixtures/config/js-config-default/src.js | 1 - .../config/js-config-error/.babelrc.js | 2 - .../fixtures/config/js-config-error/src.js | 1 - .../config/js-config-error2/.babelrc.js | 1 - .../fixtures/config/js-config-error2/src.js | 1 - .../config/js-config-error3/.babelrc.js | 1 - .../fixtures/config/js-config-error3/src.js | 1 - .../config/js-config-extended/.babelrc.js | 6 - .../fixtures/config/js-config-extended/src.js | 1 - .../config/js-config-function/.babelrc.js | 7 - .../fixtures/config/js-config/.babelrc.js | 5 - .../test/fixtures/config/js-config/src.js | 1 - .../fixtures/config/js-json-config/.babelrc | 5 - .../config/js-json-config/.babelrc.js | 5 - .../fixtures/config/js-json-config/src.js | 1 - .../fixtures/config/js-pkg-config/.babelrc.js | 5 - .../test/fixtures/config/js-pkg-config/src.js | 1 - .../config/json-config-error/.babelrc | 3 - .../fixtures/config/json-config-error/src.js | 1 - .../config/json-pkg-config-no-babel/.babelrc | 5 - .../config/json-pkg-config-no-babel/src.js | 1 - .../fixtures/config/json-pkg-config/.babelrc | 5 - .../fixtures/config/json-pkg-config/src.js | 1 - .../test/fixtures/config/pkg/.babelignore | 1 - .../test/fixtures/config/pkg/package.json | 7 - .../test/fixtures/config/pkg/src.js | 1 - 65 files changed, 353 insertions(+), 1061 deletions(-) delete mode 100644 packages/babel-core/test/fixtures/config/.babelignore delete mode 100644 packages/babel-core/test/fixtures/config/.babelrc create mode 100644 packages/babel-core/test/fixtures/config/complex-plugin-config/config-identity/babelrc-js/plugin.js create mode 100644 packages/babel-core/test/fixtures/config/complex-plugin-config/config-identity/babelrc/plugin.js create mode 100644 packages/babel-core/test/fixtures/config/complex-plugin-config/config-identity/pkg/plugin.js create mode 100644 packages/babel-core/test/fixtures/config/config-files/.babelignore create mode 100644 packages/babel-core/test/fixtures/config/config-files/babelignore/.babelignore create mode 100644 packages/babel-core/test/fixtures/config/config-files/babelrc-error/.babelrc create mode 100644 packages/babel-core/test/fixtures/config/config-files/babelrc-js-error/.babelrc.js create mode 100644 packages/babel-core/test/fixtures/config/config-files/babelrc-js/.babelrc.js create mode 100644 packages/babel-core/test/fixtures/config/config-files/babelrc/.babelrc rename packages/babel-core/test/fixtures/config/{json-pkg-config-no-babel/package.json => config-files/both-babelrc/.babelrc} (100%) create mode 100644 packages/babel-core/test/fixtures/config/config-files/both-babelrc/.babelrc.js create mode 100644 packages/babel-core/test/fixtures/config/config-files/pkg-babelrc-js/.babelrc.js rename packages/babel-core/test/fixtures/config/{js-pkg-config => config-files/pkg-babelrc-js}/package.json (100%) create mode 100644 packages/babel-core/test/fixtures/config/config-files/pkg-babelrc/.babelrc rename packages/babel-core/test/fixtures/config/{json-pkg-config => config-files/pkg-babelrc}/package.json (100%) create mode 100644 packages/babel-core/test/fixtures/config/config-files/pkg-error/package.json create mode 100644 packages/babel-core/test/fixtures/config/config-files/pkg-ignored/.babelrc create mode 100644 packages/babel-core/test/fixtures/config/config-files/pkg-ignored/package.json create mode 100644 packages/babel-core/test/fixtures/config/config-files/pkg/package.json delete mode 100644 packages/babel-core/test/fixtures/config/dir1/src.js delete mode 100644 packages/babel-core/test/fixtures/config/dir2/.babelrc delete mode 100644 packages/babel-core/test/fixtures/config/dir2/src.js delete mode 100644 packages/babel-core/test/fixtures/config/dir3/package.json delete mode 100644 packages/babel-core/test/fixtures/config/dir3/src.js delete mode 100644 packages/babel-core/test/fixtures/config/env/.babelrc delete mode 100644 packages/babel-core/test/fixtures/config/env/src.js delete mode 100644 packages/babel-core/test/fixtures/config/extended.babelrc.json delete mode 100644 packages/babel-core/test/fixtures/config/ignore-negate-folder/.babelrc delete mode 100644 packages/babel-core/test/fixtures/config/ignore-negate-folder/folder/.gitignore delete mode 100644 packages/babel-core/test/fixtures/config/ignore-negate/.babelrc delete mode 100644 packages/babel-core/test/fixtures/config/js-config-default/.babelrc.js delete mode 100644 packages/babel-core/test/fixtures/config/js-config-default/src.js delete mode 100644 packages/babel-core/test/fixtures/config/js-config-error/.babelrc.js delete mode 100644 packages/babel-core/test/fixtures/config/js-config-error/src.js delete mode 100644 packages/babel-core/test/fixtures/config/js-config-error2/.babelrc.js delete mode 100644 packages/babel-core/test/fixtures/config/js-config-error2/src.js delete mode 100644 packages/babel-core/test/fixtures/config/js-config-error3/.babelrc.js delete mode 100644 packages/babel-core/test/fixtures/config/js-config-error3/src.js delete mode 100644 packages/babel-core/test/fixtures/config/js-config-extended/.babelrc.js delete mode 100644 packages/babel-core/test/fixtures/config/js-config-extended/src.js delete mode 100644 packages/babel-core/test/fixtures/config/js-config-function/.babelrc.js delete mode 100644 packages/babel-core/test/fixtures/config/js-config/.babelrc.js delete mode 100644 packages/babel-core/test/fixtures/config/js-config/src.js delete mode 100644 packages/babel-core/test/fixtures/config/js-json-config/.babelrc delete mode 100644 packages/babel-core/test/fixtures/config/js-json-config/.babelrc.js delete mode 100644 packages/babel-core/test/fixtures/config/js-json-config/src.js delete mode 100644 packages/babel-core/test/fixtures/config/js-pkg-config/.babelrc.js delete mode 100644 packages/babel-core/test/fixtures/config/js-pkg-config/src.js delete mode 100644 packages/babel-core/test/fixtures/config/json-config-error/.babelrc delete mode 100644 packages/babel-core/test/fixtures/config/json-config-error/src.js delete mode 100644 packages/babel-core/test/fixtures/config/json-pkg-config-no-babel/.babelrc delete mode 100644 packages/babel-core/test/fixtures/config/json-pkg-config-no-babel/src.js delete mode 100644 packages/babel-core/test/fixtures/config/json-pkg-config/.babelrc delete mode 100644 packages/babel-core/test/fixtures/config/json-pkg-config/src.js delete mode 100644 packages/babel-core/test/fixtures/config/pkg/.babelignore delete mode 100644 packages/babel-core/test/fixtures/config/pkg/package.json delete mode 100644 packages/babel-core/test/fixtures/config/pkg/src.js diff --git a/packages/babel-core/src/config/option-manager.js b/packages/babel-core/src/config/option-manager.js index 42c1ac4e1f..355e1057d2 100644 --- a/packages/babel-core/src/config/option-manager.js +++ b/packages/babel-core/src/config/option-manager.js @@ -83,6 +83,8 @@ class OptionManager { delete options.plugins; delete options.presets; delete options.passPerPreset; + delete options.ignore; + delete options.only; // "sourceMap" is just aliased to sourceMap, so copy it over as // we merge the options together. diff --git a/packages/babel-core/test/config-chain.js b/packages/babel-core/test/config-chain.js index 4b4ea20ff0..f36ea98e4f 100644 --- a/packages/babel-core/test/config-chain.js +++ b/packages/babel-core/test/config-chain.js @@ -1,217 +1,250 @@ import assert from "assert"; import fs from "fs"; import path from "path"; -import buildConfigChainFn from "../lib/config/build-config-chain"; +import { loadOptions } from "../lib"; -const DEFAULT_ENV = "development"; - -function buildConfigChain(opts, envName) { - return buildConfigChainFn(process.cwd(), opts, envName); -} - -function fixture() { - const args = [__dirname, "fixtures", "config"]; - for (let i = 0; i < arguments.length; i++) { - args.push(arguments[i]); - } - return path.join.apply(path, args); -} - -function base() { - return process.cwd(); +function fixture(...args) { + return path.join(__dirname, "fixtures", "config", ...args); } describe("buildConfigChain", function() { describe("ignore", () => { it("should ignore files that match", () => { - const chain = buildConfigChain( - { - filename: fixture("nonexistant-fake", "src.js"), - babelrc: false, - ignore: [ - fixture("nonexistant-fake", "src.js"), + const opts = loadOptions({ + filename: fixture("nonexistant-fake", "src.js"), + babelrc: false, + ignore: [ + fixture("nonexistant-fake", "src.js"), - // We had a regression where multiple ignore patterns broke things, so - // we keep some extra random items in here. - fixture("nonexistant-fake", "other.js"), - fixture("nonexistant-fake", "misc.js"), - ], - }, - DEFAULT_ENV, - ); + // We had a regression where multiple ignore patterns broke things, so + // we keep some extra random items in here. + fixture("nonexistant-fake", "other.js"), + fixture("nonexistant-fake", "misc.js"), + ], + }); - assert.equal(chain, null); + assert.equal(opts, null); }); it("should not ignore files that don't match", () => { - const chain = buildConfigChain( - { - filename: fixture("nonexistant-fake", "src.js"), - babelrc: false, - ignore: [ - fixture("nonexistant-fake", "other.js"), - fixture("nonexistant-fake", "misc.js"), - ], - }, - DEFAULT_ENV, - ); + const opts = loadOptions({ + filename: fixture("nonexistant-fake", "src.js"), + babelrc: false, + ignore: [ + fixture("nonexistant-fake", "other.js"), + fixture("nonexistant-fake", "misc.js"), + ], + }); - const expected = [ - { - type: "arguments", - options: { - filename: fixture("nonexistant-fake", "src.js"), - babelrc: false, - ignore: [ - fixture("nonexistant-fake", "other.js"), - fixture("nonexistant-fake", "misc.js"), - ], - }, - alias: "base", - dirname: base(), - }, - ]; - - assert.deepEqual(chain, expected); + assert.notEqual(opts, null); }); }); describe("only", () => { it("should ignore files that don't match", () => { - const chain = buildConfigChain( - { - filename: fixture("nonexistant-fake", "src.js"), - babelrc: false, - only: [ - fixture("nonexistant-fake", "other.js"), - fixture("nonexistant-fake", "misc.js"), - ], - }, - DEFAULT_ENV, - ); + const opts = loadOptions({ + filename: fixture("nonexistant-fake", "src.js"), + babelrc: false, + only: [ + fixture("nonexistant-fake", "other.js"), + fixture("nonexistant-fake", "misc.js"), + ], + }); - assert.equal(chain, null); + assert.equal(opts, null); }); it("should not ignore files that match", () => { - const chain = buildConfigChain( - { - filename: fixture("nonexistant-fake", "src.js"), - babelrc: false, - only: [ - fixture("nonexistant-fake", "src.js"), - fixture("nonexistant-fake", "misc.js"), - ], - }, - DEFAULT_ENV, - ); + const opts = loadOptions({ + filename: fixture("nonexistant-fake", "src.js"), + babelrc: false, + only: [ + fixture("nonexistant-fake", "src.js"), + fixture("nonexistant-fake", "misc.js"), + ], + }); - const expected = [ - { - type: "arguments", - options: { - filename: fixture("nonexistant-fake", "src.js"), - babelrc: false, - only: [ - fixture("nonexistant-fake", "src.js"), - fixture("nonexistant-fake", "misc.js"), - ], - }, - alias: "base", - dirname: base(), - }, - ]; - - assert.deepEqual(chain, expected); + assert.notEqual(opts, null); }); }); describe("ignore/only", () => { it("should ignore files that match ignore and don't match only", () => { - const chain = buildConfigChain( - { - filename: fixture("nonexistant-fake", "src.js"), - babelrc: false, - ignore: [fixture("nonexistant-fake", "src.js")], - only: [fixture("nonexistant-fake", "src.js")], - }, - DEFAULT_ENV, - ); + const opts = loadOptions({ + filename: fixture("nonexistant-fake", "src.js"), + babelrc: false, + ignore: [fixture("nonexistant-fake", "src.js")], + only: [], + }); - assert.equal(chain, null); + assert.equal(opts, null); + }); + + it("should ignore files that match ignore and also only", () => { + const opts = loadOptions({ + filename: fixture("nonexistant-fake", "src.js"), + babelrc: false, + ignore: [fixture("nonexistant-fake", "src.js")], + only: [fixture("nonexistant-fake", "src.js")], + }); + + assert.equal(opts, null); + }); + + it("should not ignore files that match only and not ignore", () => { + const opts = loadOptions({ + filename: fixture("nonexistant-fake", "src.js"), + babelrc: false, + only: [fixture("nonexistant-fake", "src.js")], + }); + + assert.notEqual(opts, null); + }); + + it("should not ignore files when no ignore/only are specified", () => { + const opts = loadOptions({ + filename: fixture("nonexistant-fake", "src.js"), + babelrc: false, + }); + + assert.notEqual(opts, null); + }); + + it("should allow negation of only", () => { + const opts1 = loadOptions({ + filename: fixture("nonexistant-fake", "src.js"), + babelrc: false, + only: [ + "!" + fixture("nonexistant-fake"), + fixture("nonexistant-fake", "other.js"), + ], + }); + assert.equal(opts1, null); + + const opts2 = loadOptions({ + filename: fixture("nonexistant-fake", "src.js"), + babelrc: false, + only: [ + "!" + fixture("nonexistant-fake"), + fixture("nonexistant-fake", "src.js"), + ], + }); + assert.notEqual(opts2, null); + + const opts3 = loadOptions({ + filename: fixture("nonexistant-fake", "folder", "src.js"), + babelrc: false, + only: [ + "!" + fixture("nonexistant-fake"), + fixture("nonexistant-fake", "folder"), + ], + }); + assert.notEqual(opts3, null); + }); + + it("should allow negation of ignore", () => { + const opts1 = loadOptions({ + filename: fixture("nonexistant-fake", "src.js"), + babelrc: false, + ignore: [ + "!" + fixture("nonexistant-fake", "other.js"), + fixture("nonexistant-fake"), + ], + }); + assert.equal(opts1, null); + + // Tests disabled pending https://github.com/babel/babel/issues/6907 + // const opts2 = loadOptions({ + // filename: fixture("nonexistant-fake", "src.js"), + // babelrc: false, + // ignore: [ + // "!" + fixture("nonexistant-fake", "src.js"), + // fixture("nonexistant-fake"), + // ], + // }); + // assert.notEqual(opts2, null); + // + // const opts3 = loadOptions({ + // filename: fixture("nonexistant-fake", "folder", "src.js"), + // babelrc: false, + // ignore: [ + // "!" + fixture("nonexistant-fake", "folder"), + // fixture("nonexistant-fake"), + // ], + // }); + // assert.notEqual(opts3, null); }); }); describe("caching", function() { describe("programmatic options", function() { + const plugins1 = [() => ({})]; + const plugins2 = [() => ({})]; + it("should not cache the input options by identity", () => { - const comments = false; + const inputOpts = { plugins: plugins1 }; - const chain1 = buildConfigChain({ comments }, DEFAULT_ENV); - const chain2 = buildConfigChain({ comments }, DEFAULT_ENV); + const opts1 = loadOptions(inputOpts); - assert.equal(chain1.length, 1); - assert.equal(chain2.length, 1); - assert.notStrictEqual(chain1[0], chain2[0]); + inputOpts.plugins = plugins2; + const opts2 = loadOptions(inputOpts); + + assert.equal(opts1.plugins.length, 1); + assert.equal(opts2.plugins.length, 1); + assert.notEqual(opts1.plugins[0], opts2.plugins[1]); }); it("should cache the env options by identity", () => { const env = { foo: { - comments: false, + plugins: plugins1, }, }; - const chain1 = buildConfigChain({ env }, "foo"); - const chain2 = buildConfigChain({ env }, "foo"); + const opts1 = loadOptions({ envName: "foo", env }); - assert.equal(chain1.length, 2); - assert.equal(chain2.length, 2); - assert.strictEqual(chain1[0], chain2[0]); - assert.strictEqual(chain1[1], chain2[1]); + env.foo.plugins = plugins2; + const opts2 = loadOptions({ envName: "foo", env }); + + assert.equal(opts1.plugins.length, 1); + assert.equal(opts2.plugins.length, 1); + assert.equal(opts1.plugins[0], opts2.plugins[0]); }); it("should cache the plugin options by identity", () => { - const plugins = []; + const plugins = [() => ({})]; - const chain1 = buildConfigChain({ plugins }, DEFAULT_ENV); - const chain2 = buildConfigChain({ plugins }, DEFAULT_ENV); + const opts1 = loadOptions({ plugins }); + const opts2 = loadOptions({ plugins }); - assert.equal(chain1.length, 1); - assert.equal(chain2.length, 1); - assert.strictEqual(chain1[0], chain2[0]); + assert.equal(opts1.plugins.length, 1); + assert.equal(opts2.plugins.length, 1); + assert.equal(opts1.plugins[0], opts2.plugins[0]); }); it("should cache the presets options by identity", () => { - const presets = []; + const presets = [() => ({ plugins: [() => ({})] })]; - const chain1 = buildConfigChain({ presets }, DEFAULT_ENV); - const chain2 = buildConfigChain({ presets }, DEFAULT_ENV); + const opts1 = loadOptions({ presets }); + const opts2 = loadOptions({ presets }); - assert.equal(chain1.length, 1); - assert.equal(chain2.length, 1); - assert.strictEqual(chain1[0], chain2[0]); + assert.equal(opts1.plugins.length, 1); + assert.equal(opts2.plugins.length, 1); + assert.strictEqual(opts1.plugins[0], opts2.plugins[0]); }); it("should not cache the presets options with passPerPreset", () => { - const presets = []; + const presets = [() => ({ plugins: [() => ({})] })]; - const chain1 = buildConfigChain({ presets }, DEFAULT_ENV); - const chain2 = buildConfigChain( - { presets, passPerPreset: true }, - DEFAULT_ENV, - ); - const chain3 = buildConfigChain( - { presets, passPerPreset: false }, - DEFAULT_ENV, - ); + const opts1 = loadOptions({ presets }); + const opts2 = loadOptions({ presets, passPerPreset: true }); + const opts3 = loadOptions({ presets, passPerPreset: false }); - assert.equal(chain1.length, 1); - assert.equal(chain2.length, 1); - assert.equal(chain3.length, 1); - assert.notStrictEqual(chain1[0], chain2[0]); - assert.strictEqual(chain1[0], chain3[0]); - assert.notStrictEqual(chain2[0], chain3[0]); + assert.equal(opts1.plugins.length, 1); + assert.equal(opts2.plugins.length, 0); + assert.equal(opts3.plugins.length, 1); + + assert.strictEqual(opts1.plugins[0], opts3.plugins[0]); }); }); @@ -239,27 +272,24 @@ describe("buildConfigChain", function() { "package.json", ); - const chain1 = buildConfigChain({ filename }, DEFAULT_ENV); - const chain2 = buildConfigChain({ filename }, DEFAULT_ENV); + const opts1 = loadOptions({ filename }); + const opts2 = loadOptions({ filename }); touch(pkgJSON); - const chain3 = buildConfigChain({ filename }, DEFAULT_ENV); - const chain4 = buildConfigChain({ filename }, DEFAULT_ENV); + const opts3 = loadOptions({ filename }); + const opts4 = loadOptions({ filename }); - assert.equal(chain1.length, 3); - assert.equal(chain2.length, 3); - assert.equal(chain3.length, 3); - assert.equal(chain4.length, 3); - assert.equal(chain1[1].alias, pkgJSON); - assert.equal(chain2[1].alias, pkgJSON); - assert.equal(chain3[1].alias, pkgJSON); - assert.equal(chain4[1].alias, pkgJSON); - assert.strictEqual(chain1[1], chain2[1]); + assert.equal(opts1.plugins.length, 1); + assert.equal(opts2.plugins.length, 1); + assert.equal(opts1.plugins[0], opts2.plugins[0]); + + assert.equal(opts3.plugins.length, 1); + assert.equal(opts4.plugins.length, 1); + assert.equal(opts3.plugins[0], opts4.plugins[0]); // Identity changed after touch(). - assert.notStrictEqual(chain3[1], chain1[1]); - assert.strictEqual(chain3[1], chain4[1]); + assert.notEqual(opts1.plugins[0], opts3.plugins[0]); }); it("should cache .babelrc files by mtime", () => { @@ -276,64 +306,24 @@ describe("buildConfigChain", function() { ".babelrc", ); - const chain1 = buildConfigChain({ filename }, DEFAULT_ENV); - const chain2 = buildConfigChain({ filename }, DEFAULT_ENV); + const opts1 = loadOptions({ filename }); + const opts2 = loadOptions({ filename }); touch(babelrcFile); - const chain3 = buildConfigChain({ filename }, DEFAULT_ENV); - const chain4 = buildConfigChain({ filename }, DEFAULT_ENV); + const opts3 = loadOptions({ filename }); + const opts4 = loadOptions({ filename }); - assert.equal(chain1.length, 3); - assert.equal(chain2.length, 3); - assert.equal(chain3.length, 3); - assert.equal(chain4.length, 3); - assert.equal(chain1[1].alias, babelrcFile); - assert.equal(chain2[1].alias, babelrcFile); - assert.equal(chain3[1].alias, babelrcFile); - assert.equal(chain4[1].alias, babelrcFile); - assert.strictEqual(chain1[1], chain2[1]); + assert.equal(opts1.plugins.length, 1); + assert.equal(opts2.plugins.length, 1); + assert.equal(opts1.plugins[0], opts2.plugins[0]); + + assert.equal(opts3.plugins.length, 1); + assert.equal(opts4.plugins.length, 1); + assert.equal(opts3.plugins[0], opts4.plugins[0]); // Identity changed after touch(). - assert.notStrictEqual(chain3[1], chain1[1]); - assert.strictEqual(chain3[1], chain4[1]); - }); - - it("should cache .babelignore files by mtime", () => { - const filename = fixture( - "complex-plugin-config", - "config-identity", - "babelignore", - "src.js", - ); - const babelignoreFile = fixture( - "complex-plugin-config", - "config-identity", - "babelignore", - ".babelignore", - ); - - const chain1 = buildConfigChain({ filename }, DEFAULT_ENV); - const chain2 = buildConfigChain({ filename }, DEFAULT_ENV); - - touch(babelignoreFile); - - const chain3 = buildConfigChain({ filename }, DEFAULT_ENV); - const chain4 = buildConfigChain({ filename }, DEFAULT_ENV); - - assert.equal(chain1.length, 6); - assert.equal(chain2.length, 6); - assert.equal(chain3.length, 6); - assert.equal(chain4.length, 6); - assert.equal(chain1[4].alias, babelignoreFile); - assert.equal(chain2[4].alias, babelignoreFile); - assert.equal(chain3[4].alias, babelignoreFile); - assert.equal(chain4[4].alias, babelignoreFile); - assert.strictEqual(chain1[4], chain2[4]); - - // Identity changed after touch(). - assert.notStrictEqual(chain3[4], chain1[4]); - assert.strictEqual(chain3[4], chain4[4]); + assert.notEqual(opts1.plugins[0], opts3.plugins[0]); }); it("should cache .babelrc.js files programmable behavior", () => { @@ -343,742 +333,132 @@ describe("buildConfigChain", function() { "babelrc-js", "src.js", ); - const babelrcFile = fixture( - "complex-plugin-config", - "config-identity", - "babelrc-js", - ".babelrc.js", - ); - const chain1 = buildConfigChain({ filename }, DEFAULT_ENV); - const chain2 = buildConfigChain({ filename }, DEFAULT_ENV); + const opts1 = loadOptions({ filename }); + const opts2 = loadOptions({ filename }); - const chain3 = buildConfigChain({ filename }, "new-env"); - const chain4 = buildConfigChain({ filename }, "new-env"); + const opts3 = loadOptions({ filename, envName: "new-env" }); + const opts4 = loadOptions({ filename, envName: "new-env" }); - assert.equal(chain1.length, 3); - assert.equal(chain2.length, 3); - assert.equal(chain3.length, 3); - assert.equal(chain4.length, 3); - assert.equal(chain1[1].alias, babelrcFile); - assert.equal(chain2[1].alias, babelrcFile); - assert.equal(chain3[1].alias, babelrcFile); - assert.equal(chain4[1].alias, babelrcFile); - assert.strictEqual(chain1[1], chain2[1]); + assert.equal(opts1.plugins.length, 1); + assert.equal(opts2.plugins.length, 1); + assert.equal(opts1.plugins[0], opts2.plugins[0]); - // Identity changed after changing the envName. - assert.notStrictEqual(chain3[1], chain1[1]); - assert.strictEqual(chain3[1], chain4[1]); + assert.equal(opts3.plugins.length, 1); + assert.equal(opts4.plugins.length, 1); + assert.equal(opts3.plugins[0], opts4.plugins[0]); + + // Identity changed with different .env + assert.notEqual(opts1.plugins[0], opts3.plugins[0]); }); }); }); - it("dir1", function() { - const chain = buildConfigChain( - { - filename: fixture("dir1", "src.js"), - }, - DEFAULT_ENV, - ); + describe("config files", () => { + const getDefaults = () => ({ + babelrc: false, + cwd: process.cwd(), + envName: "development", + passPerPreset: false, + plugins: [], + presets: [], + }); - const expected = [ - { - type: "file", - options: { - plugins: ["extended"], - }, - alias: fixture("extended.babelrc.json"), - dirname: fixture(), - }, - { - type: "file", - options: { - extends: "./extended.babelrc.json", - plugins: ["root"], - }, - alias: fixture(".babelrc"), - dirname: fixture(), - }, - { - type: "file", - options: { - ignore: ["root-ignore"], - }, - alias: fixture(".babelignore"), - dirname: fixture(), - }, - { - type: "arguments", - options: { - filename: fixture("dir1", "src.js"), - }, - alias: "base", - dirname: base(), - }, - ]; + it("should load .babelrc", () => { + const filename = fixture("config-files", "babelrc", "src.js"); - assert.deepEqual(chain, expected); - }); + assert.deepEqual(loadOptions({ filename }), { + ...getDefaults(), + filename, + comments: true, + }); + }); - it("dir2", function() { - const chain = buildConfigChain( - { - filename: fixture("dir2", "src.js"), - }, - DEFAULT_ENV, - ); + it("should load .babelrc.js", () => { + const filename = fixture("config-files", "babelrc-js", "src.js"); - const expected = [ - { - type: "file", - options: { - ignore: ["root-ignore"], - }, - alias: fixture(".babelignore"), - dirname: fixture(), - }, - { - type: "file", - options: { - plugins: ["dir2"], - }, - alias: fixture("dir2", ".babelrc"), - dirname: fixture("dir2"), - }, - { - type: "arguments", - options: { - filename: fixture("dir2", "src.js"), - }, - alias: "base", - dirname: base(), - }, - ]; + assert.deepEqual(loadOptions({ filename }), { + ...getDefaults(), + filename, + comments: true, + }); + }); - assert.deepEqual(chain, expected); - }); + it("should load package.json#babel", () => { + const filename = fixture("config-files", "pkg", "src.js"); - it("dir3", function() { - const chain = buildConfigChain( - { - filename: fixture("dir3", "src.js"), - }, - DEFAULT_ENV, - ); + assert.deepEqual(loadOptions({ filename }), { + ...getDefaults(), + filename, + comments: true, + }); + }); - const expected = [ - { - type: "file", - options: { - plugins: ["extended"], - }, - alias: fixture("extended.babelrc.json"), - dirname: fixture(), - }, - { - type: "file", - options: { - extends: "./extended.babelrc.json", - plugins: ["root"], - }, - alias: fixture(".babelrc"), - dirname: fixture(), - }, - { - type: "file", - options: { - ignore: ["root-ignore"], - }, - alias: fixture(".babelignore"), - dirname: fixture(), - }, - { - type: "arguments", - options: { - filename: fixture("dir3", "src.js"), - }, - alias: "base", - dirname: base(), - }, - ]; + it("should load .babelignore", () => { + const filename = fixture("config-files", "babelignore", "src.js"); - assert.deepEqual(chain, expected); - }); + assert.deepEqual(loadOptions({ filename }), null); + }); - it("env - base", function() { - const chain = buildConfigChain( - { - filename: fixture("env", "src.js"), - }, - DEFAULT_ENV, - ); + it("should throw if there are both .babelrc and .babelrc.js", () => { + const filename = fixture("config-files", "both-babelrc", "src.js"); - const expected = [ - { - type: "file", - options: { - ignore: ["root-ignore"], - }, - alias: fixture(".babelignore"), - dirname: fixture(), - }, - { - type: "file", - options: { - env: { - bar: { - plugins: ["env-bar"], - }, - foo: { - plugins: ["env-foo"], - }, - }, - plugins: ["env-base"], - }, - alias: fixture("env", ".babelrc"), - dirname: fixture("env"), - }, - { - type: "arguments", - options: { - filename: fixture("env", "src.js"), - }, - alias: "base", - dirname: base(), - }, - ]; - - assert.deepEqual(chain, expected); - }); - - it("env - foo", function() { - const chain = buildConfigChain( - { - filename: fixture("env", "src.js"), - }, - "foo", - ); - - const expected = [ - { - type: "file", - options: { - ignore: ["root-ignore"], - }, - alias: fixture(".babelignore"), - dirname: fixture(), - }, - { - type: "file", - options: { - env: { - bar: { - plugins: ["env-bar"], - }, - foo: { - plugins: ["env-foo"], - }, - }, - plugins: ["env-base"], - }, - alias: fixture("env", ".babelrc"), - dirname: fixture("env"), - }, - { - type: "env", - options: { - plugins: ["env-foo"], - }, - alias: fixture("env", ".babelrc.env.foo"), - dirname: fixture("env"), - }, - { - type: "arguments", - options: { - filename: fixture("env", "src.js"), - }, - alias: "base", - dirname: base(), - }, - ]; - - assert.deepEqual(chain, expected); - }); - - it("env - bar", function() { - const chain = buildConfigChain( - { - filename: fixture("env", "src.js"), - }, - "bar", - ); - - const expected = [ - { - type: "file", - options: { - ignore: ["root-ignore"], - }, - alias: fixture(".babelignore"), - dirname: fixture(), - }, - { - type: "file", - options: { - env: { - bar: { - plugins: ["env-bar"], - }, - foo: { - plugins: ["env-foo"], - }, - }, - plugins: ["env-base"], - }, - alias: fixture("env", ".babelrc"), - dirname: fixture("env"), - }, - { - type: "env", - options: { - plugins: ["env-bar"], - }, - alias: fixture("env", ".babelrc.env.bar"), - dirname: fixture("env"), - }, - { - type: "arguments", - options: { - filename: fixture("env", "src.js"), - }, - alias: "base", - dirname: base(), - }, - ]; - - assert.deepEqual(chain, expected); - }); - - it("env - foo", function() { - const chain = buildConfigChain( - { - filename: fixture("pkg", "src.js"), - }, - "foo", - ); - - const expected = [ - { - type: "file", - options: { - plugins: ["pkg-plugin"], - }, - alias: fixture("pkg", "package.json"), - dirname: fixture("pkg"), - }, - { - type: "file", - options: { - ignore: ["pkg-ignore"], - }, - alias: fixture("pkg", ".babelignore"), - dirname: fixture("pkg"), - }, - { - type: "arguments", - options: { - filename: fixture("pkg", "src.js"), - }, - alias: "base", - dirname: base(), - }, - ]; - - assert.deepEqual(chain, expected); - }); - - it("js-config", function() { - const chain = buildConfigChain( - { - filename: fixture("js-config", "src.js"), - }, - DEFAULT_ENV, - ); - - const expected = [ - { - type: "file", - options: { - ignore: ["root-ignore"], - }, - alias: fixture(".babelignore"), - dirname: fixture(), - }, - { - type: "file", - options: { - plugins: ["foo", "bar"], - }, - alias: fixture("js-config", ".babelrc.js"), - dirname: fixture("js-config"), - }, - { - type: "arguments", - options: { - filename: fixture("js-config", "src.js"), - }, - alias: "base", - dirname: base(), - }, - ]; - - assert.deepEqual(chain, expected); - }); - - it("js-config-function", function() { - const chain = buildConfigChain( - { - filename: fixture("js-config-function", "src.js"), - }, - DEFAULT_ENV, - ); - - const expected = [ - { - type: "file", - options: { - ignore: ["root-ignore"], - }, - alias: fixture(".babelignore"), - dirname: fixture(), - }, - { - type: "file", - options: { - compact: true, - }, - alias: fixture("js-config-function", ".babelrc.js"), - dirname: fixture("js-config-function"), - }, - { - type: "arguments", - options: { - filename: fixture("js-config-function", "src.js"), - }, - alias: "base", - dirname: base(), - }, - ]; - - assert.deepEqual(chain, expected); - }); - - it("js-config-default - should read transpiled export default", function() { - const chain = buildConfigChain( - { - filename: fixture("js-config-default", "src.js"), - }, - DEFAULT_ENV, - ); - - const expected = [ - { - type: "file", - options: { - ignore: ["root-ignore"], - }, - alias: fixture(".babelignore"), - dirname: fixture(), - }, - { - type: "file", - options: { - plugins: ["foo", "bar"], - }, - alias: fixture("js-config-default", ".babelrc.js"), - dirname: fixture("js-config-default"), - }, - { - type: "arguments", - options: { - filename: fixture("js-config-default", "src.js"), - }, - alias: "base", - dirname: base(), - }, - ]; - - assert.deepEqual(chain, expected); - }); - it("js-config-extended", function() { - const chain = buildConfigChain( - { - filename: fixture("js-config-extended", "src.js"), - }, - DEFAULT_ENV, - ); - - const expected = [ - { - type: "file", - options: { - ignore: ["root-ignore"], - }, - alias: fixture(".babelignore"), - dirname: fixture(), - }, - { - type: "file", - options: { - plugins: ["extended"], - }, - alias: fixture("extended.babelrc.json"), - dirname: fixture(), - }, - { - type: "file", - options: { - extends: "../extended.babelrc.json", - plugins: ["foo", "bar"], - }, - alias: fixture("js-config-extended", ".babelrc.js"), - dirname: fixture("js-config-extended"), - }, - { - type: "arguments", - options: { - filename: fixture("js-config-extended", "src.js"), - }, - alias: "base", - dirname: base(), - }, - ]; - - assert.deepEqual(chain, expected); - }); - - it( - "json-pkg-config-no-babel - should not throw if" + - " package.json doesn't contain a `babel` field", - function() { - const chain = buildConfigChain( - { - filename: fixture("json-pkg-config-no-babel", "src.js"), - }, - DEFAULT_ENV, + assert.throws( + () => loadOptions({ filename }), + /Multiple configuration files found/, ); + }); - const expected = [ - { - type: "file", - options: { - ignore: ["root-ignore"], - }, - alias: fixture(".babelignore"), - dirname: fixture(), - }, - { - type: "file", - options: { - plugins: ["json"], - }, - alias: fixture("json-pkg-config-no-babel", ".babelrc"), - dirname: fixture("json-pkg-config-no-babel"), - }, - { - type: "arguments", - options: { - filename: fixture("json-pkg-config-no-babel", "src.js"), - }, - alias: "base", - dirname: base(), - }, - ]; + it("should throw if there are both .babelrc and package.json", () => { + const filename = fixture("config-files", "pkg-babelrc", "src.js"); - assert.deepEqual(chain, expected); - }, - ); - - it("should not ignore file matching negated file pattern", function() { - const chain = buildConfigChain( - { - filename: fixture("ignore-negate", "src.js"), - }, - DEFAULT_ENV, - ); - - const expected = [ - { - type: "file", - options: { - ignore: ["root-ignore"], - }, - alias: fixture(".babelignore"), - dirname: fixture(), - }, - { - type: "file", - options: { - ignore: ["*", "!src.js"], - }, - alias: fixture("ignore-negate", ".babelrc"), - dirname: fixture("ignore-negate"), - }, - { - type: "arguments", - options: { - filename: fixture("ignore-negate", "src.js"), - }, - alias: "base", - dirname: base(), - }, - ]; - - assert.deepEqual(chain, expected); - - const chain2 = buildConfigChain( - { - filename: fixture("ignore-negate", "src2.js"), - }, - DEFAULT_ENV, - ); - - assert.equal(chain2, null); - }); - - it("should not ignore file matching negated folder pattern", function() { - const chain = buildConfigChain( - { - filename: fixture("ignore-negate-folder", "folder", "src.js"), - }, - DEFAULT_ENV, - ); - - const expected = [ - { - type: "file", - options: { - ignore: ["root-ignore"], - }, - alias: fixture(".babelignore"), - dirname: fixture(), - }, - { - type: "file", - options: { - ignore: ["*", "!folder"], - }, - alias: fixture("ignore-negate-folder", ".babelrc"), - dirname: fixture("ignore-negate-folder"), - }, - { - type: "arguments", - options: { - filename: fixture("ignore-negate-folder", "folder", "src.js"), - }, - alias: "base", - dirname: base(), - }, - ]; - - assert.deepEqual(chain, expected); - - const chain2 = buildConfigChain( - { - filename: fixture("ignore-negate-folder", "src2.js"), - }, - DEFAULT_ENV, - ); - - assert.equal(chain2, null); - }); - - it( - "js-json-config - should throw an error if both a .babelrc" + - " and a .babelrc.js are present", - function() { - assert.throws(function() { - buildConfigChain( - { - filename: fixture("js-json-config", "src.js"), - }, - DEFAULT_ENV, - ); - }, /Multiple configuration files found\.(.|\n)*\.babelrc(.|\n)*\.babelrc\.js/); - }, - ); - - it( - "js-pkg-config - should throw an error if both a .babelrc.js" + - " and a package.json with a babel field are present", - function() { - assert.throws(function() { - buildConfigChain( - { - filename: fixture("js-pkg-config", "src.js"), - }, - DEFAULT_ENV, - ); - }, /Multiple configuration files found\.(.|\n)*\.babelrc\.js(.|\n)*package\.json/); - }, - ); - - it( - "json-pkg-config - should throw an error if both a .babelrc" + - " and a package.json with a babel field are present", - function() { - assert.throws(function() { - buildConfigChain( - { - filename: fixture("json-pkg-config", "src.js"), - }, - DEFAULT_ENV, - ); - }, /Multiple configuration files found\.(.|\n)*\.babelrc(.|\n)*package\.json/); - }, - ); - - it("js-config-error", function() { - assert.throws(function() { - buildConfigChain( - { - filename: fixture("js-config-error", "src.js"), - }, - DEFAULT_ENV, + assert.throws( + () => loadOptions({ filename }), + /Multiple configuration files found/, ); - }, /Error while loading config/); - }); + }); - it("js-config-error2", function() { - assert.throws(function() { - buildConfigChain( - { - filename: fixture("js-config-error2", "src.js"), - }, - DEFAULT_ENV, - ); - }, /Configuration should be an exported JavaScript object/); - }); + it("should throw if there are both .babelrc.js and package.json", () => { + const filename = fixture("config-files", "pkg-babelrc-js", "src.js"); - it("js-config-error3", function() { - assert.throws(function() { - buildConfigChain( - { - filename: fixture("js-config-error3", "src.js"), - }, - DEFAULT_ENV, + assert.throws( + () => loadOptions({ filename }), + /Multiple configuration files found/, ); - }, /Configuration should be an exported JavaScript object/); - }); + }); - it("json-config-error", function() { - assert.throws(function() { - buildConfigChain( - { - filename: fixture("json-config-error", "src.js"), - }, - DEFAULT_ENV, + it("should ignore package.json without a 'babel' property", () => { + const filename = fixture("config-files", "pkg-ignored", "src.js"); + + assert.deepEqual(loadOptions({ filename }), { + ...getDefaults(), + filename, + comments: true, + }); + }); + + it("should show helpful errors for .babelrc", () => { + const filename = fixture("config-files", "babelrc-error", "src.js"); + + assert.throws( + () => loadOptions({ filename }), + /Error while parsing config - /, ); - }, /Error while parsing config/); + }); + + it("should show helpful errors for .babelrc.js", () => { + const filename = fixture("config-files", "babelrc-js-error", "src.js"); + + assert.throws(() => loadOptions({ filename }), /Babelrc threw an error/); + }); + + it("should show helpful errors for package.json", () => { + const filename = fixture("config-files", "pkg-error", "src.js"); + + assert.throws( + () => loadOptions({ filename }), + /Error while parsing JSON - /, + ); + }); }); }); diff --git a/packages/babel-core/test/fixtures/config/.babelignore b/packages/babel-core/test/fixtures/config/.babelignore deleted file mode 100644 index 054b9bf2d3..0000000000 --- a/packages/babel-core/test/fixtures/config/.babelignore +++ /dev/null @@ -1 +0,0 @@ -root-ignore diff --git a/packages/babel-core/test/fixtures/config/.babelrc b/packages/babel-core/test/fixtures/config/.babelrc deleted file mode 100644 index 3dc5d1fa19..0000000000 --- a/packages/babel-core/test/fixtures/config/.babelrc +++ /dev/null @@ -1,4 +0,0 @@ -{ - "plugins": ["root"], - "extends": "./extended.babelrc.json" -} diff --git a/packages/babel-core/test/fixtures/config/complex-plugin-config/.babelignore b/packages/babel-core/test/fixtures/config/complex-plugin-config/.babelignore index 81b328e97e..8bfc7be079 100644 --- a/packages/babel-core/test/fixtures/config/complex-plugin-config/.babelignore +++ b/packages/babel-core/test/fixtures/config/complex-plugin-config/.babelignore @@ -18,4 +18,5 @@ seventeen.js eighteen.js nineteen.js twenty.js -plugin.js + +**/plugin.js diff --git a/packages/babel-core/test/fixtures/config/complex-plugin-config/config-identity/babelrc-js/.babelrc.js b/packages/babel-core/test/fixtures/config/complex-plugin-config/config-identity/babelrc-js/.babelrc.js index 968dcc5d7d..4c6ead5b56 100644 --- a/packages/babel-core/test/fixtures/config/complex-plugin-config/config-identity/babelrc-js/.babelrc.js +++ b/packages/babel-core/test/fixtures/config/complex-plugin-config/config-identity/babelrc-js/.babelrc.js @@ -2,6 +2,8 @@ module.exports = function(api) { api.env(); return { - comments: false, + plugins: [ + require("./plugin"), + ], }; } diff --git a/packages/babel-core/test/fixtures/config/complex-plugin-config/config-identity/babelrc-js/plugin.js b/packages/babel-core/test/fixtures/config/complex-plugin-config/config-identity/babelrc-js/plugin.js new file mode 100644 index 0000000000..2987ecf017 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/complex-plugin-config/config-identity/babelrc-js/plugin.js @@ -0,0 +1,3 @@ +module.exports = function() { + return {}; +}; diff --git a/packages/babel-core/test/fixtures/config/complex-plugin-config/config-identity/babelrc/.babelrc b/packages/babel-core/test/fixtures/config/complex-plugin-config/config-identity/babelrc/.babelrc index 68628f8709..b6c4eda98c 100644 --- a/packages/babel-core/test/fixtures/config/complex-plugin-config/config-identity/babelrc/.babelrc +++ b/packages/babel-core/test/fixtures/config/complex-plugin-config/config-identity/babelrc/.babelrc @@ -1,3 +1,3 @@ { - comments: false, + plugins: ["./plugin"], } diff --git a/packages/babel-core/test/fixtures/config/complex-plugin-config/config-identity/babelrc/plugin.js b/packages/babel-core/test/fixtures/config/complex-plugin-config/config-identity/babelrc/plugin.js new file mode 100644 index 0000000000..2987ecf017 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/complex-plugin-config/config-identity/babelrc/plugin.js @@ -0,0 +1,3 @@ +module.exports = function() { + return {}; +}; diff --git a/packages/babel-core/test/fixtures/config/complex-plugin-config/config-identity/pkg/package.json b/packages/babel-core/test/fixtures/config/complex-plugin-config/config-identity/pkg/package.json index 612c17bb1f..15c1fa1430 100644 --- a/packages/babel-core/test/fixtures/config/complex-plugin-config/config-identity/pkg/package.json +++ b/packages/babel-core/test/fixtures/config/complex-plugin-config/config-identity/pkg/package.json @@ -1,5 +1,5 @@ { "babel": { - "comments": false + "plugins": ["./plugin"] } } diff --git a/packages/babel-core/test/fixtures/config/complex-plugin-config/config-identity/pkg/plugin.js b/packages/babel-core/test/fixtures/config/complex-plugin-config/config-identity/pkg/plugin.js new file mode 100644 index 0000000000..2987ecf017 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/complex-plugin-config/config-identity/pkg/plugin.js @@ -0,0 +1,3 @@ +module.exports = function() { + return {}; +}; diff --git a/packages/babel-core/test/fixtures/config/config-files/.babelignore b/packages/babel-core/test/fixtures/config/config-files/.babelignore new file mode 100644 index 0000000000..56afcc3fdd --- /dev/null +++ b/packages/babel-core/test/fixtures/config/config-files/.babelignore @@ -0,0 +1 @@ +# Placeholder so the monorepo ignore isn't accessed diff --git a/packages/babel-core/test/fixtures/config/config-files/babelignore/.babelignore b/packages/babel-core/test/fixtures/config/config-files/babelignore/.babelignore new file mode 100644 index 0000000000..66a870808e --- /dev/null +++ b/packages/babel-core/test/fixtures/config/config-files/babelignore/.babelignore @@ -0,0 +1 @@ +src.js diff --git a/packages/babel-core/test/fixtures/config/config-files/babelrc-error/.babelrc b/packages/babel-core/test/fixtures/config/config-files/babelrc-error/.babelrc new file mode 100644 index 0000000000..1d936d04a4 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/config-files/babelrc-error/.babelrc @@ -0,0 +1 @@ +{45 diff --git a/packages/babel-core/test/fixtures/config/config-files/babelrc-js-error/.babelrc.js b/packages/babel-core/test/fixtures/config/config-files/babelrc-js-error/.babelrc.js new file mode 100644 index 0000000000..accbe7c461 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/config-files/babelrc-js-error/.babelrc.js @@ -0,0 +1,3 @@ +module.exports = function() { + throw new Error("Babelrc threw an error"); +}; diff --git a/packages/babel-core/test/fixtures/config/config-files/babelrc-js/.babelrc.js b/packages/babel-core/test/fixtures/config/config-files/babelrc-js/.babelrc.js new file mode 100644 index 0000000000..37622f0ad3 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/config-files/babelrc-js/.babelrc.js @@ -0,0 +1,3 @@ +module.exports = { + comments: true, +}; diff --git a/packages/babel-core/test/fixtures/config/config-files/babelrc/.babelrc b/packages/babel-core/test/fixtures/config/config-files/babelrc/.babelrc new file mode 100644 index 0000000000..2f6b10872c --- /dev/null +++ b/packages/babel-core/test/fixtures/config/config-files/babelrc/.babelrc @@ -0,0 +1,3 @@ +{ + comments: true, +} diff --git a/packages/babel-core/test/fixtures/config/json-pkg-config-no-babel/package.json b/packages/babel-core/test/fixtures/config/config-files/both-babelrc/.babelrc similarity index 100% rename from packages/babel-core/test/fixtures/config/json-pkg-config-no-babel/package.json rename to packages/babel-core/test/fixtures/config/config-files/both-babelrc/.babelrc diff --git a/packages/babel-core/test/fixtures/config/config-files/both-babelrc/.babelrc.js b/packages/babel-core/test/fixtures/config/config-files/both-babelrc/.babelrc.js new file mode 100644 index 0000000000..f053ebf797 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/config-files/both-babelrc/.babelrc.js @@ -0,0 +1 @@ +module.exports = {}; diff --git a/packages/babel-core/test/fixtures/config/config-files/pkg-babelrc-js/.babelrc.js b/packages/babel-core/test/fixtures/config/config-files/pkg-babelrc-js/.babelrc.js new file mode 100644 index 0000000000..f053ebf797 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/config-files/pkg-babelrc-js/.babelrc.js @@ -0,0 +1 @@ +module.exports = {}; diff --git a/packages/babel-core/test/fixtures/config/js-pkg-config/package.json b/packages/babel-core/test/fixtures/config/config-files/pkg-babelrc-js/package.json similarity index 100% rename from packages/babel-core/test/fixtures/config/js-pkg-config/package.json rename to packages/babel-core/test/fixtures/config/config-files/pkg-babelrc-js/package.json diff --git a/packages/babel-core/test/fixtures/config/config-files/pkg-babelrc/.babelrc b/packages/babel-core/test/fixtures/config/config-files/pkg-babelrc/.babelrc new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/packages/babel-core/test/fixtures/config/config-files/pkg-babelrc/.babelrc @@ -0,0 +1 @@ +{} diff --git a/packages/babel-core/test/fixtures/config/json-pkg-config/package.json b/packages/babel-core/test/fixtures/config/config-files/pkg-babelrc/package.json similarity index 100% rename from packages/babel-core/test/fixtures/config/json-pkg-config/package.json rename to packages/babel-core/test/fixtures/config/config-files/pkg-babelrc/package.json diff --git a/packages/babel-core/test/fixtures/config/config-files/pkg-error/package.json b/packages/babel-core/test/fixtures/config/config-files/pkg-error/package.json new file mode 100644 index 0000000000..5d59a03edc --- /dev/null +++ b/packages/babel-core/test/fixtures/config/config-files/pkg-error/package.json @@ -0,0 +1,3 @@ +{ + "babel": {235 +} diff --git a/packages/babel-core/test/fixtures/config/config-files/pkg-ignored/.babelrc b/packages/babel-core/test/fixtures/config/config-files/pkg-ignored/.babelrc new file mode 100644 index 0000000000..2f6b10872c --- /dev/null +++ b/packages/babel-core/test/fixtures/config/config-files/pkg-ignored/.babelrc @@ -0,0 +1,3 @@ +{ + comments: true, +} diff --git a/packages/babel-core/test/fixtures/config/config-files/pkg-ignored/package.json b/packages/babel-core/test/fixtures/config/config-files/pkg-ignored/package.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/packages/babel-core/test/fixtures/config/config-files/pkg-ignored/package.json @@ -0,0 +1 @@ +{} diff --git a/packages/babel-core/test/fixtures/config/config-files/pkg/package.json b/packages/babel-core/test/fixtures/config/config-files/pkg/package.json new file mode 100644 index 0000000000..49de3b4a5d --- /dev/null +++ b/packages/babel-core/test/fixtures/config/config-files/pkg/package.json @@ -0,0 +1,5 @@ +{ + "babel": { + "comments": true + } +} diff --git a/packages/babel-core/test/fixtures/config/dir1/src.js b/packages/babel-core/test/fixtures/config/dir1/src.js deleted file mode 100644 index 8b1a393741..0000000000 --- a/packages/babel-core/test/fixtures/config/dir1/src.js +++ /dev/null @@ -1 +0,0 @@ -// empty diff --git a/packages/babel-core/test/fixtures/config/dir2/.babelrc b/packages/babel-core/test/fixtures/config/dir2/.babelrc deleted file mode 100644 index bb094e669b..0000000000 --- a/packages/babel-core/test/fixtures/config/dir2/.babelrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "plugins": [ - "dir2" - ] -} diff --git a/packages/babel-core/test/fixtures/config/dir2/src.js b/packages/babel-core/test/fixtures/config/dir2/src.js deleted file mode 100644 index 8b1a393741..0000000000 --- a/packages/babel-core/test/fixtures/config/dir2/src.js +++ /dev/null @@ -1 +0,0 @@ -// empty diff --git a/packages/babel-core/test/fixtures/config/dir3/package.json b/packages/babel-core/test/fixtures/config/dir3/package.json deleted file mode 100644 index e65c70ab41..0000000000 --- a/packages/babel-core/test/fixtures/config/dir3/package.json +++ /dev/null @@ -1,5 +0,0 @@ - -{ - "name": "application-name", - "version": "0.0.1" -} diff --git a/packages/babel-core/test/fixtures/config/dir3/src.js b/packages/babel-core/test/fixtures/config/dir3/src.js deleted file mode 100644 index 8b1a393741..0000000000 --- a/packages/babel-core/test/fixtures/config/dir3/src.js +++ /dev/null @@ -1 +0,0 @@ -// empty diff --git a/packages/babel-core/test/fixtures/config/env/.babelrc b/packages/babel-core/test/fixtures/config/env/.babelrc deleted file mode 100644 index 8804d3b2fb..0000000000 --- a/packages/babel-core/test/fixtures/config/env/.babelrc +++ /dev/null @@ -1,11 +0,0 @@ -{ - "plugins": ["env-base"], - "env": { - "foo": { - "plugins": ["env-foo"] - }, - "bar": { - "plugins": ["env-bar"] - } - } -} diff --git a/packages/babel-core/test/fixtures/config/env/src.js b/packages/babel-core/test/fixtures/config/env/src.js deleted file mode 100644 index 8b1a393741..0000000000 --- a/packages/babel-core/test/fixtures/config/env/src.js +++ /dev/null @@ -1 +0,0 @@ -// empty diff --git a/packages/babel-core/test/fixtures/config/extended.babelrc.json b/packages/babel-core/test/fixtures/config/extended.babelrc.json deleted file mode 100644 index 6996c6d74e..0000000000 --- a/packages/babel-core/test/fixtures/config/extended.babelrc.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "plugins": [ - "extended" - ] -} diff --git a/packages/babel-core/test/fixtures/config/ignore-negate-folder/.babelrc b/packages/babel-core/test/fixtures/config/ignore-negate-folder/.babelrc deleted file mode 100644 index dfee3683a4..0000000000 --- a/packages/babel-core/test/fixtures/config/ignore-negate-folder/.babelrc +++ /dev/null @@ -1,6 +0,0 @@ -{ - ignore: [ - "*", - "!folder", - ], -} diff --git a/packages/babel-core/test/fixtures/config/ignore-negate-folder/folder/.gitignore b/packages/babel-core/test/fixtures/config/ignore-negate-folder/folder/.gitignore deleted file mode 100644 index b65b769d49..0000000000 --- a/packages/babel-core/test/fixtures/config/ignore-negate-folder/folder/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Blank .gitignore to ensure this directory exists. -!.gitignore diff --git a/packages/babel-core/test/fixtures/config/ignore-negate/.babelrc b/packages/babel-core/test/fixtures/config/ignore-negate/.babelrc deleted file mode 100644 index 301a5ac2b1..0000000000 --- a/packages/babel-core/test/fixtures/config/ignore-negate/.babelrc +++ /dev/null @@ -1,6 +0,0 @@ -{ - ignore: [ - "*", - "!src.js", - ], -} diff --git a/packages/babel-core/test/fixtures/config/js-config-default/.babelrc.js b/packages/babel-core/test/fixtures/config/js-config-default/.babelrc.js deleted file mode 100644 index de5f1c0244..0000000000 --- a/packages/babel-core/test/fixtures/config/js-config-default/.babelrc.js +++ /dev/null @@ -1,10 +0,0 @@ -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -var plugins = ["foo", "bar"]; - -exports.default = { - plugins: plugins -}; diff --git a/packages/babel-core/test/fixtures/config/js-config-default/src.js b/packages/babel-core/test/fixtures/config/js-config-default/src.js deleted file mode 100644 index 8b1a393741..0000000000 --- a/packages/babel-core/test/fixtures/config/js-config-default/src.js +++ /dev/null @@ -1 +0,0 @@ -// empty diff --git a/packages/babel-core/test/fixtures/config/js-config-error/.babelrc.js b/packages/babel-core/test/fixtures/config/js-config-error/.babelrc.js deleted file mode 100644 index d14a2b71a8..0000000000 --- a/packages/babel-core/test/fixtures/config/js-config-error/.babelrc.js +++ /dev/null @@ -1,2 +0,0 @@ -throw new Error("Something bad happened!"); -module.exports = {} diff --git a/packages/babel-core/test/fixtures/config/js-config-error/src.js b/packages/babel-core/test/fixtures/config/js-config-error/src.js deleted file mode 100644 index 8b1a393741..0000000000 --- a/packages/babel-core/test/fixtures/config/js-config-error/src.js +++ /dev/null @@ -1 +0,0 @@ -// empty diff --git a/packages/babel-core/test/fixtures/config/js-config-error2/.babelrc.js b/packages/babel-core/test/fixtures/config/js-config-error2/.babelrc.js deleted file mode 100644 index 9dc5fc1e4a..0000000000 --- a/packages/babel-core/test/fixtures/config/js-config-error2/.babelrc.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = ''; diff --git a/packages/babel-core/test/fixtures/config/js-config-error2/src.js b/packages/babel-core/test/fixtures/config/js-config-error2/src.js deleted file mode 100644 index 8b1a393741..0000000000 --- a/packages/babel-core/test/fixtures/config/js-config-error2/src.js +++ /dev/null @@ -1 +0,0 @@ -// empty diff --git a/packages/babel-core/test/fixtures/config/js-config-error3/.babelrc.js b/packages/babel-core/test/fixtures/config/js-config-error3/.babelrc.js deleted file mode 100644 index b894a23a24..0000000000 --- a/packages/babel-core/test/fixtures/config/js-config-error3/.babelrc.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = null; diff --git a/packages/babel-core/test/fixtures/config/js-config-error3/src.js b/packages/babel-core/test/fixtures/config/js-config-error3/src.js deleted file mode 100644 index 8b1a393741..0000000000 --- a/packages/babel-core/test/fixtures/config/js-config-error3/src.js +++ /dev/null @@ -1 +0,0 @@ -// empty diff --git a/packages/babel-core/test/fixtures/config/js-config-extended/.babelrc.js b/packages/babel-core/test/fixtures/config/js-config-extended/.babelrc.js deleted file mode 100644 index 05741c6ef8..0000000000 --- a/packages/babel-core/test/fixtures/config/js-config-extended/.babelrc.js +++ /dev/null @@ -1,6 +0,0 @@ -var plugins = ["foo", "bar"]; - -module.exports = { - extends: "../extended.babelrc.json", - plugins: plugins -} diff --git a/packages/babel-core/test/fixtures/config/js-config-extended/src.js b/packages/babel-core/test/fixtures/config/js-config-extended/src.js deleted file mode 100644 index 8b1a393741..0000000000 --- a/packages/babel-core/test/fixtures/config/js-config-extended/src.js +++ /dev/null @@ -1 +0,0 @@ -// empty diff --git a/packages/babel-core/test/fixtures/config/js-config-function/.babelrc.js b/packages/babel-core/test/fixtures/config/js-config-function/.babelrc.js deleted file mode 100644 index 73ace51a11..0000000000 --- a/packages/babel-core/test/fixtures/config/js-config-function/.babelrc.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = function(api) { - api.cache(true); - - return { - compact: true, - }; -}; diff --git a/packages/babel-core/test/fixtures/config/js-config/.babelrc.js b/packages/babel-core/test/fixtures/config/js-config/.babelrc.js deleted file mode 100644 index e6fa0742df..0000000000 --- a/packages/babel-core/test/fixtures/config/js-config/.babelrc.js +++ /dev/null @@ -1,5 +0,0 @@ -var plugins = ["foo", "bar"]; - -module.exports = { - plugins: plugins -} diff --git a/packages/babel-core/test/fixtures/config/js-config/src.js b/packages/babel-core/test/fixtures/config/js-config/src.js deleted file mode 100644 index 8b1a393741..0000000000 --- a/packages/babel-core/test/fixtures/config/js-config/src.js +++ /dev/null @@ -1 +0,0 @@ -// empty diff --git a/packages/babel-core/test/fixtures/config/js-json-config/.babelrc b/packages/babel-core/test/fixtures/config/js-json-config/.babelrc deleted file mode 100644 index c80e833d70..0000000000 --- a/packages/babel-core/test/fixtures/config/js-json-config/.babelrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "plugins": [ - "json" - ] -} diff --git a/packages/babel-core/test/fixtures/config/js-json-config/.babelrc.js b/packages/babel-core/test/fixtures/config/js-json-config/.babelrc.js deleted file mode 100644 index 71bb3e5762..0000000000 --- a/packages/babel-core/test/fixtures/config/js-json-config/.babelrc.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - plugins: [ - "js" - ] -} diff --git a/packages/babel-core/test/fixtures/config/js-json-config/src.js b/packages/babel-core/test/fixtures/config/js-json-config/src.js deleted file mode 100644 index 8b1a393741..0000000000 --- a/packages/babel-core/test/fixtures/config/js-json-config/src.js +++ /dev/null @@ -1 +0,0 @@ -// empty diff --git a/packages/babel-core/test/fixtures/config/js-pkg-config/.babelrc.js b/packages/babel-core/test/fixtures/config/js-pkg-config/.babelrc.js deleted file mode 100644 index 71bb3e5762..0000000000 --- a/packages/babel-core/test/fixtures/config/js-pkg-config/.babelrc.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - plugins: [ - "js" - ] -} diff --git a/packages/babel-core/test/fixtures/config/js-pkg-config/src.js b/packages/babel-core/test/fixtures/config/js-pkg-config/src.js deleted file mode 100644 index 8b1a393741..0000000000 --- a/packages/babel-core/test/fixtures/config/js-pkg-config/src.js +++ /dev/null @@ -1 +0,0 @@ -// empty diff --git a/packages/babel-core/test/fixtures/config/json-config-error/.babelrc b/packages/babel-core/test/fixtures/config/json-config-error/.babelrc deleted file mode 100644 index a07fde17a3..0000000000 --- a/packages/babel-core/test/fixtures/config/json-config-error/.babelrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "bad: "json" -} diff --git a/packages/babel-core/test/fixtures/config/json-config-error/src.js b/packages/babel-core/test/fixtures/config/json-config-error/src.js deleted file mode 100644 index 8b1a393741..0000000000 --- a/packages/babel-core/test/fixtures/config/json-config-error/src.js +++ /dev/null @@ -1 +0,0 @@ -// empty diff --git a/packages/babel-core/test/fixtures/config/json-pkg-config-no-babel/.babelrc b/packages/babel-core/test/fixtures/config/json-pkg-config-no-babel/.babelrc deleted file mode 100644 index c80e833d70..0000000000 --- a/packages/babel-core/test/fixtures/config/json-pkg-config-no-babel/.babelrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "plugins": [ - "json" - ] -} diff --git a/packages/babel-core/test/fixtures/config/json-pkg-config-no-babel/src.js b/packages/babel-core/test/fixtures/config/json-pkg-config-no-babel/src.js deleted file mode 100644 index 8b1a393741..0000000000 --- a/packages/babel-core/test/fixtures/config/json-pkg-config-no-babel/src.js +++ /dev/null @@ -1 +0,0 @@ -// empty diff --git a/packages/babel-core/test/fixtures/config/json-pkg-config/.babelrc b/packages/babel-core/test/fixtures/config/json-pkg-config/.babelrc deleted file mode 100644 index c80e833d70..0000000000 --- a/packages/babel-core/test/fixtures/config/json-pkg-config/.babelrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "plugins": [ - "json" - ] -} diff --git a/packages/babel-core/test/fixtures/config/json-pkg-config/src.js b/packages/babel-core/test/fixtures/config/json-pkg-config/src.js deleted file mode 100644 index 8b1a393741..0000000000 --- a/packages/babel-core/test/fixtures/config/json-pkg-config/src.js +++ /dev/null @@ -1 +0,0 @@ -// empty diff --git a/packages/babel-core/test/fixtures/config/pkg/.babelignore b/packages/babel-core/test/fixtures/config/pkg/.babelignore deleted file mode 100644 index 902ca293de..0000000000 --- a/packages/babel-core/test/fixtures/config/pkg/.babelignore +++ /dev/null @@ -1 +0,0 @@ -pkg-ignore diff --git a/packages/babel-core/test/fixtures/config/pkg/package.json b/packages/babel-core/test/fixtures/config/pkg/package.json deleted file mode 100644 index 94fdf25db6..0000000000 --- a/packages/babel-core/test/fixtures/config/pkg/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "application-name", - "version": "0.0.1", - "babel": { - "plugins": ["pkg-plugin"] - } -} diff --git a/packages/babel-core/test/fixtures/config/pkg/src.js b/packages/babel-core/test/fixtures/config/pkg/src.js deleted file mode 100644 index 8b1a393741..0000000000 --- a/packages/babel-core/test/fixtures/config/pkg/src.js +++ /dev/null @@ -1 +0,0 @@ -// empty