baconjs / bacon.js

Functional reactive programming library for TypeScript and JavaScript
https://baconjs.github.io
MIT License
6.47k stars 331 forks source link

Converge esm imports #776

Closed semmel closed 3 years ago

semmel commented 3 years ago

Fixes #774

I left out the Node.js import test because it would require creating a new npm project and npm installing baconjs.

Here is the code anyway:

// file: testBareImport.mjs
import * as Bacon from 'baconjs';
import pkg from "chai";
const { assert } = pkg;

describe("Bare ES6 import in Node.js", function() {
    it("passes smoke test", () =>
        Bacon.sequentially(10, [1, 2, 3])
        .map(x => x * x)
        .reduce(0, (acc, y) => acc +y)
        .toPromise()
        .then(sum => assert.equal(sum, 14))
    );
    it ("imports the ES6 classes", () => {
        // ES6 class constructors require 'new'
        // So while with ES5 constructor functions calls without 'new'
        // do not throw, calls to ES6 constructors throw TypeError
        assert.throws(() => {Bacon.Error("woo");}, TypeError);
    });
});

Execute with $mocha testBareImport.mjs.

raimohanska commented 3 years ago

Included in 3.0.17