Skip to content

Commit 34afadc

Browse files
committed
test: add integration test for TypeScript declarations
Signed-off-by: Andrey <[email protected]>
1 parent 157111d commit 34afadc

File tree

9 files changed

+72
-0
lines changed

9 files changed

+72
-0
lines changed

.github/workflows/ci.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,10 @@ jobs:
470470
run: make
471471
working-directory: ./test/javascript_prelude
472472

473+
- name: Test generated TypeScript declarations
474+
run: make test
475+
working-directory: ./test/typescript_declarations
476+
473477
- name: Test export of hex tarball
474478
run: make test
475479
working-directory: ./test/hextarball

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@
6969
spans.
7070
([Giacomo Cavalieri](https://github.com/giacomocavalieri))
7171

72+
- Added integration test for TypeScript type declarations.
73+
([Andrey Kozhev](https://github.com/ankddev))
74+
7275
### Build tool
7376

7477
- New projects are generated using OTP28 on GitHub Actions.

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ test: ## Run the compiler unit tests
2424
cd test/project_javascript && cargo run clean && cargo run check && cargo run test
2525
cd test/project_deno && cargo run clean && cargo run check && cargo run test
2626
cd test/hextarball && make test
27+
cd test/typescript_declarations && make test
2728
cd test/running_modules && make test
2829
cd test/subdir_ffi && make
2930

@@ -51,6 +52,14 @@ test-watch: ## Run compiler tests when files change
5152
export-hex-tarball-test: ## Run `gleam export hex-tarball` and verify it is created
5253
cd test/hextarball && make test
5354

55+
.PHONY: typescript-declarations-test
56+
typescript-declarations-test: ## Check that generated TypeScript declaration compile
57+
cd test/typescript_declarations && make test
58+
59+
.PHONY: typescript-declarations-test-watch
60+
typescript-declarations-test-watch: ## Check that generated TypeScript declaration compile when files change
61+
watchexec "cd test/typescript_declarations && make test"
62+
5463
.PHONY: benchmark
5564
benchmark: ## Run the benchmarks
5665
cd benchmark/list && make
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.beam
2+
*.ez
3+
/build
4+
erl_crash.dump
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.PHONY: clean
2+
clean:
3+
rm -rf build
4+
5+
.PHONY: build
6+
test:
7+
cargo run --quiet -- build
8+
tsc ./build/dev/javascript/typescript_declarations/typescript_declarations.d.mts --noEmit --lib es2015
9+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# typescript_declarations
2+
3+
Check that generated TypeScript declarartions are correct. This requires TypeScript installed and be in PATH.
4+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name = "typescript_declarations"
2+
version = "1.0.0"
3+
target = "javascript"
4+
5+
[javascript]
6+
typescript_declarations = true
7+
8+
[dependencies]
9+
gleam_stdlib = ">= 0.44.0 and < 2.0.0"
10+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# This file was generated by Gleam
2+
# You typically do not need to edit this file
3+
4+
packages = [
5+
{ name = "gleam_stdlib", version = "0.62.1", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "0080706D3A5A9A36C40C68481D1D231D243AF602E6D2A2BE67BA8F8F4DFF45EC" },
6+
]
7+
8+
[requirements]
9+
gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" }
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//// Test TS declarartions
2+
3+
/// Answer for all questions in the world
4+
pub const answer = 256
5+
6+
pub type User {
7+
// Registered user
8+
User(name: String, email: String)
9+
/// Unregistered guest
10+
Guest
11+
}
12+
13+
/// Get name of user. Returns "Guest" if user is guest
14+
pub fn get_name(user) {
15+
case user {
16+
User(name, ..) -> name
17+
Guest -> "Guest"
18+
}
19+
}
20+

0 commit comments

Comments
 (0)