* Lint against CJS globals in modules * Use `import.meta.url` instead of `__filename` in `src` files * Prepare fixtures runner for `import.meta.url` * Use `import.meta.url` instead of `__filename` in `test/index` files * Remove `__dirname` from remaining test files dirname * Avoid using `module` in `src` files * Avoid using `require` in `src` files * Avoid using `require` in `test` files * Update `@types/node` * Compile dynamic import in `@babel/node` * Fix windows * Use `@babel/plugin-proposal-dynamic-import` from npm
36 lines
866 B
JavaScript
36 lines
866 B
JavaScript
import * as babel from "@babel/core";
|
|
import vm from "vm";
|
|
import { fileURLToPath } from "url";
|
|
import path from "path";
|
|
|
|
import transformCommonJS from "..";
|
|
|
|
test("Re-export doesn't overwrite __esModule flag", function () {
|
|
let code = 'export * from "./dep";';
|
|
const depStub = {
|
|
__esModule: false,
|
|
};
|
|
|
|
const context = {
|
|
module: {
|
|
exports: {},
|
|
},
|
|
require: function (id) {
|
|
if (id === "./dep") return depStub;
|
|
throw new Error("Unexpected dependency: " + id);
|
|
},
|
|
};
|
|
context.exports = context.module.exports;
|
|
|
|
code = babel.transform(code, {
|
|
cwd: path.dirname(fileURLToPath(import.meta.url)),
|
|
plugins: [[transformCommonJS, { loose: true }]],
|
|
ast: false,
|
|
}).code;
|
|
|
|
vm.runInNewContext(code, context);
|
|
|
|
// exports.__esModule shouldn't be overwritten.
|
|
expect(context.exports.__esModule).toBe(true);
|
|
});
|