Update export test to avoid "ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time".

This commit is contained in:
David Anson 2024-12-24 00:15:19 +00:00
parent 8e5f699bb2
commit df33933fe5

View file

@ -1388,15 +1388,20 @@ test("exportMappings", (t) => {
}); });
const jsonRe = /\.json$/u; const jsonRe = /\.json$/u;
const importOptionsJson = { "with": { "type": "json" } }; // ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
// const importOptionsJson = { "with": { "type": "json" } };
for (const [ exportName, exportPath ] of exportMappings) { for (const [ exportName, exportPath ] of exportMappings) {
test(exportName, async(t) => { test(exportName, async(t) => {
const json = jsonRe.test(exportPath); const json = jsonRe.test(exportPath);
const importOptions = json ? importOptionsJson : undefined; const exportByName = exportName.replace(/^\./u, packageJson.name);
const importExportName = await import(exportName.replace(/^\./u, packageJson.name), importOptions); const importExportByName = json ?
const importExportPath = await import(exportPath, importOptions); require(exportByName) :
t.is(importExportName, importExportPath); await import(exportByName);
const importExportByPath = json ?
require(exportPath) :
await import(exportPath);
t.is(importExportByName, importExportByPath);
}); });
} }