Skip to content

Commit

Permalink
restructure tests and consolidate logic
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-haynes committed Aug 10, 2019
1 parent 6965b1b commit cf7b08c
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 43 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha src/**/.test/*"
"test": "mocha tests/*"
},
"author": "",
"license": "ISC",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
const Promise = require('bluebird');
const { assert } = require('chai');
const sinon = require('sinon');

const PinToggle = require('../pin_toggle');

sinon.usingPromise(Promise);
const PinToggle = require('../../src/composables/pin_toggle');
const { assert, sinon } = require('../utils');

const MockPinToggle = PinToggle.props({
pin: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
const { assert } = require('chai');
const sinon = require('sinon');

const { LogLevel } = require('../../constants');
const { mockPinController } = require('../../tests/mocks');
const Thermostat = require('../../thermostat/thermostat');
const Controller = require('../controller');
const { LogLevel } = require('../../src/constants/index');
const Thermostat = require('../../src/thermostat/thermostat');
const Controller = require('../../src/controller/controller');
const { mockPinController } = require('../mocks');
const { assert, sinon } = require('../utils');

const TARGET_TEMP = 152;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
const Promise = require('bluebird');
const { assert } = require('chai');
const sinon = require('sinon');

const { mockPinController } = require('../../tests/mocks');

sinon.usingPromise(Promise);
const { mockPinController } = require('../mocks');
const { assert } = require('../utils');

const P_INDEX = 10;

Expand Down
17 changes: 4 additions & 13 deletions src/gpio/.test/pin.js → tests/gpio/pin.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
const Promise = require('bluebird');
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
const sinon = require('sinon');

const { PinState } = require('../../constants');
const { mockPin } = require('../../tests/mocks');
const Pin = require('../pin');

sinon.usingPromise(Promise);

chai.use(chaiAsPromised);
const { assert } = chai;
const { PinState } = require('../../src/constants/index');
const Pin = require('../../src/gpio/pin');
const { mockPin } = require('../mocks');
const { assert } = require('../utils');

const P_INDEX = 10;

Expand Down
8 changes: 4 additions & 4 deletions src/tests/mocks.js → tests/mocks.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const sinon = require('sinon');

const { LogLevel } = require('../constants');
const PinController = require('../controller/pin_controller');
const GPIO = require('../gpio/gpio');
const Pin = require('../gpio/pin');
const { LogLevel } = require('../src/constants/index');
const PinController = require('../src/controller/pin_controller');
const GPIO = require('../src/gpio/gpio');
const Pin = require('../src/gpio/pin');

const mockGPIOMethod = (rejects) =>
rejects
Expand Down
4 changes: 2 additions & 2 deletions src/thermostat/.test/pid.js → tests/thermostat/pid.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { assert } = require('chai');
const sinon = require('sinon');

const { LogLevel, PIDState } = require('../../constants');
const PID = require('../pid');
const { LogLevel, PIDState } = require('../../src/constants/index');
const PID = require('../../src/thermostat/pid');

const PID_TARGET = 100;
const PID_VALUE = 50;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
const sinon = require('sinon');

const { LogLevel } = require('../../constants');
const Thermometer = require('../thermometer');
const { LogLevel } = require('../../src/constants/index');
const Thermometer = require('../../src/thermostat/thermometer');

chai.use(chaiAsPromised);
const { assert } = chai;
Expand Down
15 changes: 15 additions & 0 deletions tests/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const Promise = require('bluebird');
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
const sinon = require('sinon');

sinon.usingPromise(Promise);

chai.use(chaiAsPromised);

const { assert } = chai;

module.exports = {
assert,
sinon,
};

0 comments on commit cf7b08c

Please sign in to comment.