Add test to verify exported names are stable, add missing test files after earlier refactor.

This commit is contained in:
David Anson 2025-03-06 20:24:20 -08:00
parent d4a638101a
commit 5cc88a7759
6 changed files with 137 additions and 9 deletions

View file

@ -19,7 +19,7 @@ const exportMappings = new Map([
[ "./style/relaxed", "../style/relaxed.json" ]
]);
test("exportMappings", (t) => {
test("exportMappings table", (t) => {
t.deepEqual(
Object.keys(packageJson.exports),
[ ...exportMappings.keys() ]
@ -31,9 +31,10 @@ const jsonRe = /\.json$/u;
// const importOptionsJson = { "with": { "type": "json" } };
for (const [ exportName, exportPath ] of exportMappings) {
test(exportName, async(t) => {
const exportByName = exportName.replace(/^\./u, packageJson.name);
test(`export mapping for ${exportByName}`, async(t) => {
t.plan(1);
const json = jsonRe.test(exportPath);
const exportByName = exportName.replace(/^\./u, packageJson.name);
const importExportByName = json ?
require(exportByName) :
await import(exportByName);
@ -44,7 +45,22 @@ for (const [ exportName, exportPath ] of exportMappings) {
});
}
test("subpathImports", async(t) => {
test(`exported names`, async(t) => {
t.plan(1);
const exportedNames = {};
for (const [ exportName, exportPath ] of exportMappings) {
const exportByName = exportName.replace(/^\./u, packageJson.name);
const json = jsonRe.test(exportPath);
const importExportByName = json ?
require(exportByName) :
// eslint-disable-next-line no-await-in-loop
await import(exportByName);
exportedNames[exportByName] = Object.keys(importExportByName);
}
t.snapshot(exportedNames);
});
test("subpathImports and conditions", async(t) => {
t.plan(8);
const scenarios = [
{ "conditions": "browser", "throws": true },