diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..c9eb255 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,8 @@ +sudo: false +language: node_js +node_js: + - '4' + - '6' + - '7' + - '8' +after_success: npm run coverage diff --git a/fixtures/test.ino b/fixtures/test.ino new file mode 100644 index 0000000..32f56ba --- /dev/null +++ b/fixtures/test.ino @@ -0,0 +1,7 @@ +void setup() { + +} + +void loop() { + +} diff --git a/index.js b/index.js index 816b0cf..609731d 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,4 @@ +'use strict'; const request = require('request'); const semver = require('semver'); @@ -35,12 +36,14 @@ const MIRRORS = [{ /** * Initialize a new `Arduino` * - * @param {String} version + * @param {Object} [opts] * @api public */ -function arduino(version) { - version = version || 'latest'; +function arduino(opts) { + const version = opts.version || 'latest'; + const binPath = opts.path || BIN_PATH; + const binSlug = opts.tag ? ('-' + opts.tag) : ''; let inited = false; let bin; @@ -174,7 +177,7 @@ function arduino(version) { * @api private */ function init(version) { - bin = manager(BIN_PATH, 'arduino-' + version); + bin = manager(binPath, 'arduino-' + version + binSlug); MIRRORS.forEach(mirror => { bin.src(mirror.uri.replace('{{version}}', version), mirror.os, mirror.arch); diff --git a/test.js b/test.js index 40e6a13..6f7bcb0 100644 --- a/test.js +++ b/test.js @@ -1,10 +1,12 @@ import fs from 'fs'; +import path from 'path'; import pify from 'pify'; import test from 'ava'; import arduino from './'; +const fixture = path.join.bind(path, __dirname, 'fixtures'); test('arduino loads arduino latest', async t => { - const arduinoObj = arduino(); + const arduinoObj = arduino({tag: 'load'}); const err = await pify(arduinoObj.load)(); t.is(err, undefined); const accessErr = await pify(fs.access)(arduinoObj.binary(), fs.constants.X_OK); @@ -12,8 +14,23 @@ test('arduino loads arduino latest', async t => { }); test('arduino fails to download a version', async t => { - const arduinoObj = arduino('🦄'); + const arduinoObj = arduino({version: '🦄', tag: 'fail'}); const err = await t.throws(pify(arduinoObj.load)()); t.is(err.statusCode, 404); }); +test('arduino run fail on test test.ino', async t => { + const arduinoObj = arduino({tag: 'run'}); + pify(arduinoObj.load)(); + const err = await pify(arduinoObj.run)(['--verify', fixture('test.ino')]); + t.is(err.failed, false); +}); + +test('arduino unload on test latest version', async t => { + const arduinoObj = arduino({tag: 'unload'}); + pify(arduinoObj.load)(); + const err = await pify(arduinoObj.unload)(); + t.is(err, undefined); + const accessErr = await t.throws(pify(fs.access)(arduinoObj.binary(), fs.constants.F_OK)); + t.is(accessErr.code, 'ENOENT'); +});