Skip to content

Commit

Permalink
Adding NodeJS tests for WASM module (#262)
Browse files Browse the repository at this point in the history
* modularize wasm and add mocha tests

* add npm tests to CI

* fix mv command

* revert to build directory

* added rest of example tests

* fixed three.js test

* update web examples for module
  • Loading branch information
elalish authored Oct 27, 2022
1 parent 491d7d8 commit c59130c
Show file tree
Hide file tree
Showing 11 changed files with 2,376 additions and 501 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/manifold.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ jobs:
run: |
cd build/test
node ./manifold_test.js
cd ../bindings/wasm
npm install
npm test
- name: Upload WASM files
uses: actions/upload-artifact@v3
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,6 @@ Temporary Items
build
buildWASM
docs/html
node_modules/
__pycache__
.vscode/c_cpp_properties.json
9 changes: 4 additions & 5 deletions bindings/wasm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ set_source_files_properties(bindings.cpp OBJECT_DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/bindings.js)
target_link_libraries(manifoldjs manifold sdf)
target_compile_options(manifoldjs PRIVATE ${MANIFOLD_FLAGS} -fexceptions)
target_link_options(manifoldjs PUBLIC --pre-js ${CMAKE_CURRENT_SOURCE_DIR}/bindings.js --bind -s ALLOW_TABLE_GROWTH=1
-sEXPORTED_RUNTIME_METHODS=addFunction,removeFunction)
target_link_options(manifoldjs PUBLIC --pre-js ${CMAKE_CURRENT_SOURCE_DIR}/bindings.js --bind -sALLOW_TABLE_GROWTH=1
-sEXPORTED_RUNTIME_METHODS=addFunction,removeFunction -sMODULARIZE=1)

target_compile_features(manifoldjs PUBLIC cxx_std_14)
set_target_properties(manifoldjs PROPERTIES OUTPUT_NAME "manifold")

file(GLOB_RECURSE WEB_FILES CONFIGURE_DEPENDS *.html *.ts)
file(COPY ${WEB_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${WEB_FILES})
file(COPY examples;test;. DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS examples;test)
12 changes: 7 additions & 5 deletions bindings/wasm/examples/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

const exampleFunctions = examples.functionBodies;

let editor = undefined;

// File UI ------------------------------------------------------------
Expand Down Expand Up @@ -53,7 +55,7 @@ function nthKey(n) {
function saveCurrent() {
if (editor) {
const currentName = currentElement.textContent;
if (!examples.get(currentName)) {
if (!exampleFunctions.get(currentName)) {
setScript(currentName, editor.getValue());
}
}
Expand All @@ -69,8 +71,8 @@ function switchTo(scriptName) {
switching = true;
currentElement.textContent = scriptName;
setScript('currentName', scriptName);
const code = examples.get(scriptName) ?? getScript(scriptName) ?? '';
isExample = examples.get(scriptName) != null;
const code = exampleFunctions.get(scriptName) ?? getScript(scriptName) ?? '';
isExample = exampleFunctions.get(scriptName) != null;
editor.setValue(code);
}
}
Expand Down Expand Up @@ -103,7 +105,7 @@ function addIcon(button) {
function uniqueName(name) {
let num = 1;
let newName = name;
while (getScript(newName) != null || examples.get(newName) != null) {
while (getScript(newName) != null || exampleFunctions.get(newName) != null) {
newName = name + ' ' + num++;
}
return newName;
Expand Down Expand Up @@ -214,7 +216,7 @@ require(['vs/editor/editor.main'], async function () {
const w = await monaco.languages.typescript.getTypeScriptWorker();
tsWorker = await w(editor.getModel().uri);

for (const [name] of examples) {
for (const [name] of exampleFunctions) {
const button = createDropdownItem(name);
dropdown.appendChild(button.parentElement);
}
Expand Down
Loading

0 comments on commit c59130c

Please sign in to comment.