fix browser tests
This commit is contained in:
@@ -31,7 +31,7 @@ export default class PluginManager {
|
||||
// this is a plugin in the form of "foobar" or "foobar:after"
|
||||
// where the optional colon is the delimiter for plugin position in the transformer stack
|
||||
|
||||
var match = key.match(/^(.*?):(after|before)$/);
|
||||
var match = name.match(/^(.*?):(after|before)$/);
|
||||
if (match) [, name, position] = match;
|
||||
|
||||
var loc = util.resolveRelative(name) || util.resolveRelative(`babel-plugin-${name}`);
|
||||
|
||||
@@ -43,6 +43,9 @@ export function resolve(loc: string) {
|
||||
var relativeMod;
|
||||
|
||||
export function resolveRelative(loc: string) {
|
||||
// we're in the browser, probably
|
||||
if (typeof Module === "object") return null;
|
||||
|
||||
if (!relativeMod) {
|
||||
relativeMod = new Module;
|
||||
relativeMod.paths = Module._nodeModulePaths(process.cwd());
|
||||
|
||||
@@ -25,6 +25,20 @@ suite("api", function () {
|
||||
}, /Unknown helper foob/);
|
||||
});
|
||||
|
||||
test("resolveModuleSource", function () {
|
||||
var actual = 'import foo from "foo-import-default";\nimport "foo-import-bare";\nexport { foo } from "foo-export-named";';
|
||||
var expected = 'import foo from "resolved/foo-import-default";\nimport "resolved/foo-import-bare";\nexport { foo } from "resolved/foo-export-named";';
|
||||
|
||||
actual = transform(actual, {
|
||||
blacklist: ["es6.modules", "strict"],
|
||||
resolveModuleSource: function (originalSource) {
|
||||
return "resolved/" + originalSource;
|
||||
}
|
||||
}).code.trim();
|
||||
|
||||
assert.equal(actual, expected);
|
||||
});
|
||||
|
||||
test("extra options", function () {
|
||||
var file1 = new File({ extra: { foo: "bar" } });
|
||||
assert.equal(file1.opts.extra.foo, "bar");
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
export { foo } from "foo-export-named";
|
||||
import foo from "foo-import-default";
|
||||
import "foo-import-bare";
|
||||
@@ -1,5 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
import foo from "resolved/foo-import-default";
|
||||
import "resolved/foo-import-bare";
|
||||
export { foo } from "resolved/foo-export-named";
|
||||
@@ -1,5 +0,0 @@
|
||||
exports.blacklist = ["es6.modules"];
|
||||
|
||||
exports.resolveModuleSource = function (originalSource) {
|
||||
return "resolved/" + originalSource;
|
||||
};
|
||||
Reference in New Issue
Block a user