Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Benchmark not exported by dist/index.min.js #2

Closed
spl opened this issue Mar 2, 2022 · 3 comments
Closed

Benchmark not exported by dist/index.min.js #2

spl opened this issue Mar 2, 2022 · 3 comments

Comments

@spl
Copy link

spl commented Mar 2, 2022

I'm running into a strange problem in which Benchmark does not seem to be exported by dist/index.min.js.

The following code:

const Benchmark = require('buffalo-bench')
const bench = new Benchmark('my_bench', { })

produced the following error:

TypeError: Benchmark is not a constructor

So then I changed it to this:

const Benchmark = require('buffalo-bench')
console.log(JSON.stringify(Benchmark, null, 2))

which produced this:

{
  "CompareBy": {
    "MeanTime": "meanTime",
    "MedianTime": "medianTime",
    "StandardDeviation": "standardDeviation",
    "MaxTime": "maxTime",
    "MinTime": "minTime",
    "Hz": "hz",
    "RunTime": "runTime",
    "Cycles": "cycles",
    "Percent": "percent"
  }
}

Then, I tried something similar with your repository by changing the import in your test as follows:

diff --git a/bench/index.ts b/bench/index.ts
index 4eec1a3..ea26122 100644
--- a/bench/index.ts
+++ b/bench/index.ts
@@ -1,4 +1,6 @@
-import Benchmark, { CompareBy } from '../lib';
+import Benchmark, { CompareBy } from '../dist/index.min.js';
+
+console.log(JSON.stringify(Benchmark, null, 2))
 
 (async () => {
   // let benchmark = new Benchmark("Regexp test", {

and I encountered the same problem:

$ yarn run test
yarn run v1.22.17
$ node ./index.js
{
  "CompareBy": {
    "MeanTime": "meanTime",
    "MedianTime": "medianTime",
    "StandardDeviation": "standardDeviation",
    "MaxTime": "maxTime",
    "MinTime": "minTime",
    "Hz": "hz",
    "RunTime": "runTime",
    "Cycles": "cycles",
    "Percent": "percent"
  }
}
/.../buffalo-bench/bench/index.ts:22
  let suite = new import_index_min.default.Suite("String comparison", {
              ^

TypeError: import_index_min.default.Suite is not a constructor

Also, I noticed your dist/index.min.js currently mentions version 1.0.1, but it was updated for the 1.0.2 release.

Perhaps, once you've fixed the export issue, you need to (a) add a test for dist/index.min.js and (b) document your release steps, so you won't have these problems in the future.

@spl
Copy link
Author

spl commented Mar 2, 2022

Okay, I just discovered buffalo-test and this line:

const { default: Benchmark } = require("buffalo-bench");

I was not aware of that syntax, but it seems to work.

@spl
Copy link
Author

spl commented Mar 2, 2022

Is there a context in which const Benchmark = require("buffalo-bench") works, as demonstrated in the README? If not, then perhaps the README needs to be updated.

@Masquerade-Circus
Copy link
Owner

I have made a new release changing this behavior.
Now we will use named exports to be consistent between different types of modules (cjs, mjs).

Now, you need to import it as import { Benchmark } from 'buffalo-bench' or const { Benchmark } = require('buffalo-bench').

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants