1
0

rom_comm_test.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. 'use strict';
  2. const expect = require('chai').expect;
  3. const RomComm = require('../back-end/rom_comm');
  4. describe('ESP8266', () => {
  5. const boards = require('../back-end/boards');
  6. it('defaults to the Esp12', () => {
  7. var esp = new RomComm({
  8. portName: 'TEST'
  9. });
  10. expect(esp.board).to.be.an.instanceof(boards.Esp12);
  11. });
  12. });
  13. describe('RomComm', () => {
  14. const esp = new RomComm({
  15. portName: "/dev/ttys000",
  16. baud: 9600
  17. });
  18. describe('handleResponse', () => {
  19. // Helper function for response creation, takes *args
  20. const handle = function() {
  21. let data = new Buffer(Uint8Array.from(arguments));
  22. return esp.handleResponse(data);
  23. }
  24. const SUCCESS = new Buffer([0x00, 0x00]);
  25. it('ignores missing headers', () => {
  26. expect(handle(1, 8, 2)).to.be.false;
  27. });
  28. it('ensures direction', () => {
  29. expect(handle(114, 108, 0, 108, 156, 158, 124, 0, 140)).to.be.false;
  30. });
  31. it('emits on success', done => {
  32. esp.on('RECEIVED-FLASH_DOWNLOAD_BEGIN', body => {
  33. expect(body).to.deep.equal(SUCCESS);
  34. done();
  35. });
  36. // Result from flash download begin
  37. let result = handle(1, 2, 2, 0, 7, 7, 18, 32, 0 ,0);
  38. expect(result).to.be.true;
  39. })
  40. });
  41. });