Skip to content

Commit

Permalink
Adds testcases and working examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
tcr committed May 23, 2014
1 parent c47ec3b commit 5c7c742
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
node_modules
2 changes: 1 addition & 1 deletion examples/rfid.js
Expand Up @@ -8,7 +8,7 @@ then logs its UID to the console.
// http://creativecommons.org/publicdomain/zero/1.0/

var tessel = require('tessel');
var rfid = require('../').use(tessel.port('A')); // Replace '../' with 'rfid-pn532' in your own code
var rfid = require('../').use(tessel.port['A']); // Replace '../' with 'rfid-pn532' in your own code

rfid.on('ready', function (version) {
console.log('Ready to read RFID card');
Expand Down
12 changes: 10 additions & 2 deletions package.json
Expand Up @@ -4,10 +4,18 @@
"description": "Library to run the PN532 RFID Reader",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "./testsuite.js"
},
"hardware": {
"./examples": false
"./examples": false,
"tape": false,
"tap": false,
"shelljs": false
},
"devDependencies": {
"tape": "~2.3.2",
"tap": "git+https://github.com/tcr/node-tap.git#3cb76e",
"shelljs": "~0.3.0"
},
"repository": "",
"author": "Jon McKay <jon@technical.io>",
Expand Down
25 changes: 25 additions & 0 deletions test/readcard.js
@@ -0,0 +1,25 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/

var portname = process.argv[2] || 'A';
console.log('# connecting to port', portname);

var tessel = require('tessel');
var rfid = require('../').use(tessel.port[portname]);

console.log('1..2');

rfid.on('ready', function (version) {
console.log('# ready to read RFID card');
console.log('ok')

rfid.on('data', function(uid) {
console.log('# uid', uid);
console.log(uid.length == 4 ? 'ok' : 'not ok', '- length of returned data');
rfid.disable();
});
});

rfid.on('error', function (err) {
console.log('not ok', '-', err);
})
10 changes: 10 additions & 0 deletions testsuite.js
@@ -0,0 +1,10 @@
#!/usr/bin/env node

require('shelljs/global');

var port = process.env.RFID_PORT || 'A';
var cmd = './node_modules/.bin/tap -e "tessel run {} ' + port + '" test/*.js';

// execute
cd(__dirname)
process.exit(exec(cmd).code);

0 comments on commit 5c7c742

Please sign in to comment.