mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-29 21:12:00 +00:00
Add new tests to validate relative import path fix
This commit is contained in:
28
tests/ts/JavaScriptRelativeImportPathTest.js
Normal file
28
tests/ts/JavaScriptRelativeImportPathTest.js
Normal 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");
|
||||||
@@ -185,6 +185,20 @@ flatc(
|
|||||||
flatc(options=["--ts"], schema="../long_namespace.fbs")
|
flatc(options=["--ts"], schema="../long_namespace.fbs")
|
||||||
flatc(options=["--ts"], schema="../longer_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...")
|
print("Running TypeScript Compiler...")
|
||||||
check_call(["tsc"])
|
check_call(["tsc"])
|
||||||
print(
|
print(
|
||||||
@@ -201,6 +215,7 @@ check_call(NODE_CMD + ["JavaScriptUnionVectorTest"])
|
|||||||
check_call(NODE_CMD + ["JavaScriptFlexBuffersTest"])
|
check_call(NODE_CMD + ["JavaScriptFlexBuffersTest"])
|
||||||
check_call(NODE_CMD + ["JavaScriptComplexArraysTest"])
|
check_call(NODE_CMD + ["JavaScriptComplexArraysTest"])
|
||||||
check_call(NODE_CMD + ["JavaScriptUnionUnderlyingTypeTest"])
|
check_call(NODE_CMD + ["JavaScriptUnionUnderlyingTypeTest"])
|
||||||
|
check_call(NODE_CMD + ["JavaScriptRelativeImportPathTest"])
|
||||||
|
|
||||||
print("Running old v1 TypeScript Tests...")
|
print("Running old v1 TypeScript Tests...")
|
||||||
check_call(NODE_CMD + ["JavaScriptTestv1.cjs", "./monster_test_generated.cjs"])
|
check_call(NODE_CMD + ["JavaScriptTestv1.cjs", "./monster_test_generated.cjs"])
|
||||||
|
|||||||
20
tests/ts/relative_imports/relative_imports.fbs
Normal file
20
tests/ts/relative_imports/relative_imports.fbs
Normal 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;
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "ES2020",
|
"target": "ES2020",
|
||||||
"lib": ["ES2020", "DOM"],
|
"lib": [
|
||||||
|
"ES2020",
|
||||||
|
"DOM"
|
||||||
|
],
|
||||||
"module": "NodeNext",
|
"module": "NodeNext",
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"strict": true
|
"strict": true
|
||||||
@@ -17,6 +20,7 @@
|
|||||||
"arrays_test_complex/**/*.ts",
|
"arrays_test_complex/**/*.ts",
|
||||||
"union_underlying_type_test.ts",
|
"union_underlying_type_test.ts",
|
||||||
"long-namespace/**/*.ts",
|
"long-namespace/**/*.ts",
|
||||||
"longer-namespace/**/*.ts"
|
"longer-namespace/**/*.ts",
|
||||||
|
"relative_imports/**/*.ts"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user