Giter Site home page Giter Site logo

Comments (4)

michaeldwan avatar michaeldwan commented on September 26, 2024

@mrkurt I can take a look. Where's the app code?

from fly.rs.

mrkurt avatar mrkurt commented on September 26, 2024

Currently this:

import { expect } from "chai"
import cache from "@fly/cache"
import { Image } from "@fly/image"
import db, { Collection } from "@fly/data"

fly.http.respondWith(async function(req){
  const result = []

  // Document global
  try{
    const dom = Document.parse(html)
    expect(dom).to.be.instanceof(Document)
    const p = dom.querySelector("p")
    expect(p).to.be.instanceof(Element)
    expect(p.getAttribute("something")).to.equal("yo")
    result.push("Document success!")
  }catch(err){
    result.push("Document error: " + err.toString())
  }

  // Text Encoding
  try{
    const td = new TextDecoder()
    expect(td.decode(new Uint8Array([104, 101, 108, 108, 111]))).to.equal("hello")

    const te = new TextEncoder()
    expect(te.encode("hello")).to.deep.equal(new Uint8Array([104, 101, 108, 108, 111]))
    result.push("Text Encoding success!")
  }catch(err){
    result.push("Text Encoding error: " + err.toString())
  }
  // Cache
  try{
    await cache.del("test-key")
    await cache.set("test-key", "test-value")
    const v = await cache.getString("test-key")
    expect(v).to.eq("test-value")
    result.push("Cache success!")
  }catch(err){
    result.push("Cache error: " + err.toString())
  }

  // Image
  try{
    const img = new Image({
      width: 200,
      height: 200,
      background: { r: 255, g: 0, b: 0, alpha: 0.5 },
      channels: 4
    })

    const meta = img.metadata()
    expect(meta.width).to.eq(200)
    expect(meta.height).to.eq(200)
    result.push("Image success!")
  }catch(err){
    result.push("Image error: " + err.toString())
  }
  
  // Data
  try{
    const coll = db.collection("testing")

    // insert initial object
    let ok = await coll.put("yo", { some: "json" })
    expect(ok).to.be.true

    // replace the object
    ok = await coll.put("yo", { some: "json2" })
    expect(ok).to.be.true

    // get the obj, to assert its value
    const res = await coll.get("yo")
    expect(res).to.deep.equal({ some: "json2" })
    result.push("Data success!")
  }catch(err){
    result.push("Data error: " + err.toString())
  }

  try{
    expect(app.config.secretThing).to.eq("secretValue")
    result.push("Secret success!")
  }catch(err){
    result.push("Secret error: " + err.toString())
  }

  return new Response(result.join("\n\n"))
})

const html = `
<html>
  <p something="yo">hello</p>
</html>
`

from fly.rs.

mrkurt avatar mrkurt commented on September 26, 2024

fwiw, it wouldn't bother me at all to solve this with a babel/webpack step that transforms the node based bundles into something better for this. It also wouldn't bother me to just have fly.rs understand these natively. Choose your own adventure.

from fly.rs.

michaeldwan avatar michaeldwan commented on September 26, 2024

Document is one of the several objects not inserted into the global scope yet. The rest of the errors are from the old bridge api being referenced from the bundle. I think we can prepend a shim to the compiled source to get it working. I'll give that a try and see if there's an easy mode fix.

from fly.rs.

Related Issues (20)

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.