Files
Huáng JùnliàngandGitHub 254525d565 Enforce node protocol import (#17207)
* enable prefer-node-protocol rule

* prefer node protocol import

* fix broken scripts

* fix e2e-old-babel error

* strip node: protocol for old node versions

* update Makefile.mjs
2025-03-31 10:49:22 -04:00

36 lines
898 B
JavaScript

import * as babel from "@babel/core";
import vm from "node:vm";
import { fileURLToPath } from "node:url";
import path from "node:path";
import transformCommonJS from "../lib/index.js";
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.transformSync(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);
});