Add new tests to validate relative import path fix

This commit is contained in:
Austin Chick
2025-12-22 08:18:43 -06:00
parent 0dc7ab69ec
commit 03e5dab416
4 changed files with 70 additions and 3 deletions

View File

@@ -0,0 +1,28 @@
import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { dirname, resolve } from "node:path";
const here = dirname(fileURLToPath(import.meta.url));
const headerPath = resolve(here, "relative_imports/transit/three/header.ts");
const contents = readFileSync(headerPath, "utf8");
const expectedImports = [
"from '../one/info.js';",
"from '../two/identity.js';",
];
for (const expected of expectedImports) {
if (!contents.includes(expected)) {
throw new Error(`Missing relative import "${expected}" in ${headerPath}`);
}
}
const forbidden = "../transit/";
if (contents.includes(forbidden)) {
throw new Error(
`Found unexpected namespace segment in import path within ${headerPath}`
);
}
console.log("JavaScriptRelativeImportPathTest: OK");

View File

@@ -185,6 +185,20 @@ flatc(
flatc(options=["--ts"], schema="../long_namespace.fbs")
flatc(options=["--ts"], schema="../longer_namespace.fbs")
flatc(
options=[
"--ts",
"--reflect-names",
"--gen-name-strings",
"--gen-object-api",
"--ts-entry-points",
"--ts-flat-files",
],
schema="relative_imports/relative_imports.fbs",
prefix="relative_imports",
)
print("Running TypeScript Compiler...")
check_call(["tsc"])
print(
@@ -201,6 +215,7 @@ check_call(NODE_CMD + ["JavaScriptUnionVectorTest"])
check_call(NODE_CMD + ["JavaScriptFlexBuffersTest"])
check_call(NODE_CMD + ["JavaScriptComplexArraysTest"])
check_call(NODE_CMD + ["JavaScriptUnionUnderlyingTypeTest"])
check_call(NODE_CMD + ["JavaScriptRelativeImportPathTest"])
print("Running old v1 TypeScript Tests...")
check_call(NODE_CMD + ["JavaScriptTestv1.cjs", "./monster_test_generated.cjs"])

View File

@@ -0,0 +1,20 @@
namespace Transit.One;
table Info {
timestamp:ulong;
}
namespace Transit.Two;
table Identity {
id:uint;
}
namespace Transit.Three;
table Header {
info:Transit.One.Info;
id:Transit.Two.Identity;
}
root_type Header;

View File

@@ -1,7 +1,10 @@
{
"compilerOptions": {
"target": "ES2020",
"lib": ["ES2020", "DOM"],
"lib": [
"ES2020",
"DOM"
],
"module": "NodeNext",
"declaration": true,
"strict": true
@@ -17,6 +20,7 @@
"arrays_test_complex/**/*.ts",
"union_underlying_type_test.ts",
"long-namespace/**/*.ts",
"longer-namespace/**/*.ts"
"longer-namespace/**/*.ts",
"relative_imports/**/*.ts"
]
}
}