Git Product home page Git Product logo

Comments (2)

munrocket avatar munrocket commented on August 23, 2024 1
  • pakage.json
{
  "test": "concurrently -k -s first \"npm:puppeteer\" \"http-server -c-1 -p 1234\"",
  "puppeteer": "node --experimental-modules --es-module-specifier-resolution=node --no-warnings ./test/puppeteer"
}
  • test.js
import { test } from '../node_modules/zora/dist/bundle/module.js';

test('should result to the answer', t => {
    const answer = 42
    t.equal(answer, 42, 'answer should be 42');
});
  • puppeteer.js
import puppeteer from 'puppeteer';

(async () => {
  const browser = await puppeteer.launch({ headless: false });

  const page = await browser.newPage();
  page.on('console', msg => {
    for (let i = 0; i < msg.args().length; ++i) {
      const str = msg.args()[i].toString().slice(9);
      console.log(str);
      if (str.trim() == '# ok') {
        process.exit(0)
      } else if (str == '# not ok') {
        process.exit(1)
      }
    }
  });
  await page.goto('http://127.0.0.1:1234/');

  await new Promise(resolve => setTimeout(resolve, 10000));
  process.exit(2);
})();
  • index.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Testing</title>
</head>
<body>
  
</body>
<script type="module" src="test.js"></script>
</html>

from zora.

lorenzofox3 avatar lorenzofox3 commented on August 23, 2024

As I understand for now it's only possible with Zora and node 10+ (or 12+).

For older Node, you can also install esm and pass it as the require option when running node

node -r esm my/node/esm/program.js

see this example from another user

Thanks for the example, I'll put something similar in my next article

from zora.

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.