Skip to content

Commit

Permalink
move to project based tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ksjogo committed Dec 26, 2021
1 parent a43f2d2 commit 45fd188
Show file tree
Hide file tree
Showing 23 changed files with 247 additions and 188 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module.exports = {
"**/godot_src/**",
"**/js/**",
".eslintrc.js",
"tsconfig.json",
],
env: {
es2021: true,
Expand Down
26 changes: 18 additions & 8 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,33 @@
"version": "0.2.0",
"configurations": [
{
"name": "Launch Program",
"name": "Run Example",
"program": "${workspaceFolder}/js/main.js",
"request": "launch",
"skipFiles": ["<node_internals>/**"],
"args": ["${workspaceFolder}/example/ts2gd.json"],
"skipFiles": [
"<node_internals>/**"
],
"args": [
"${workspaceFolder}/example/ts2gd.json"
],
"type": "pwa-node",
"preLaunchTask": "tsc: build - tsconfig.json",
"outFiles": ["${workspaceFolder}/js/**/*.js"]
"outFiles": [
"${workspaceFolder}/js/**/*.js"
]
},
{
"name": "Launch Test",
"name": "Run Tests",
"program": "${workspaceFolder}/js/tests/test.js",
"request": "launch",
"skipFiles": ["<node_internals>/**"],
"skipFiles": [
"<node_internals>/**"
],
"type": "pwa-node",
"preLaunchTask": "tsc: build - tsconfig.json",
"outFiles": ["${workspaceFolder}/js/**/*.js"]
"outFiles": [
"${workspaceFolder}/js/**/*.js"
]
}
]
}
}
13 changes: 13 additions & 0 deletions example/Autoload.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

# This file has been autogenerated by ts2gd. DO NOT EDIT!


extends Node2D
class_name Autoload




var _MyAutoload = Autoload.new()

var hello: String = "hi"
12 changes: 12 additions & 0 deletions example/Test.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

# This file has been autogenerated by ts2gd. DO NOT EDIT!



class_name Test






2 changes: 2 additions & 0 deletions example/Test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// this file will have dynamic content from our test infrastructure
export class Test {}
8 changes: 8 additions & 0 deletions example/autoload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// this file will have dynamic content from our test infrastructure

@autoload
class Autoload extends Node2D {
public hello = "hi"
}

export const MyAutoload = new Autoload()
File renamed without changes.
20 changes: 19 additions & 1 deletion example/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,30 @@

config_version=4

_global_script_classes=[ {
"base": "Reference",
"class": "Test",
"language": "GDScript",
"path": "res://Test.gd"
} ]
_global_script_class_icons={
"Test": ""
}

[application]

config/name="example"
run/main_scene="res://Main.tscn"
run/main_scene="res://main.tscn"
config/icon="res://icon.png"

[autoload]

Autoload="*res://Autoload.gd"

[global]

autoload=false

[physics]

common/enable_pause_aware_picking=true
Expand Down
7 changes: 5 additions & 2 deletions example/ts2gd.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"destination": "./",
"source": "./",
"godotSourceRepoPath": "./godot_src",
"ignore": ["**/ignore_me/**", "ignore_me.ts"]
}
"ignore": [
"**/ignore_me/**",
"ignore_me.ts"
]
}
6 changes: 3 additions & 3 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ const setup = (tsgdJson: Paths) => {
opt.config.useCaseSensitiveFileNames = false

return {
watchProgram,
program: watchProgram.getProgram().getProgram(),
tsgdJson,
reportWatchStatusChanged,
tsInitializationFinished,
Expand All @@ -266,10 +266,10 @@ export const main = async (args: ParsedArgs) => {
const tsgdJson = new Paths(args)

showLoadingMessage("Initializing TypeScript", args)
const { watchProgram, tsInitializationFinished } = setup(tsgdJson)
const { program, tsInitializationFinished } = setup(tsgdJson)

showLoadingMessage("Scanning project", args)
let project = await makeTsGdProject(tsgdJson, watchProgram, args)
let project = await makeTsGdProject(tsgdJson, program, args)

if (args.buildLibraries || project.shouldBuildLibraryDefinitions(args)) {
showLoadingMessage("Building definition files", args)
Expand Down
24 changes: 24 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,23 @@
"semi": false
},
"lint-staged": {
"*.{ts,json}": [
"*.ts": [
"eslint --fix",
"prettier --write"
],
"*.json": [
"prettier --write"
]
},
"dependencies": {
"chalk": "^4.1.2",
"chokidar": "^3.5.2",
"lodash": "^4.17.21",
"tsutils": "^3.21.0",
"xml2js": "^0.4.23"
},
"devDependencies": {
"@types/lodash": "^4.14.178",
"@types/node": "^16.11.9",
"@types/xml2js": "^0.4.9",
"@typescript-eslint/eslint-plugin": "^5.7.0",
Expand Down
13 changes: 7 additions & 6 deletions parse_node/parse_enum_declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import ts from "typescript"

import { ParseNodeType, ParseState, combine } from "../parse_node"
import { Test } from "../tests/test"
import { examplePath } from "../tests/test_utils"

import { getImportResPathForEnum } from "./parse_import_declaration"

Expand Down Expand Up @@ -71,17 +72,17 @@ export class Hello {
type: "multiple-files",
files: [
{
fileName: "/Users/johnfn/MyGame/compiled/Hello.gd",
fileName: examplePath("Hello.gd"),
expected: `
class_name Hello
const MyEnum = preload("res://compiled/Test_MyEnum.gd").MyEnum
const MyEnum = preload("res://Test_MyEnum.gd").MyEnum
func _ready():
print(MyEnum.A)
`,
},

{
fileName: "/Users/johnfn/MyGame/compiled/Test_MyEnum.gd",
fileName: examplePath("Test_MyEnum.gd"),
expected: `
const MyEnum = {
"A": 0,
Expand Down Expand Up @@ -109,17 +110,17 @@ export class Hello {
type: "multiple-files",
files: [
{
fileName: "/Users/johnfn/MyGame/compiled/Hello.gd",
fileName: examplePath("Hello.gd"),
expected: `
class_name Hello
const TestEnum = preload("res://compiled/Test_TestEnum.gd").TestEnum
const TestEnum = preload("res://Test_TestEnum.gd").TestEnum
func _ready():
print(TestEnum.A)
`,
},

{
fileName: "/Users/johnfn/MyGame/compiled/Test_TestEnum.gd",
fileName: examplePath("Test_TestEnum.gd"),
expected: `
const TestEnum = {
"A": "A",
Expand Down
7 changes: 4 additions & 3 deletions parse_node/parse_property_declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ErrorName } from "../project/errors"
import { ParseNodeType, ParseState, combine } from "../parse_node"
import { Test } from "../tests/test"
import { getGodotType, getTypeHierarchy, isEnumType } from "../ts_utils"
import { examplePath } from "../tests/test_utils"

export const isDecoratedAsExports = (
node:
Expand Down Expand Up @@ -448,16 +449,16 @@ export class Test {
type: "multiple-files",
files: [
{
fileName: "/Users/johnfn/MyGame/compiled/Test.gd",
fileName: examplePath("Test.gd"),
expected: `
class_name Test
const MyEnum = preload("res://compiled/Test_MyEnum.gd").MyEnum
const MyEnum = preload("res://Test_MyEnum.gd").MyEnum
export(MyEnum) var foo
`,
},

{
fileName: "/Users/johnfn/MyGame/compiled/Test_MyEnum.gd",
fileName: examplePath("Test_MyEnum.gd"),
expected: `
const MyEnum = {
}`,
Expand Down
7 changes: 4 additions & 3 deletions parse_node/parse_source_file.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import ts, { SyntaxKind } from "typescript"

import { ErrorName } from "../project/errors"
import { ErrorName } from "../project"
import { ParseNodeType, ParseState, combine, parseNode } from "../parse_node"
import { Test } from "../tests/test"
import { examplePath } from "../tests/test_utils"

import { LibraryFunctions } from "./library_functions"

Expand Down Expand Up @@ -221,11 +222,11 @@ export class Test2 { }
type: "multiple-files",
files: [
{
fileName: "/Users/johnfn/MyGame/compiled/Test1.gd",
fileName: examplePath("Test1.gd"),
expected: `class_name Test1`,
},
{
fileName: "/Users/johnfn/MyGame/compiled/Test2.gd",
fileName: examplePath("Test2.gd"),
expected: `class_name Test2`,
},
],
Expand Down
Loading

0 comments on commit 45fd188

Please sign in to comment.