123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345 |
- import * as babel from "../lib/index";
- import path from "path";
- describe("addon resolution", function() {
- const base = path.join(__dirname, "fixtures", "resolution");
- let cwd;
- beforeEach(function() {
- cwd = process.cwd();
- process.chdir(base);
- });
- afterEach(function() {
- process.chdir(cwd);
- });
- it("should find module: presets", function() {
- process.chdir("module-paths");
- babel.transform("", {
- filename: "filename.js",
- babelrc: false,
- presets: ["module:preset"],
- });
- });
- it("should find module: plugins", function() {
- process.chdir("module-paths");
- babel.transform("", {
- filename: "filename.js",
- babelrc: false,
- plugins: ["module:plugin"],
- });
- });
- it("should find standard presets", function() {
- process.chdir("standard-paths");
- babel.transform("", {
- filename: "filename.js",
- babelrc: false,
- presets: ["mod"],
- });
- });
- it("should find standard plugins", function() {
- process.chdir("standard-paths");
- babel.transform("", {
- filename: "filename.js",
- babelrc: false,
- plugins: ["mod"],
- });
- });
- it("should find standard presets with an existing prefix", function() {
- process.chdir("standard-paths");
- babel.transform("", {
- filename: "filename.js",
- babelrc: false,
- presets: ["babel-preset-mod"],
- });
- });
- it("should find standard plugins with an existing prefix", function() {
- process.chdir("standard-paths");
- babel.transform("", {
- filename: "filename.js",
- babelrc: false,
- plugins: ["babel-plugin-mod"],
- });
- });
- it("should find @babel scoped presets", function() {
- process.chdir("babel-org-paths");
- babel.transform("", {
- filename: "filename.js",
- babelrc: false,
- presets: ["@babel/foo"],
- });
- });
- it("should find @babel scoped plugins", function() {
- process.chdir("babel-org-paths");
- babel.transform("", {
- filename: "filename.js",
- babelrc: false,
- plugins: ["@babel/foo"],
- });
- });
- it("should find @babel scoped presets with an existing prefix", function() {
- process.chdir("babel-org-paths");
- babel.transform("", {
- filename: "filename.js",
- babelrc: false,
- presets: ["@babel/preset-foo"],
- });
- });
- it("should find @babel scoped plugins", function() {
- process.chdir("babel-org-paths");
- babel.transform("", {
- filename: "filename.js",
- babelrc: false,
- plugins: ["@babel/plugin-foo"],
- });
- });
- it("should find @foo scoped presets", function() {
- process.chdir("foo-org-paths");
- babel.transform("", {
- filename: "filename.js",
- babelrc: false,
- presets: ["@foo/mod"],
- });
- });
- it("should find @foo scoped plugins", function() {
- process.chdir("foo-org-paths");
- babel.transform("", {
- filename: "filename.js",
- babelrc: false,
- plugins: ["@foo/mod"],
- });
- });
- it("should find @foo scoped presets with an existing prefix", function() {
- process.chdir("foo-org-paths");
- babel.transform("", {
- filename: "filename.js",
- babelrc: false,
- presets: ["@foo/babel-preset-mod"],
- });
- });
- it("should find @foo scoped plugins with an existing prefix", function() {
- process.chdir("foo-org-paths");
- babel.transform("", {
- filename: "filename.js",
- babelrc: false,
- plugins: ["@foo/babel-plugin-mod"],
- });
- });
- it("should find relative path presets", function() {
- process.chdir("relative-paths");
- babel.transform("", {
- filename: "filename.js",
- babelrc: false,
- presets: ["./dir/preset.js"],
- });
- });
- it("should find relative path plugins", function() {
- process.chdir("relative-paths");
- babel.transform("", {
- filename: "filename.js",
- babelrc: false,
- plugins: ["./dir/plugin.js"],
- });
- });
- it("should find module file presets", function() {
- process.chdir("nested-module-paths");
- babel.transform("", {
- filename: "filename.js",
- babelrc: false,
- presets: ["mod/preset"],
- });
- });
- it("should find module file plugins", function() {
- process.chdir("nested-module-paths");
- babel.transform("", {
- filename: "filename.js",
- babelrc: false,
- plugins: ["mod/plugin"],
- });
- });
- it("should find @foo scoped module file presets", function() {
- process.chdir("scoped-nested-module-paths");
- babel.transform("", {
- filename: "filename.js",
- babelrc: false,
- presets: ["@foo/mod/preset"],
- });
- });
- it("should find @foo scoped module file plugins", function() {
- process.chdir("scoped-nested-module-paths");
- babel.transform("", {
- filename: "filename.js",
- babelrc: false,
- plugins: ["@foo/mod/plugin"],
- });
- });
- it("should find @babel scoped module file presets", function() {
- process.chdir("babel-scoped-nested-module-paths");
- babel.transform("", {
- filename: "filename.js",
- babelrc: false,
- presets: ["@babel/mod/preset"],
- });
- });
- it("should find @babel scoped module file plugins", function() {
- process.chdir("babel-scoped-nested-module-paths");
- babel.transform("", {
- filename: "filename.js",
- babelrc: false,
- plugins: ["@babel/mod/plugin"],
- });
- });
- it("should throw about module: usage for presets", function() {
- process.chdir("throw-module-paths");
- expect(() => {
- babel.transform("", {
- filename: "filename.js",
- babelrc: false,
- presets: ["foo"],
- });
- }).toThrow(
- /Cannot find module 'babel-preset-foo'.*\n- If you want to resolve "foo", use "module:foo"/,
- );
- });
- it("should throw about module: usage for plugins", function() {
- process.chdir("throw-module-paths");
- expect(() => {
- babel.transform("", {
- filename: "filename.js",
- babelrc: false,
- plugins: ["foo"],
- });
- }).toThrow(
- /Cannot find module 'babel-plugin-foo'.*\n- If you want to resolve "foo", use "module:foo"/,
- );
- });
- it("should throw about @babel usage for presets", function() {
- process.chdir("throw-babel-paths");
- expect(() => {
- babel.transform("", {
- filename: "filename.js",
- babelrc: false,
- presets: ["foo"],
- });
- }).toThrow(
- /Cannot find module 'babel-preset-foo'.*\n- Did you mean "@babel\/foo"\?/,
- );
- });
- it("should throw about @babel usage for plugins", function() {
- process.chdir("throw-babel-paths");
- expect(() => {
- babel.transform("", {
- filename: "filename.js",
- babelrc: false,
- plugins: ["foo"],
- });
- }).toThrow(
- /Cannot find module 'babel-plugin-foo'.*\n- Did you mean "@babel\/foo"\?/,
- );
- });
- it("should throw about passing a preset as a plugin", function() {
- process.chdir("throw-opposite-paths");
- expect(() => {
- babel.transform("", {
- filename: "filename.js",
- babelrc: false,
- presets: ["testplugin"],
- });
- }).toThrow(
- /Cannot find module 'babel-preset-testplugin'.*\n- Did you accidentally pass a preset as a plugin\?/,
- );
- });
- it("should throw about passing a plugin as a preset", function() {
- process.chdir("throw-opposite-paths");
- expect(() => {
- babel.transform("", {
- filename: "filename.js",
- babelrc: false,
- plugins: ["testpreset"],
- });
- }).toThrow(
- /Cannot find module 'babel-plugin-testpreset'.*\n- Did you accidentally pass a plugin as a preset\?/,
- );
- });
- it("should throw about missing presets", function() {
- process.chdir("throw-missing-paths");
- expect(() => {
- babel.transform("", {
- filename: "filename.js",
- babelrc: false,
- presets: ["foo"],
- });
- }).toThrow(/Cannot find module 'babel-preset-foo'/);
- });
- it("should throw about missing plugins", function() {
- process.chdir("throw-missing-paths");
- expect(() => {
- babel.transform("", {
- filename: "filename.js",
- babelrc: false,
- plugins: ["foo"],
- });
- }).toThrow(/Cannot find module 'babel-plugin-foo'/);
- });
- });
|