mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-01 12:31:37 +00:00
Moved TypeScriptTests to python script (#7411)
* Moved TypeScriptTests to python script * fixed CI issue with out-dated generated file * Build flatc for TS CI * reverting yarn.lock
This commit is contained in:
5
.github/workflows/build.yml
vendored
5
.github/workflows/build.yml
vendored
@@ -315,11 +315,14 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
- name: flatc
|
||||||
|
# FIXME: make test script not rely on flatc
|
||||||
|
run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF . && make -j
|
||||||
- name: compile
|
- name: compile
|
||||||
run: npm run compile
|
run: npm run compile
|
||||||
- name: test
|
- name: test
|
||||||
working-directory: tests
|
working-directory: tests
|
||||||
run: sh TypeScriptTest.sh
|
run: python3 TypeScriptTest.py
|
||||||
|
|
||||||
build-dart:
|
build-dart:
|
||||||
name: Build Dart
|
name: Build Dart
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ https://www.npmjs.com/package/flatbuffers.
|
|||||||
|
|
||||||
## Testing the FlatBuffers TypeScript library
|
## Testing the FlatBuffers TypeScript library
|
||||||
|
|
||||||
To run the tests, use the [TypeScriptTest.sh](https://github.com/google/
|
To run the tests, use the [TypeScriptTest.py](https://github.com/google/
|
||||||
flatbuffers/blob/master/tests/TypeScriptTest.sh) shell script.
|
flatbuffers/blob/master/tests/TypeScriptTest.py) Python3 script.
|
||||||
|
|
||||||
*Note: The TypeScript test file requires [Node.js](https://nodejs.org/en/).*
|
*Note: The TypeScript test file requires [Node.js](https://nodejs.org/en/).*
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
"test": "tests"
|
"test": "tests"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "npm run compile && cd tests && ./TypeScriptTest.sh",
|
"test": "npm run compile && cd tests && python3 ./TypeScriptTest.py",
|
||||||
"compile": "tsc && tsc -p tsconfig.mjs.json",
|
"compile": "tsc && tsc -p tsconfig.mjs.json",
|
||||||
"prepublishOnly": "npm install --only=dev && npm run compile"
|
"prepublishOnly": "npm install --only=dev && npm run compile"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ sh PythonTest.sh
|
|||||||
|
|
||||||
echo "************************ TypeScript:"
|
echo "************************ TypeScript:"
|
||||||
|
|
||||||
sh TypeScriptTest.sh
|
python3 TypeScriptTest.py
|
||||||
|
|
||||||
echo "************************ C++:"
|
echo "************************ C++:"
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
npm install
|
|
||||||
../flatc.exe --ts --gen-name-strings --gen-mutable --gen-object-api -I include_test monster_test.fbs
|
|
||||||
../flatc.exe --gen-object-api -b -I include_test monster_test.fbs unicode_test.json
|
|
||||||
../flatc.exe --ts --gen-name-strings --gen-mutable --gen-object-api -o union_vector union_vector/union_vector.fbs
|
|
||||||
../flatc.exe --ts --gen-name-strings optional_scalars.fbs
|
|
||||||
tsc
|
|
||||||
node -r esm JavaScriptTest
|
|
||||||
node -r esm JavaScriptUnionVectorTest
|
|
||||||
node -r esm JavaScriptFlexBuffersTest
|
|
||||||
124
tests/TypeScriptTest.py
Normal file
124
tests/TypeScriptTest.py
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
#
|
||||||
|
# Copyright 2022 Google Inc. All rights reserved.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import filecmp
|
||||||
|
import glob
|
||||||
|
import platform
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
# Get the path where this script is located so we can invoke the script from
|
||||||
|
# any directory and have the paths work correctly.
|
||||||
|
tests_path = Path(__file__).parent.resolve()
|
||||||
|
|
||||||
|
# Get the root path as an absolute path, so all derived paths are absolute.
|
||||||
|
root_path = tests_path.parent.absolute()
|
||||||
|
|
||||||
|
# Get the location of the flatc executable
|
||||||
|
flatc_exe = Path("flatc" if not platform.system() == "Windows" else "flatc.exe")
|
||||||
|
|
||||||
|
# Find and assert flatc compiler is present.
|
||||||
|
if root_path in flatc_exe.parents:
|
||||||
|
flatc_exe = flatc_exe.relative_to(root_path)
|
||||||
|
flatc_path = Path(root_path, flatc_exe)
|
||||||
|
assert flatc_path.exists(), "Cannot find the flatc compiler " + str(flatc_path)
|
||||||
|
|
||||||
|
# Execute the flatc compiler with the specified parameters
|
||||||
|
def flatc(options, schema, prefix=None, include=None, data=None, cwd=tests_path):
|
||||||
|
cmd = [str(flatc_path)] + options
|
||||||
|
if prefix:
|
||||||
|
cmd += ["-o"] + [prefix]
|
||||||
|
if include:
|
||||||
|
cmd += ["-I"] + [include]
|
||||||
|
cmd += [schema] if isinstance(schema, str) else schema
|
||||||
|
if data:
|
||||||
|
cmd += [data] if isinstance(data, str) else data
|
||||||
|
result = subprocess.run(cmd, cwd=str(cwd), check=True)
|
||||||
|
|
||||||
|
|
||||||
|
print("Removing node_modules/ directory...")
|
||||||
|
shutil.rmtree(Path(tests_path, "node_modules"), ignore_errors=True)
|
||||||
|
|
||||||
|
assert subprocess.run(["npm", "install", "--silent"], cwd=str(tests_path), shell=True)
|
||||||
|
|
||||||
|
print("Invoking flatc...")
|
||||||
|
flatc(
|
||||||
|
options=["--ts", "--gen-name-strings", "--gen-mutable", "--gen-object-api"],
|
||||||
|
schema="monster_test.fbs",
|
||||||
|
include="include_test",
|
||||||
|
)
|
||||||
|
|
||||||
|
flatc(
|
||||||
|
options=["--gen-object-api", "-b"],
|
||||||
|
schema="monster_test.fbs",
|
||||||
|
include="include_test",
|
||||||
|
data="unicode_test.json",
|
||||||
|
)
|
||||||
|
|
||||||
|
flatc(
|
||||||
|
options=["--ts", "--gen-name-strings", "--gen-mutable", "--gen-object-api"],
|
||||||
|
schema="union_vector/union_vector.fbs",
|
||||||
|
prefix="union_vector",
|
||||||
|
)
|
||||||
|
|
||||||
|
flatc(
|
||||||
|
options=["--ts", "--gen-name-strings"],
|
||||||
|
schema="optional_scalars.fbs",
|
||||||
|
)
|
||||||
|
|
||||||
|
flatc(
|
||||||
|
options=["--ts", "--gen-name-strings", "--gen-mutable", "--gen-object-api"],
|
||||||
|
schema=[
|
||||||
|
"typescript_keywords.fbs",
|
||||||
|
"test_dir/typescript_include.fbs",
|
||||||
|
"test_dir/typescript_transitive_include.fbs",
|
||||||
|
"../reflection/reflection.fbs",
|
||||||
|
],
|
||||||
|
include="../",
|
||||||
|
)
|
||||||
|
|
||||||
|
flatc(
|
||||||
|
options=[
|
||||||
|
"--ts",
|
||||||
|
"--gen-name-strings",
|
||||||
|
"--gen-mutable",
|
||||||
|
"--gen-object-api",
|
||||||
|
"--ts-flat-files",
|
||||||
|
],
|
||||||
|
schema=[
|
||||||
|
"typescript_keywords.fbs",
|
||||||
|
"test_dir/typescript_include.fbs",
|
||||||
|
"test_dir/typescript_transitive_include.fbs",
|
||||||
|
"../reflection/reflection.fbs",
|
||||||
|
],
|
||||||
|
include="../",
|
||||||
|
)
|
||||||
|
|
||||||
|
print("Running TypeScript Compiler...")
|
||||||
|
assert subprocess.run(["tsc"], cwd=str(tests_path), shell=True)
|
||||||
|
|
||||||
|
NODE_CMD = ["node", "-r", "esm"]
|
||||||
|
|
||||||
|
print("Running TypeScript Tests...")
|
||||||
|
assert subprocess.run(NODE_CMD + ["JavaScriptTest"], cwd=str(tests_path), shell=True)
|
||||||
|
assert subprocess.run(
|
||||||
|
NODE_CMD + ["JavaScriptUnionVectorTest"], cwd=str(tests_path), shell=True
|
||||||
|
)
|
||||||
|
assert subprocess.run(
|
||||||
|
NODE_CMD + ["JavaScriptFlexBuffersTest"], cwd=str(tests_path), shell=True
|
||||||
|
)
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
#
|
|
||||||
# Copyright 2016 Google Inc. All rights reserved.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# clean node_modules to make sure we depend on latest local flatbuffers at ../
|
|
||||||
rm -rf node_modules
|
|
||||||
npm install
|
|
||||||
|
|
||||||
if [ -x ../flatc ]; then
|
|
||||||
../flatc --ts --gen-name-strings --gen-mutable --gen-object-api -I include_test monster_test.fbs
|
|
||||||
../flatc --gen-object-api -b -I include_test monster_test.fbs unicode_test.json
|
|
||||||
../flatc --ts --gen-name-strings --gen-mutable --gen-object-api -o union_vector union_vector/union_vector.fbs
|
|
||||||
../flatc --ts --gen-name-strings optional_scalars.fbs
|
|
||||||
../flatc --ts --gen-name-strings --gen-object-api --gen-mutable -I ../ ./typescript_keywords.fbs test_dir/typescript_include.fbs test_dir/typescript_transitive_include.fbs ../reflection/reflection.fbs
|
|
||||||
../flatc --ts --gen-name-strings --gen-object-api --gen-mutable --ts-flat-files -I ../ ./typescript_keywords.fbs test_dir/typescript_include.fbs test_dir/typescript_transitive_include.fbs ../reflection/reflection.fbs
|
|
||||||
fi
|
|
||||||
tsc
|
|
||||||
node -r esm JavaScriptTest
|
|
||||||
node -r esm JavaScriptUnionVectorTest
|
|
||||||
node -r esm JavaScriptFlexBuffersTest
|
|
||||||
@@ -9,6 +9,7 @@ export { Race } from './my-game/example/race';
|
|||||||
export { Referrable, ReferrableT } from './my-game/example/referrable';
|
export { Referrable, ReferrableT } from './my-game/example/referrable';
|
||||||
export { Stat, StatT } from './my-game/example/stat';
|
export { Stat, StatT } from './my-game/example/stat';
|
||||||
export { StructOfStructs, StructOfStructsT } from './my-game/example/struct-of-structs';
|
export { StructOfStructs, StructOfStructsT } from './my-game/example/struct-of-structs';
|
||||||
|
export { StructOfStructsOfStructs, StructOfStructsOfStructsT } from './my-game/example/struct-of-structs-of-structs';
|
||||||
export { Test, TestT } from './my-game/example/test';
|
export { Test, TestT } from './my-game/example/test';
|
||||||
export { TestSimpleTableWithEnum, TestSimpleTableWithEnumT } from './my-game/example/test-simple-table-with-enum';
|
export { TestSimpleTableWithEnum, TestSimpleTableWithEnumT } from './my-game/example/test-simple-table-with-enum';
|
||||||
export { TypeAliases, TypeAliasesT } from './my-game/example/type-aliases';
|
export { TypeAliases, TypeAliasesT } from './my-game/example/type-aliases';
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ export class StructOfStructsT {
|
|||||||
this.c = c;
|
this.c = c;
|
||||||
}
|
}
|
||||||
pack(builder) {
|
pack(builder) {
|
||||||
return StructOfStructs.createStructOfStructs(builder, (this.a === null ? 0 : this.a.id), (this.a === null ? 0 : this.a.distance), (this.b === null ? 0 : this.b.a), (this.b === null ? 0 : this.b.b), (this.c === null ? 0 : this.c.id), (this.c === null ? 0 : this.c.distance));
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
||||||
|
return StructOfStructs.createStructOfStructs(builder, ((_b = (_a = this.a) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : 0), ((_d = (_c = this.a) === null || _c === void 0 ? void 0 : _c.distance) !== null && _d !== void 0 ? _d : 0), ((_f = (_e = this.b) === null || _e === void 0 ? void 0 : _e.a) !== null && _f !== void 0 ? _f : 0), ((_h = (_g = this.b) === null || _g === void 0 ? void 0 : _g.b) !== null && _h !== void 0 ? _h : 0), ((_k = (_j = this.c) === null || _j === void 0 ? void 0 : _j.id) !== null && _k !== void 0 ? _k : 0), ((_m = (_l = this.c) === null || _l === void 0 ? void 0 : _l.distance) !== null && _m !== void 0 ? _m : 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ export class Vec3T {
|
|||||||
this.test3 = test3;
|
this.test3 = test3;
|
||||||
}
|
}
|
||||||
pack(builder) {
|
pack(builder) {
|
||||||
return Vec3.createVec3(builder, this.x, this.y, this.z, this.test1, this.test2, (this.test3 === null ? 0 : this.test3.a), (this.test3 === null ? 0 : this.test3.b));
|
var _a, _b, _c, _d;
|
||||||
|
return Vec3.createVec3(builder, this.x, this.y, this.z, this.test1, this.test2, ((_b = (_a = this.test3) === null || _a === void 0 ? void 0 : _a.a) !== null && _b !== void 0 ? _b : 0), ((_d = (_c = this.test3) === null || _c === void 0 ? void 0 : _c.b) !== null && _d !== void 0 ? _d : 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user