Giter Club home page Giter Club logo

appflowy-wasm-test's Introduction

React + Jest + Wasm

This is a simple example of how to use WebAssembly in a React application. The wasm module is written in Rust and compiled with wasm-pack.

Development

Install dependencies

pnpm install

How to build wasm

pnpm run wasm:build

How to test

Use cypress tests is the recommended way, because the browser is more similar to the environment where the application will run.

Unit tests with Cypress (Recommended)

This will run the tests in the browser.

  • test: run the tests in the background
  • test:open: open the browser and run the tests
// Build the wasm module
pnpm run wasm:build

// Start the dev server
pnpm run dev --host

// Run the tests
pnpm run test

// or
pnpm run test:open

Unit tests with wasm-pack

cd flowy-wasm

// if you want to run the tests in the browser

// brew install chromedriver
wasm-pack test --headless --chrome

// or
// brew install geckodriver
wasm-pack test --headless --firefox

How to write tests

Cypress Tests

The tests are located in the cypress/integration folder. The tests are written in TypeScript

// cypress/integration/flowy.spec.ts

describe('Flowy', () => {
  it('should render the flowy canvas', () => {
    const text_route = '/test_add'
    cy.visit(text_route);
    
    // Get the input element
    cy.get('#flowy-first-number').type('1');
    cy.get('#flowy-second-number').type('2');
    cy.get('#flowy-add').click();
    
    // Get the output element
    cy.get('#flowy-output').should('have.value', '3');
    
    // Clear the input
    cy.get('#flowy-first-number').clear();
    cy.get('#flowy-second-number').clear();
    
    // Repeat the process for the other operations
    // ...
  })
})

Wasm-pack Tests

The tests are located in the flowy-wasm/tests folder. The tests are written in Rust and use the #[wasm_bindgen_test] macro to interact with the wasm module.

// flowy-wasm/tests/add.rs

#[wasm_bindgen_test]
fn test_add() {
    let result = add(1, 2);
    assert_eq!(result, 3);
}

appflowy-wasm-test's People

Contributors

qinluhe avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.