Skip to content

Instantly share code, notes, and snippets.

@lifuzu
Created October 9, 2017 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lifuzu/a77ffa1868e08e0353b04a881f8c47ce to your computer and use it in GitHub Desktop.
Save lifuzu/a77ffa1868e08e0353b04a881f8c47ce to your computer and use it in GitHub Desktop.
A node/npm functions template
// __tests__/funcs.spec.js
const funcs = require("../libs/funcs")()
describe('hello', () => {
it('should say hello', () => {
expect(funcs.hello()).toBe('world!')
})
})
describe('world', () => {
it('should caculate world', () => {
expect(funcs.world([1, 2]) === [2, 4])
})
})
// libs/funcs.js
exports = module.exports = (options) => {
// PRIVATE FUNCTION(S)
// get a random integer between 0 (zero) and max
function random_wait(max) {
return Math.floor(Math.random() * (max + 1))
}
// PRIVATE VARIABLE(S)
const private_count = 'something'
// PUBLIC FUNCTION(S)
return {
hello: function (params) {
return 'world!'
},
world: function (params) {
return params.map( p => {
return p * 2
})
}
}
}
// package.json
{
// ...
"scripts": {
"test": "jest",
"start": "babel-node --presets env $npm_package_main"
},
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment