Skip to content

Commit

Permalink
Merge pull request #17 from JHWelch/require-node-20
Browse files Browse the repository at this point in the history
Require node 20
  • Loading branch information
JHWelch authored Oct 20, 2024
2 parents 2503bab + ff0a393 commit a7b0985
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 33 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/qc-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
node-version-file: .nvmrc

- name: Install Dependencies
run: npm install
Expand All @@ -41,7 +41,7 @@ jobs:
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
node-version-file: .nvmrc

- name: Install Dependencies
run: npm install
Expand Down
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
2 changes: 1 addition & 1 deletion MMM-CTA.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Module.register('MMM-CTA', {
stops: [],
},

requiresVersion: '2.2.0',
requiresVersion: '2.28.0',

loading: true,

Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ In ~/MagicMirror/modules
git clone https://github.com/JHWelch/MMM-CTA.git
```

Install NPM dependencies
```sh
cd MMM-CTA
npm install --production
```
No dependencies are required for usage. See below for development dependencies.

## Obtaining CTA API keys

Expand Down Expand Up @@ -97,6 +93,8 @@ The `stops` option is an array of objects. Each object represents a stop to disp

### Installation

Install dev dependencies

```sh
npm install
```
Expand Down
1 change: 0 additions & 1 deletion __mocks__/node-fetch.js

This file was deleted.

2 changes: 1 addition & 1 deletion __tests__/MMM-CTA.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ it('has a default config', () => {
});

it('requires expected version', () => {
expect(MMMCTA.requiresVersion).toBe('2.2.0');
expect(MMMCTA.requiresVersion).toBe('2.28.0');
});

it('inits module in loading state', () => {
Expand Down
47 changes: 27 additions & 20 deletions __tests__/node_helper.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
const { default: fetchMock } = require('fetch-mock');

/* eslint-disable global-require */
beforeAll(() => {
require('../__mocks__/logger');
require('../__mocks__/node-fetch');
});

const mockBusFetch = (fetch) => fetch.mockReturnValueOnce(Promise.resolve({
json: () => Promise.resolve({
afterEach(() => {
fetchMock.restore();
});

const mockBusFetch = () => fetchMock.get(
'http://www.ctabustracker.com/bustime/api/v2/getpredictions?key=BUS_API_KEY&stpid=1234&top=5&format=json',
{
'bustime-response': {
prd: [
{
Expand Down Expand Up @@ -48,11 +54,12 @@ const mockBusFetch = (fetch) => fetch.mockReturnValueOnce(Promise.resolve({
},
],
},
}),
}));
},
);

const mockBusFetchNoService = (fetch) => fetch.mockReturnValueOnce(Promise.resolve({
json: () => Promise.resolve({
const mockBusFetchNoService = () => fetchMock.get(
'http://www.ctabustracker.com/bustime/api/v2/getpredictions?key=BUS_API_KEY&stpid=1234&top=5&format=json',
{
'bustime-response': {
error: [
{
Expand All @@ -61,11 +68,12 @@ const mockBusFetchNoService = (fetch) => fetch.mockReturnValueOnce(Promise.resol
},
],
},
}),
}));
},
);

const mockTrainFetch = (fetch) => fetch.mockReturnValueOnce(Promise.resolve({
json: () => Promise.resolve({
const mockTrainFetch = () => fetchMock.get(
'http://lapi.transitchicago.com/api/1.0/ttarrivals.aspx?key=TRAIN_API_KEY&mapid=1234&max=5&outputType=json',
{
ctatt: {
tmst: '2024-01-20T21:23:30',
errCd: '0',
Expand Down Expand Up @@ -115,16 +123,15 @@ const mockTrainFetch = (fetch) => fetch.mockReturnValueOnce(Promise.resolve({
},
],
},
}),
}));
},
);

let helper;
let fetch;

beforeEach(() => {
helper = require('../node_helper');
Log = require('logger'); // eslint-disable-line import/no-unresolved
fetch = require('node-fetch'); // eslint-disable-line import/no-unresolved

helper.setName('MMM-CTA');
});
Expand All @@ -134,13 +141,13 @@ describe('socketNotificationReceived', () => {
it('does nothing', () => {
helper.socketNotificationReceived('NOT-CTA-FETCH', {});

expect(fetch).not.toHaveBeenCalled();
expect(fetchMock.calls).toHaveLength(0);
});
});

describe('passed proper train config', () => {
beforeEach(() => {
mockTrainFetch(fetch);
mockTrainFetch();

helper.socketNotificationReceived('MMM-CTA-FETCH', {
trainApiKey: 'TRAIN_API_KEY',
Expand All @@ -156,7 +163,7 @@ describe('socketNotificationReceived', () => {
});

it('calls train API with passed arguments', () => {
expect(fetch).toHaveBeenCalledWith(
expect(fetchMock.calls(true)[0][0]).toBe(
'http://lapi.transitchicago.com/api/1.0/ttarrivals.aspx?key=TRAIN_API_KEY&mapid=1234&max=5&outputType=json',
);
});
Expand Down Expand Up @@ -201,7 +208,7 @@ describe('socketNotificationReceived', () => {
});

it('calls bus API with passed arguments', () => {
expect(fetch).toHaveBeenCalledWith(
expect(fetchMock.calls()[0][0]).toBe(
'http://www.ctabustracker.com/bustime/api/v2/getpredictions?key=BUS_API_KEY&stpid=1234&top=5&format=json',
);
});
Expand Down Expand Up @@ -254,11 +261,11 @@ describe('socketNotificationReceived', () => {
});

it('calls bus API with passed arguments', () => {
expect(fetch).toHaveBeenCalledWith(
expect(fetchMock.calls()[0][0]).toBe(
'http://lapi.transitchicago.com/api/1.0/ttarrivals.aspx?key=TRAIN_API_KEY&mapid=1234&max=5&outputType=json',
);

expect(fetch).toHaveBeenCalledWith(
expect(fetchMock.calls()[1][0]).toBe(
'http://www.ctabustracker.com/bustime/api/v2/getpredictions?key=BUS_API_KEY&stpid=1234&top=5&format=json',
);
});
Expand Down
1 change: 0 additions & 1 deletion node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* MIT Licensed.
*/

const fetch = require('node-fetch');
const Log = require('logger');
const NodeHelper = require('node_helper');

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
},
"author": "Jordan Welch",
"license": "MIT",
"dependencies": {
"node-fetch": "^2.6.12"
"engines": {
"node": ">=20.0.0"
},
"devDependencies": {
"eslint": "^8.43.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.27.5",
"fetch-mock": "^11.1.5",
"jest": "^29.5.0",
"nunjucks": "^3.2.4"
},
Expand Down

0 comments on commit a7b0985

Please sign in to comment.