App for the Fitbit Ionic, mostly to demonstrate how to incorporate unit testing and cross-platform file compatibility.
2018-08-24
Previous article
Fitbit-CoachUSA
Check-out the source here.
A small Fitbit app for the Ionic that displays bus times for me to reference. The motivation for this project was to see how I could run unit tests when developing, since at the time of writing, the Web-based Fitbit Studio does not lend itself to testing nor to source control and CI processes.
Testing
Tests are written in Jest, and can be found in the tests
directory.
Run them by issuing
JEST=JEST npm test
The weirdness with JEST=JEST
is because of some hacks needed to allow the code (including the Jest tests) to be compatible across you development/testing and production environments.
You’ll find references to the environment variable weirdness in app/index.js
. It’s also explained below in the hope that someone can come up with a better way.
Development Environment
I use Intellij and run the tests with the JEST=JEST
added in the run configuration when running Jest.
Environment variable weirdness explained
I wanted the same code for local and Fitbit web-based environments. Needing to reference index.js from the tests directory and noticing that Fitbit does not support some JS directives, I came up with this hack:
// Fitbit does not support process
try {
// Testing environment
documentPath = process.env.JEST ? "../tests/document" : "document";
clockPath = process.env.JEST ? "../tests/clock" : "clock";
} catch(error) {
// Production environment
documentPath = "document";
clockPath = "clock";
}
const document = require(documentPath);
const clock = require(clockPath);
and
// Fitbit does not support module
try {
module.exports = functions;
} catch(error) { }
Hack #1: Fitbit does not support process
so the whole thing is in a try-catch.
Hack #2: If I am local, then use the mock documetn
and clock
modules in the tests
directory, else use the real ones.
Hack #3: If I am in Fitbit, then fail on the process
and look for the modules in their production location.
Hack #4: Fitbit does not support module
, so catch it out.
Make this shit better!
License
Knock yourself out.
Contributing
Yes please.
Previous article
Filed under
Fitbit
Javascript
Jest
Unit testing
Other Tags
API GW
AWS
- Programming ESP32 using MQTT with AWS and FreeRTOS
- Quick AWS IoT Setup and test
- Set up AWS API GW with a Typescript authorizer and logging
- Use AWS CodePipline to execute CloudFormation templates
- Use GitHub Actions to deploy your SPA hosted on Amazon S3
- Use an AWS CloudFormation script to create and host an SPA on S3 with SSL and apex/subdomain redirection using CloudFront
- Writing an Alexa skill using Ruby and AWS Lambda (Part 0)
ActiveRecord
Agile
- A review of software development metrics
- Agile programme management brief
- An alternative to current product development metrics
- An alternative to the current product development governance model
- Command & Control Management - The Party Killer
- Document Driven Development
- Inceptions revisited
- Managing multiple stakeholders
- Returns Driven Development
- The tip of the (good) iceberg
Alexa
Analysis
Ansible
BDD
BLE
C
CAB
CloudFormation
- Set up AWS API GW with a Typescript authorizer and logging
- Use AWS CodePipline to execute CloudFormation templates
- Use GitHub Actions to deploy your SPA hosted on Amazon S3
- Use an AWS CloudFormation script to create and host an SPA on S3 with SSL and apex/subdomain redirection using CloudFront
- Writing an Alexa skill using Ruby and AWS Lambda (Part 0)
CloudFront
CloudWatch
Cross-compile
Cucumber
DevOps
Devops
DotNet
Embedded
Fitbit
GNU
GitHub Actions
Governance
How-to
Inception
IoT
Javascript
Jest
Lambda
Mac OS X
- Bluetooth Low Energy (BLE) Implementing a peripheral on Mac OS X
- Cross-compiling for Raspberry Pi on a Mac and debugging using NetBeans
- Drobo will not mount in Finder
- Quickie - ssh dynamic port forwarding to avoid unsecured public networks
- Remote compilation, execution and debugging Raspberry Pi from a Mac using NetBeans
- Weekend warrior - MacRuby and rSpec, Mac OS X Lion, Xcode V4.3.2
MacRuby
Metrics
MySQL
NetBeans
Objective-C
PMO
Product Management
- A path to accelerating value realization
- A review of software development metrics
- Agile programme management brief
- An alternative to current product development metrics
- An alternative to the current product development governance model
- Express initiative kickoff formula
- Inceptions revisited
- Managing multiple stakeholders
- Plan for value delivery
- Pre-prod activity - Futurespective
- Value Stream Mapping
- When planning, it's not only about relative complexity
Programme management
Project Management
- A path to accelerating value realization
- A review of software development metrics
- Agile programme management brief
- An alternative to current product development metrics
- An alternative to the current product development governance model
- Command & Control Management - The Party Killer
- Express initiative kickoff formula
- Inceptions revisited
- Managing multiple stakeholders
- Plan for value delivery
- Pre-prod activity - Futurespective
- Value Stream Mapping
- When planning, it's not only about relative complexity
Quality Assurance
Rails
Raspberry Pi
Remote compilation
Remote debugging
Remote execution
Risk Assessment
Route 53
Ruby
- Alexa on Rails - how to develop and test Alexa skills using Rails
- Arduino programming using Ruby, Cucumber & rSpec
- How to reconnect to a database when its connection was lost
- Oh, the places you'll go...
- Quick AWS IoT Setup and test
- Weekend warrior - MacRuby and rSpec, Mac OS X Lion, Xcode V4.3.2
- Writing an Alexa skill using Ruby and AWS Lambda (Part 0)