Giter Club home page Giter Club logo

Comments (10)

defunctzombie avatar defunctzombie commented on May 17, 2024

What is the purpose of mock? and what is in util?

What do you expect to be in the different environments?

Why is it not just:

lib
test

:)

from node-libs-browser.

sokra avatar sokra commented on May 17, 2024

mock

A good example mock for buffer.

I want the mocks to be a very small version of the buildin lib which do not implement any features to the full module, but provide a similar API.
If you now you app do not really use any feature of the vm module, but some (stupid) 3rd party lib has a reference to it, you may choose to use the mock version.

environements

Run tests with different bundlers and maybe with node. So environments are just the bindings for the bundlers to the test code in test/tests.

Why is it not just:

lib
test

Where would the shared stuff be placed? Intermixed with the modules?

from node-libs-browser.

sokra avatar sokra commented on May 17, 2024

lib/util could be better merged into lib.

from node-libs-browser.

defunctzombie avatar defunctzombie commented on May 17, 2024

A good example mock for buffer.

I want the mocks to be a very small version of the buildin lib which do not implement any features to the full module, but provide a similar API.
If you now you app do not really use any feature of the vm module, but some (stupid) 3rd party lib has a reference to it, you may choose to use the mock version.

This is not for this library to decide imho. Module authors can make use of the browser field which was created specifically for such things. End users can educate the bundler to further replace files. In browserify we can do bundle.require('/path/to/file', { expose: 'vm' }); to replace the vm that would load for the user if they want to opt out for all. Really this is on a per module level to decide. This module should provide as close to best effort as possible for the core libs and leave it at that. We could have a folder with some examples of smaller things but I would not expose those. Or make a different module.

Different bundlers should instrument themselves properly imho on top of a common test suite. I would not want to repeat tests over and over again. I will make an example that uses mocha testing to also work in travis, locally, and on testling to capture browser support ;)

from node-libs-browser.

sokra avatar sokra commented on May 17, 2024

This is not for this library to decide imho. Module authors can make use of the browser which was created specifically for such things.

In a perfect world they would do so 👍

End users can educate the bundler to further replace files. In browserify we can do bundle.require('/path/to/file', { expose: 'vm' }); to replace the vm that would load for the user if they want to opt out for all.

This is the use case I target to with mocks. bundle.require('node-libs-browser/lib/mock/vm', { expose: 'vm' });

Really this is on a per module level to decide.

The authors can do so which the browser field.

This module should provide as close to best effort as possible for the core libs and leave it at that.

yes.

We could have a folder with some examples of smaller things but I would not expose those. Or make a different module.

So we could have a folder for mocks, but we don't expose it. Anyone could use it by referencing the file directly. I think an extra module is too much for mocks...

Different bundlers should instrument themselves properly imho on top of a common test suite. I would not want to repeat tests over and over again. I will make an example that uses mocha testing to also work in travis, locally, and on testling to capture browser support ;)

That's that want I also wanted to do. A shared test suite with test code (test/tests) plus a few small files which just configure the bundlers to use the test suite (test/environments).


lib - shared stuff/shims i. e. objectKeys.js
  core - all libs i. e. assert.js
  mock - mocks of all libs i. e. assert.js
test
  tests - shared test suite for all environments i. e. timers.test.js
  environments - environments to run tests in with references to ../tests
    node.js
    browserify.js
    webpack.js

from node-libs-browser.

defunctzombie avatar defunctzombie commented on May 17, 2024

Sounds more reasonable. I would do core files right into lib. And put mock at the top level as well for shorter paths in direct access. And yes, I would not expose mock directly. Seems cool otherwise although I think we may find the environments thing is not needed.

from node-libs-browser.

sokra avatar sokra commented on May 17, 2024

So I pushed a new directory structure...

lib - all buildin libs - i.e. assert.js
util - shared stuff of the buildin libs - i.e. objectKeys.js
mock - some mocks for libs - i.e. buffer.js
test
  suite - the test cases
  browserify - run the test cases with browserify
  webpack - run the test cases with webpack

from node-libs-browser.

sokra avatar sokra commented on May 17, 2024

Exported is a plain list of modules:

require("node-libs-browser");
{
  assert: "/path/to/node-libs-browser/lib/assert.js",
  events: "/path/to/node-libs-browser/lib/events.js",
  http: "/path/to/node-libs-browser/node_modules/http-browserify/index.js",
  /* ... */
}

from node-libs-browser.

defunctzombie avatar defunctzombie commented on May 17, 2024

Nice. What I think I will do is make browser-resolve options take a "map" object like the one above. This way users of that module can pass in their own set of core (if they want). This will make browser-resolve not have to force any particular mappings on people. It will have a default set (based on this module).

from node-libs-browser.

sokra avatar sokra commented on May 17, 2024

I've done the same as alias option/plugin for webpack:

from node-libs-browser.

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.