From 98a6ce0cc9c01a1ea285326beba1c411099c6232 Mon Sep 17 00:00:00 2001 From: chqma Date: Mon, 10 Jul 2017 17:42:19 +0200 Subject: [PATCH 1/7] Add unload test --- test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test.js b/test.js index 40e6a13..7d50de0 100644 --- a/test.js +++ b/test.js @@ -17,3 +17,10 @@ test('arduino fails to download a version', async t => { t.is(err.statusCode, 404); }); +test('arduino unload on test latest version', async t => { + const arduinoObj = arduino(); + 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'); +}); From 25993e4c63d5fc399b28a9cd7f499e0406e3a0eb Mon Sep 17 00:00:00 2001 From: chqma Date: Mon, 10 Jul 2017 19:39:26 +0200 Subject: [PATCH 2/7] Fix arduino takes optional opts --- index.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 816b0cf..5e06413 100644 --- a/index.js +++ b/index.js @@ -35,12 +35,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 +176,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); From 1463fa9f6b00d3f4eab192a097f6256116fefa1c Mon Sep 17 00:00:00 2001 From: chqma Date: Mon, 10 Jul 2017 19:39:59 +0200 Subject: [PATCH 3/7] Update tests with opts and run --- test.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/test.js b/test.js index 7d50de0..fe331f5 100644 --- a/test.js +++ b/test.js @@ -4,7 +4,7 @@ import test from 'ava'; import arduino from './'; 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,13 +12,21 @@ 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', 'fixtures\\test.ino']); + t.is(err.failed, false); +}); + test('arduino unload on test latest version', async t => { - const arduinoObj = arduino(); + 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)); From 4431f003908fa45bd3e7f368c7d8a95c5542ad87 Mon Sep 17 00:00:00 2001 From: chqma Date: Mon, 10 Jul 2017 19:40:29 +0200 Subject: [PATCH 4/7] Add test.ino example file --- fixtures/test.ino | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 fixtures/test.ino 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() { + +} From db7957db40e521dc33fa610f211a3161572d7d17 Mon Sep 17 00:00:00 2001 From: Simone Primarosa Date: Mon, 10 Jul 2017 21:18:03 +0200 Subject: [PATCH 5/7] Create .travis.yml --- .travis.yml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .travis.yml 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 From 59ec2a9a25cadde93af3d57c96ca2f4e6c73fd07 Mon Sep 17 00:00:00 2001 From: Simone Primarosa Date: Mon, 10 Jul 2017 21:30:25 +0200 Subject: [PATCH 6/7] Add missing strict mode on index.js --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index b5a9bc9..27451df 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,4 @@ +'use strict'; const request = require('request'); const semver = require('semver'); From 600ef64d8015db9a8766cebdc65ea56a89b79d24 Mon Sep 17 00:00:00 2001 From: chqma Date: Mon, 10 Jul 2017 21:46:56 +0200 Subject: [PATCH 7/7] Fix harcoded path --- test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test.js b/test.js index fe331f5..6f7bcb0 100644 --- a/test.js +++ b/test.js @@ -1,8 +1,10 @@ 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({tag: 'load'}); const err = await pify(arduinoObj.load)(); @@ -20,7 +22,7 @@ test('arduino fails to download a version', async t => { 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', 'fixtures\\test.ino']); + const err = await pify(arduinoObj.run)(['--verify', fixture('test.ino')]); t.is(err.failed, false); });