forked from madonoharu/tsify
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix invalid typescript generation for empy enums (#23)
* Add e2e tests (with purposeful error) * Allow empty enums
- Loading branch information
Showing
19 changed files
with
230 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,13 +47,18 @@ jobs: | |
override: true | ||
components: rustfmt | ||
|
||
- name: Install wasm-pack | ||
uses: jetli/[email protected] | ||
with: | ||
# Optional version of wasm-pack to install(eg. 'v0.9.1', 'latest') | ||
version: "latest" | ||
|
||
- name: Add cargo-expand | ||
run: cargo install cargo-expand | ||
|
||
# Run the ./test.sh script | ||
- name: Test | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: test | ||
run: ./test.sh | ||
lint: | ||
name: Lint | ||
runs-on: ubuntu-latest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/target | ||
Cargo.lock | ||
.vscode | ||
tests-e2e/*/pkg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "tsify-next" | ||
version = "0.5.0" | ||
version = "0.5.1" | ||
edition = "2021" | ||
authors = [ | ||
"Madono Haru <[email protected]>", | ||
|
@@ -14,7 +14,7 @@ keywords = ["wasm", "wasm-bindgen", "typescript"] | |
categories = ["wasm"] | ||
|
||
[dependencies] | ||
tsify-next-macros = { path = "tsify-next-macros", version = "^0.5" } | ||
tsify-next-macros = { path = "tsify-next-macros", version = "0.5.1" } | ||
wasm-bindgen = { version = "0.2.86", optional = true } | ||
serde = { version = "1.0", optional = true } | ||
serde_json = { version = "1.0", optional = true } | ||
|
@@ -50,4 +50,5 @@ json = [ | |
] | ||
|
||
[workspace] | ||
members = ["tsify-next-macros"] | ||
members = ["tsify-next-macros", "tests-e2e/*"] | ||
exclude = ["tests-e2e/reference_output"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# tests-e2e | ||
|
||
These tests test the actual `.d.ts` file output by `wasm-pack`. When `wasm-pack build` is run | ||
on a project in one of the sub-folders, a `pkg/` directory will be created. Running `./reference_output/compare_output.sh` | ||
will compare the reference output (stored in a directory match the test name) to that generated in the `pkg/` directory | ||
output by `wasm-pack`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
|
||
# Define the root directory for the search | ||
ROOT_DIR="tests-e2e" | ||
|
||
# Find all Cargo.toml files in the root directory and its direct subdirectories | ||
FILES=$(find "$ROOT_DIR" -maxdepth 2 -name Cargo.toml) | ||
|
||
for FILE in $FILES; do | ||
# Get the directory of the file | ||
DIR=$(dirname "$FILE") | ||
# Push the directory onto the stack and change to it | ||
pushd "$DIR" > /dev/null || exit | ||
|
||
echo "" | ||
echo "Building in $DIR" | ||
echo "" | ||
|
||
# Run wasm-pack build | ||
wasm-pack build | ||
# Pop the directory from the stack and change back to the original directory | ||
popd > /dev/null || exit | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/bash | ||
|
||
# Given files <folder>/<file> search for identically named files in `../<folder>/pkg/<file>` | ||
# and compare them. If the files differ, print the differences and return an error exit code. | ||
|
||
# Change the current directory to the directory where the script is located | ||
cd "$(dirname "$0")" || exit | ||
|
||
DIFF_FOUND=0 | ||
|
||
# Find all directories in the current directory | ||
for FOLDERNAME in $(find . -maxdepth 1 -type d); do | ||
# Skip the current directory | ||
if [ "$FOLDERNAME" = "." ]; then | ||
continue | ||
fi | ||
|
||
# Remove the leading "./" from the folder name | ||
FOLDERNAME="${FOLDERNAME#./}" | ||
|
||
# Find all files in the current folder and its subdirectories | ||
FILES=$(find "./${FOLDERNAME}/" -type f) | ||
for FILE in $FILES; do | ||
# Remove the leading "./<foldername>/" from the file path | ||
RELATIVE_PATH="${FILE#./${FOLDERNAME}/}" | ||
# Construct the path to the corresponding file in ../<foldername>/pkg/ | ||
OTHER_FILE="../${FOLDERNAME}/pkg/${RELATIVE_PATH}" | ||
# Compare the files | ||
if [ -f "$OTHER_FILE" ]; then | ||
echo "Comparing $FILE with $OTHER_FILE" | ||
|
||
# suppress the exit code if the files differ beause we want to print out all differences | ||
DIFF_OUTPUT=$(diff --brief "$FILE" "$OTHER_FILE" || true) | ||
if [ -n "$DIFF_OUTPUT" ]; then | ||
echo " $DIFF_OUTPUT" | ||
diff "$FILE" "$OTHER_FILE" | ||
DIFF_FOUND=1 | ||
else | ||
echo " Files are identical" | ||
fi | ||
fi | ||
done | ||
done | ||
|
||
exit $DIFF_FOUND |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
/** | ||
* @returns {Point} | ||
*/ | ||
export function into_js(): Point; | ||
export interface Point { | ||
x: number; | ||
y: number; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
/** | ||
* @returns {Point} | ||
*/ | ||
export function into_js(): Point; | ||
export interface Point { | ||
x: number; | ||
y: number; | ||
} | ||
|
||
export type NullPoint = void; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[package] | ||
name = "test1" | ||
publish = false | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
wasm-bindgen = "0.2" | ||
tsify-next = { path = "../..", version = "*" } | ||
serde = { version = "1.0", features = ["derive"] } | ||
serde_json = "1.0" | ||
|
||
[dev-dependencies] | ||
wasm-bindgen-test = "0.3" | ||
|
||
[lib] | ||
path = "entry_point.rs" | ||
crate-type = ["cdylib"] | ||
|
||
[build-dependencies] | ||
wasm-bindgen-cli = "0.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use tsify_next::Tsify; | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[derive(Tsify, Serialize, Deserialize)] | ||
#[tsify(into_wasm_abi, from_wasm_abi)] | ||
pub struct Point { | ||
x: i32, | ||
y: i32, | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn into_js() -> Point { | ||
Point { x: 0, y: 0 } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[package] | ||
name = "test2" | ||
publish = false | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
wasm-bindgen = "0.2" | ||
tsify-next = { path = "../..", version = "*" } | ||
serde = { version = "1.0", features = ["derive"] } | ||
serde_json = "1.0" | ||
|
||
[dev-dependencies] | ||
wasm-bindgen-test = "0.3" | ||
|
||
[lib] | ||
path = "entry_point.rs" | ||
crate-type = ["cdylib"] | ||
|
||
[build-dependencies] | ||
wasm-bindgen-cli = "0.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use tsify_next::Tsify; | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[derive(Tsify, Serialize, Deserialize)] | ||
#[tsify(into_wasm_abi, from_wasm_abi)] | ||
pub struct Point { | ||
x: i32, | ||
y: i32, | ||
} | ||
|
||
#[derive(Tsify, Serialize, Deserialize)] | ||
#[tsify(into_wasm_abi, from_wasm_abi)] | ||
pub enum NullPoint {} | ||
|
||
#[wasm_bindgen] | ||
pub fn into_js() -> Point { | ||
Point { x: 0, y: 0 } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "tsify-next-macros" | ||
version = "0.5.0" | ||
version = "0.5.1" | ||
edition = "2021" | ||
authors = [ | ||
"Madono Haru <[email protected]>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters