From aef7a9a9f1866be14745c35884830df36559d7c4 Mon Sep 17 00:00:00 2001 From: Endel Dreyer Date: Wed, 13 Sep 2023 11:10:16 -0300 Subject: [PATCH] rename test files --- package.json | 2 +- ...ArraySchemaTest.ts => ArraySchema.test.ts} | 0 ...=> BackwardsForwardsCompatibility.test.ts} | 0 test/{BenchmarkTest.ts => Benchmark.test.ts} | 0 test/{ChangeAPITest.ts => ChangeAPI.test.ts} | 0 .../{ChangeTreeTest.ts => ChangeTree.test.ts} | 0 ...SchemaTest.ts => CollectionSchema.test.ts} | 0 test/CommunityCases.test.ts | 28 +++++++++++++++++++ ...atibilityTest.ts => Compatibility.test.ts} | 0 .../{DefinitionTest.ts => Definition.test.ts} | 0 test/{EdgeCasesTest.ts => EdgeCases.test.ts} | 0 test/{FilterTest.ts => Filter.test.ts} | 0 ...SharingTest.ts => InstanceSharing.test.ts} | 0 test/{MapSchemaTest.ts => MapSchema.test.ts} | 0 ...IterationTest.ts => NextIteration.test.ts} | 0 ...PerformanceTest.ts => Performance.test.ts} | 0 ...lymorphismTest.ts => Polymorphism.test.ts} | 0 .../{ReflectionTest.ts => Reflection.test.ts} | 0 test/{SchemaTest.ts => Schema.test.ts} | 0 test/{SetSchemaTest.ts => SetSchema.test.ts} | 0 test/{SpecTest.ts => Spec.test.ts} | 0 test/TypeScriptTypes.test.ts | 21 ++++++++++++++ test/{UtilsTest.ts => Utils.test.ts} | 0 .../{CodegenTest.ts => Codegen.test.ts} | 0 24 files changed, 50 insertions(+), 1 deletion(-) rename test/{ArraySchemaTest.ts => ArraySchema.test.ts} (100%) rename test/{BackwardsForwardsCompatibilityTest.ts => BackwardsForwardsCompatibility.test.ts} (100%) rename test/{BenchmarkTest.ts => Benchmark.test.ts} (100%) rename test/{ChangeAPITest.ts => ChangeAPI.test.ts} (100%) rename test/{ChangeTreeTest.ts => ChangeTree.test.ts} (100%) rename test/{CollectionSchemaTest.ts => CollectionSchema.test.ts} (100%) create mode 100644 test/CommunityCases.test.ts rename test/{CompatibilityTest.ts => Compatibility.test.ts} (100%) rename test/{DefinitionTest.ts => Definition.test.ts} (100%) rename test/{EdgeCasesTest.ts => EdgeCases.test.ts} (100%) rename test/{FilterTest.ts => Filter.test.ts} (100%) rename test/{InstanceSharingTest.ts => InstanceSharing.test.ts} (100%) rename test/{MapSchemaTest.ts => MapSchema.test.ts} (100%) rename test/{NextIterationTest.ts => NextIteration.test.ts} (100%) rename test/{PerformanceTest.ts => Performance.test.ts} (100%) rename test/{PolymorphismTest.ts => Polymorphism.test.ts} (100%) rename test/{ReflectionTest.ts => Reflection.test.ts} (100%) rename test/{SchemaTest.ts => Schema.test.ts} (100%) rename test/{SetSchemaTest.ts => SetSchema.test.ts} (100%) rename test/{SpecTest.ts => Spec.test.ts} (100%) create mode 100644 test/TypeScriptTypes.test.ts rename test/{UtilsTest.ts => Utils.test.ts} (100%) rename test/codegen/{CodegenTest.ts => Codegen.test.ts} (100%) diff --git a/package.json b/package.json index 397bc526..8b0c2334 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "scripts": { "build": "tsc && rollup -c rollup.config.js", "watch": "tsc -w", - "test": "mocha --require ts-node/register test/*Test.ts test/**/*Test.ts", + "test": "mocha --require ts-node/register test/*.test.ts test/**/*.test.ts", "coverage": "nyc mocha --require ts-node/register --require source-map-support/register --recursive test/**Test.ts", "generate-test-1": "bin/schema-codegen test-external/PrimitiveTypes.ts --namespace SchemaTest.PrimitiveTypes --output ../colyseus-unity-sdk/Assets/Editor/ColyseusTests/Schema/PrimitiveTypes", "generate-test-2": "bin/schema-codegen test-external/ChildSchemaTypes.ts --namespace SchemaTest.ChildSchemaTypes --output ../colyseus-unity-sdk/Assets/Editor/ColyseusTests/Schema/ChildSchemaTypes", diff --git a/test/ArraySchemaTest.ts b/test/ArraySchema.test.ts similarity index 100% rename from test/ArraySchemaTest.ts rename to test/ArraySchema.test.ts diff --git a/test/BackwardsForwardsCompatibilityTest.ts b/test/BackwardsForwardsCompatibility.test.ts similarity index 100% rename from test/BackwardsForwardsCompatibilityTest.ts rename to test/BackwardsForwardsCompatibility.test.ts diff --git a/test/BenchmarkTest.ts b/test/Benchmark.test.ts similarity index 100% rename from test/BenchmarkTest.ts rename to test/Benchmark.test.ts diff --git a/test/ChangeAPITest.ts b/test/ChangeAPI.test.ts similarity index 100% rename from test/ChangeAPITest.ts rename to test/ChangeAPI.test.ts diff --git a/test/ChangeTreeTest.ts b/test/ChangeTree.test.ts similarity index 100% rename from test/ChangeTreeTest.ts rename to test/ChangeTree.test.ts diff --git a/test/CollectionSchemaTest.ts b/test/CollectionSchema.test.ts similarity index 100% rename from test/CollectionSchemaTest.ts rename to test/CollectionSchema.test.ts diff --git a/test/CommunityCases.test.ts b/test/CommunityCases.test.ts new file mode 100644 index 00000000..929acd9d --- /dev/null +++ b/test/CommunityCases.test.ts @@ -0,0 +1,28 @@ +import * as util from "util"; +import * as assert from "assert"; +import { nanoid } from "nanoid"; +import { MapSchema, Schema, type, ArraySchema, defineTypes, Reflection, Context } from "../src"; + +describe("Community cases", () => { + + xit("colyseus/schema/issues/143", () => { + class OptionalSubScheam extends Schema { + @type('number') index: number = 200; + @type('string') my_string: string = 'a good string'; + } + + class Test extends Schema { + @type('number') size: number = 0; // total number of storage slots in this container. + @type('boolean') transient?: boolean; + @type(OptionalSubScheam) sub?: OptionalSubScheam; + } + + const testobj = new Test(); + const encoded = testobj.encodeAll(false); + const handshake = Reflection.encode(testobj); + + const clientobj = Reflection.decode(handshake); + assert.strictEqual(clientobj.sub, undefined); + }); + +}); diff --git a/test/CompatibilityTest.ts b/test/Compatibility.test.ts similarity index 100% rename from test/CompatibilityTest.ts rename to test/Compatibility.test.ts diff --git a/test/DefinitionTest.ts b/test/Definition.test.ts similarity index 100% rename from test/DefinitionTest.ts rename to test/Definition.test.ts diff --git a/test/EdgeCasesTest.ts b/test/EdgeCases.test.ts similarity index 100% rename from test/EdgeCasesTest.ts rename to test/EdgeCases.test.ts diff --git a/test/FilterTest.ts b/test/Filter.test.ts similarity index 100% rename from test/FilterTest.ts rename to test/Filter.test.ts diff --git a/test/InstanceSharingTest.ts b/test/InstanceSharing.test.ts similarity index 100% rename from test/InstanceSharingTest.ts rename to test/InstanceSharing.test.ts diff --git a/test/MapSchemaTest.ts b/test/MapSchema.test.ts similarity index 100% rename from test/MapSchemaTest.ts rename to test/MapSchema.test.ts diff --git a/test/NextIterationTest.ts b/test/NextIteration.test.ts similarity index 100% rename from test/NextIterationTest.ts rename to test/NextIteration.test.ts diff --git a/test/PerformanceTest.ts b/test/Performance.test.ts similarity index 100% rename from test/PerformanceTest.ts rename to test/Performance.test.ts diff --git a/test/PolymorphismTest.ts b/test/Polymorphism.test.ts similarity index 100% rename from test/PolymorphismTest.ts rename to test/Polymorphism.test.ts diff --git a/test/ReflectionTest.ts b/test/Reflection.test.ts similarity index 100% rename from test/ReflectionTest.ts rename to test/Reflection.test.ts diff --git a/test/SchemaTest.ts b/test/Schema.test.ts similarity index 100% rename from test/SchemaTest.ts rename to test/Schema.test.ts diff --git a/test/SetSchemaTest.ts b/test/SetSchema.test.ts similarity index 100% rename from test/SetSchemaTest.ts rename to test/SetSchema.test.ts diff --git a/test/SpecTest.ts b/test/Spec.test.ts similarity index 100% rename from test/SpecTest.ts rename to test/Spec.test.ts diff --git a/test/TypeScriptTypes.test.ts b/test/TypeScriptTypes.test.ts new file mode 100644 index 00000000..c6165b4a --- /dev/null +++ b/test/TypeScriptTypes.test.ts @@ -0,0 +1,21 @@ +import * as assert from "assert"; +import { State, Player, DeepState, DeepMap, DeepChild, Position, DeepEntity } from "./Schema"; +import { Schema, ArraySchema, MapSchema, type } from "../src"; + +describe("TypeScript Types", () => { + it("strict null/undefined checks", () => { + class Player extends Schema { + @type("number") orderPriority: number; + } + class MyState extends Schema { + @type({ map: Player }) players = new MapSchema(); + } + + const state = new MyState(); + state.players.set("one", new Player().assign({ + orderPriority: null, + })); + state.encodeAll(); + console.log("DONE!"); + }); +}); \ No newline at end of file diff --git a/test/UtilsTest.ts b/test/Utils.test.ts similarity index 100% rename from test/UtilsTest.ts rename to test/Utils.test.ts diff --git a/test/codegen/CodegenTest.ts b/test/codegen/Codegen.test.ts similarity index 100% rename from test/codegen/CodegenTest.ts rename to test/codegen/Codegen.test.ts