Skip to content

Commit

Permalink
Demo Gen Feature Tests Makefile (#675)
Browse files Browse the repository at this point in the history
  • Loading branch information
ambiguousname authored Sep 10, 2024
1 parent 9dcee14 commit b375b3e
Show file tree
Hide file tree
Showing 37 changed files with 6,212 additions and 31 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,32 @@ jobs:
- name: Test JS
run: cargo make test-js

test-demo:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [
18.20.3, # supported until 2025-04-30
20.14.0, # supported until 2026-04-30
22.3.0, # current, supported until 2027-04-30
]
fail-fast: false
steps:
- uses: actions/checkout@v4

- name: Install cargo-make
uses: taiki-e/install-action@cargo-make

- name: Load Rust toolchain for WASM.
run: rustup target add wasm32-unknown-unknown

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Test Demo Gen
run: cargo make test-demo

test-dart:
runs-on: ubuntu-latest
steps:
Expand Down
31 changes: 29 additions & 2 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ dependencies = [
"test-js-feature",
]

[tasks.test-demo]
category = "Tests"
dependencies = [
"test-demo-feature",
"test-demo-example"
]

[tasks.test-dart]
category = "Tests"
dependencies = [
Expand Down Expand Up @@ -83,6 +90,7 @@ category = "Tests"
dependencies = [
"test-cpp-feature",
"test-js-feature",
"test-demo-feature",
"test-dart-feature",
"test-kotlin-feature",
]
Expand Down Expand Up @@ -130,14 +138,23 @@ cp ../../target/wasm32-unknown-unknown/debug/diplomat_feature_tests.wasm api/dip
npm install && npm run test
'''

[tasks.test-demo-feature]
category = "Tests"
dependencies = ["build-feature-wasm"]
script_runner = "@shell"
script = '''
cd feature_tests/demo_gen
cp ../../target/wasm32-unknown-unknown/debug/diplomat_feature_tests.wasm ../js/api/diplomat_feature_tests.wasm
npm install && npm run test
'''

[tasks.test-demo-example]
category = "Tests"
dependencies = ["build-example-wasm"]
script_runner = "@shell"
script = '''
cd example/demo_gen
cp ../../target/wasm32-unknown-unknown/debug/diplomat_example.wasm demo/diplomat_example.wasm
cp ../../target/wasm32-unknown-unknown/debug/diplomat_example.wasm ../js/lib/api/diplomat_example.wasm
npm install && npm run test
'''

Expand Down Expand Up @@ -319,6 +336,7 @@ dependencies = [
"gen-cpp-feature",
"gen-c-feature",
"gen-js-feature",
"gen-demo-feature",
"gen-dart-feature",
"gen-kotlin-feature",
]
Expand Down Expand Up @@ -419,13 +437,22 @@ exit_on_error true
generate_generic example js lib/api
'''

[tasks.gen-demo-feature]
category = "Code generation"
script_runner = "@duckscript"
script = '''
exit_on_error true
!include_files ./support/functions.ds
generate_generic feature_tests demo_gen demo "-l diplomat-demo-conf.toml"
'''

[tasks.gen-demo-example]
category = "Code generation"
script_runner = "@duckscript"
script = '''
exit_on_error true
!include_files ./support/functions.ds
generate_generic example demo_gen demo
generate_generic example demo_gen demo "-l diplomat-demo-conf.toml"
'''

[tasks.gen-dart-feature]
Expand Down
4 changes: 1 addition & 3 deletions example/demo_gen/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
demo/js/*
demo/*.wasm
node_modules
package-lock.json
node_modules
17 changes: 15 additions & 2 deletions example/demo_gen/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
Used by js, since generate_generic doesn't allow me to move this to another backend's folder.
Example of the `demo_gen` backend working with a smaller version of the ICU4X library.

I think ideally the way this would work is that you would just be able to run diplomat_tool demo_gen api/demo to create the demo bindings.
For a few reasons (mostly related to the CI) this folder is not self-contained. It depends on the JS bindings, and for this reason must be viewed through a webserver from the root of the diplomat repo.

If you're looking for a more simple, self-contained example, please see the [quickstart repo](https://github.com/rust-diplomat/demo-gen-quickstart).

If you're looking for an example of how to bundle multiple dependencies through say, webpack, please see [the ICU4X repository](https://github.com/unicode-org/icu4x/tree/main/tutorials/web-demo).

To view the example in action, run:

```bash
npm install
npm run start
```

Then navigate to the `demo_gen` folder in the HTTP Server that opens.
2 changes: 1 addition & 1 deletion example/demo_gen/demo/FixedDecimal.d.ts

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

2 changes: 1 addition & 1 deletion example/demo_gen/demo/FixedDecimal.mjs

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

10 changes: 5 additions & 5 deletions example/demo_gen/demo/FixedDecimalFormatter.d.ts

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

10 changes: 5 additions & 5 deletions example/demo_gen/demo/FixedDecimalFormatter.mjs

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

3 changes: 0 additions & 3 deletions example/demo_gen/demo/diplomat.config.mjs

This file was deleted.

2 changes: 1 addition & 1 deletion example/demo_gen/demo/index.mjs

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

3 changes: 0 additions & 3 deletions example/demo_gen/diplomat.config.mjs

This file was deleted.

Loading

0 comments on commit b375b3e

Please sign in to comment.