webtask-require-version v1.0.1
webtask-require-version
Override require so you can test your webtask.io scripts.
Install
npm install webtask-require-version
Usage
webtask.io only allows specific versions of modules to be used. When writing my webtasks I wanted to test against those same specific versions (mocking depedencies manually). This module does that by overriding require to make the require('module@x.y.z') syntax valid.
your-webtask.js
var request = require('request@2.56.0')
var qs = require('qs@3.1.0')
var _ = require('lodash@3.9.3')
module.exports = function (ctx, cb) {
// Use request, qs, and lodash in your webtask
}test.js
// This overrides the default `require`
require('webtask-require-version')
// Your webtask can now use use requires like require('request@2.56.0')
var webtask = require('./your-webtask')
// Other requires will still work
require('tape')(function (t) {
// Test your webtask
webtask(context, function (err, data) {
t.equal(data, expected)
t.end();
})
})What happens if that version is not installed locally?
webtask-require-version will throw an error if you try to require a module that does not match based on the semver ^ operator. It will also log a warning if semver does match but the versions dont match exactly. This warning can be suppressed by using NODE_ENV=production.
Contributing
This is written in ES6 and compiled to ES5 using babel. The code you require will come from the lib/ directory which gets compiled from src/ before each npm publish.
Tests
npm test
License
MIT

