goatslacker

  • Archive
  • RSS
  • Ask me anything

Introducing node-typedjs

node-typedjs is the node module, and more, for TypedJS

TypedJS is described as “lightweight program specifications for testing JavaScript”

In a nutshell you can annotate your functions with Haskell-like type signatures and then run a set of tests against those functions thus ensuring type safety. TypedJS will probably help you find some bugs in your code that you otherwise may not have found.

What it does

node-typedjs helps you test your JavaScript projects via the command line or programatically.

It gives you access to a few neat features like contracts via the enforce() method which enforce the types at runtime.

The contracts can be used along with your unit tests to assert that your functions are behaving as intended.

Similar to contracts.coffee, typedjs aims at solving the problem differently.

  • TypedJS is focused on JavaScript. But it also works on CoffeeScript just as well.
  • The type signatures are comments. So there is no extra compilation and the signatures are unobtrusive.

Examples

addition.js contains your function along with its type signature.

//+ add :: Number Number -> Number
function add(a, b) {
  return a + b;
}

addition-test.js is your unit test as well as the typedjs checks.

var typedjs = require('typedjs');
var fs = require('fs');
var assert = require('assert');

typedjs.enforce(fs.readFileSync('addition.js').toString());

typedjs.run(function (context) {
  assert.equal(context.square(3), 9); // pass
  assert.equal(context.square('foo', 'bar'), 'foobar'); // fail
});

Even though both assertions would pass, the typedjs check will fail on the second call since a number is expected.

node-typedjs will let you:

  • Run automated tests on your code.
  • Run automated tests on functions individually.
  • Extract all functions from a file (regardless of closures) and run automated tests on them.
  • Use it along with your unit tests to assert your functions are behaving correctly.

Getting node-typedjs

You will need node.js

Install using npm

Locally:

$ npm install typedjs

Globally

$ npm install typedjs -g

Standing on the shoulders of giants

node-typedjs would not be possible without open-source software such as

  • TypedJS by Ethan Fast
  • esprima by Ariya Hidayat

Resources

  • Fork this project on GitHub
  • Report Issues
  • Type Signatures Reference Manual
  • TypedJS website
  • Follow me on Twitter

License

MIT LICENSE

    • #javascript
    • #coffeescript
    • #type safety
    • #haskell
    • #type signatures
    • #code quality
    • #testing
    • #unit tests
    • #contracts
    • #node.js
    • #static typing
  • 5 years ago
  • 42
  • Comments
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

Adding a CoffeeScript project to Travis-CI

Say you have this project you wrote in CoffeeScript and you want to add it to Travis-CI

but you do not want to include the compiled output in your code repository. Well, you will need to tell Travis to compile your project first before running the tests otherwise they would fail.

But how?

Add this to your .travis.yml

before_script:
  coffee -c -o lib src

Commands under before_script run before the unit tests are ran. So use CoffeeScript to compile your project before running the tests.

You will obviously need coffee-script as a dev_dependency in your package.json

"devDependencies": {
  "coffee-script": "latest"
}

Alternatively you can just use this Cakefile and add the following to your package.json instead

"scripts": {
  "test": "cake test"
}
    • #coffeescript
    • #node.js
    • #travis-ci
    • #continuous integration
    • #cakefile
    • #npm
  • 5 years ago
  • 4
  • Comments
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

Security questions are not secure

As I was signing up for a service today, which deals with money, I was asked to go through an extensive process in the name of security.

There was a special “security picture” assigned to me to protect me from phishing.

Then there was the ridiculous password requirements:

  • 8-14 characters in length
  • Must contain 2 numbers and an uppercase letter

But aside from that nonsense, the part that bothered me the most was when they asked me to set up “security questions”, you know, in case I forget my ridiculous password.

My question options were limited to a few, including these:

  • What is your current best friend’s name?
  • In what city were you married?
  • What is your favorite book?
  • What hospital were you born in?
  • Who is your favorite athlete?
  • What was your high school mascot?

All of which I can easily pull the answers to from a social media site, public records, or social engineering.

Which leads me to lie on all the questions in an attempt to be “secure”.

Then I’ll not only forget my stupid 8-14 character random password with two numbers in it (was it 29 or 41?) but I’ll also forget the lies I used to answer (was I married on the moon or in the pacific ocean?).

In which I case I’m sure they’ll have a mechanism where I can contact customer support and just tell them my zip code and I’ll be granted access to my account. Everything will be ok.

    • #security
    • #rant
    • #passwords
    • #phishing
    • #social engineering
  • 5 years ago
  • 12
  • Comments
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+
Page 1 of 9
← Newer • Older →

About

Software Engineering, Music, Sports
  • @goatslacker on Twitter
  • Facebook Profile
  • goatslacker on Last.fm
  • goatslacker on Grooveshark
  • Linkedin Profile
  • goatslacker on github

Twitter

loading tweets…

Posts I like

See more →
  • Photoset via staff
    Photoset via staff
  • Video via izs
    Video

    Watch this video. I really like a lot of what he has to say. Two main comments:

    1. 165 Exceptions in the standard library, is enough!? Are you...
    Video via izs
  • RSS
  • Random
  • Archive
  • Ask me anything
  • Mobile

Josh Perez.

Effector Theme — Tumblr themes by Pixel Union