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

allow mocked plugins (for oc dev) to run code #129

Closed
andyroyle opened this issue Oct 23, 2015 · 5 comments
Closed

allow mocked plugins (for oc dev) to run code #129

andyroyle opened this issue Oct 23, 2015 · 5 comments

Comments

@andyroyle
Copy link
Collaborator

Rather than just returning a static value, it would be nice to have the option to run a function.

@andyroyle andyroyle self-assigned this Oct 23, 2015
@matteofigus
Copy link
Member

👍
current signature is:

{
  "registries": ["http://registry.com"],
  "mocks": {
    "plugins": {
      "static": {
        "foo": "bar"
      }
    }
  }
}

I would suggest something that

  • allows inclusion of js file
  • perhaps a single file to rule them all (this means that for given project it would be possible to create and share that single file easily).
{
  "registries": ["http://registry.com"],
  "mocks": {
    "plugins": {
      "src": "./mock-plugins.js",
      "static": {
        "bar": "hello"
      }
    }
  }
}

Where the requested file would be a node file with a oc-plugin-style-ish api for register method for each plugin name:

module.exports.pluginFoo = [{
  name: 'foo',
  register: require('oc-foo'), // an actual plugin or a function with the mock
  options: { /* some options in case we use the real plugin */}
}, function(err){
  if(!!err){
    console.log('plugin failed to initialise');
    process.exit(1);
  }
}];

Another approach would be to have an oc.js instead of oc.json and directly extend the current api to accept a function. This sounds a little scary, first seems not bad and easier.

What do you think?

@andyroyle
Copy link
Collaborator Author

I would say we want to keep the plugins enumerated in the oc.json:

{
  "registries": ["http://registry.com"],
  "mocks": {
    "plugins": {
      "dynamic": {
        "plugin1": "./plugin1.js",
        "plugin1": "./plugin2.js"
      },
      "static": {
        "bar": "hello"
      }
    }
  }
}

Do we need the register function for these plugins? Considering they're supposed to be mocks?

Can we keep the signature dead simple:

module.exports = function(a){
  return a ? "foo" : "bar";
}

@matteofigus
Copy link
Member

uhm, I actually like this, seems simple and readable 👍

@andyroyle
Copy link
Collaborator Author

good because it took me 10 mins 👍

https://github.com/opentable/oc/compare/mock-plugins-code?expand=1

Just need to update the docs and I'll send a PR

@andyroyle
Copy link
Collaborator Author

closed by #130

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

No branches or pull requests

2 participants