Skip to content

Commit 31d1039

Browse files
committed
Merge branch 'window-size' of https://github.com/whitneyrosenberg/create-twilio-function into whitneyrosenberg-window-size
1 parent 1a5186e commit 31d1039

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

packages/create-twilio-function/src/create-twilio-function/success-message.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { getPackageManager } = require('pkg-install');
22
const chalk = require('chalk');
3-
const windowSize = require('window-size');
3+
const getWindowSize = require('./window-size');
44
const wrap = require('wrap-ansi');
55

66
async function successMessage(config) {
@@ -20,7 +20,7 @@ Get started by running:
2020
2121
{blue cd ${config.name}}
2222
{blue ${packageManager} start}`,
23-
windowSize.get().width - 8,
23+
getWindowSize().width - 8,
2424
{ trim: false, hard: true }
2525
);
2626
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const windowSize = require('window-size');
2+
3+
function getWindowSize() {
4+
const defaultSize = { width: 80, height: 300 };
5+
let currentSize = windowSize.get();
6+
7+
if (!currentSize) {
8+
return defaultSize;
9+
}
10+
else {
11+
if(!currentSize.width) currentSize.width = defaultSize.width;
12+
if(!currentSize.height) currentSize.height = defaultSize.height;
13+
return currentSize;
14+
}
15+
}
16+
17+
module.exports = getWindowSize;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const getWindowSize = require('../src/create-twilio-function/window-size');
2+
3+
jest.mock('window-size', () => ({ get: jest
4+
.fn()
5+
.mockReturnValueOnce({ width: 40, height: 100 })
6+
.mockReturnValueOnce()
7+
.mockReturnValueOnce({ height: 250 })
8+
.mockReturnValueOnce({ width: 50 })
9+
.mockReturnValueOnce({ width: 80, height: 300 })
10+
}));
11+
12+
describe('getWindowSize', () => {
13+
it('gets a valid windowSize', () => {
14+
const windowSize = getWindowSize();
15+
expect(windowSize).toEqual({ width: 40, height: 100 });
16+
});
17+
it('cannot get a null windowSize', () => {
18+
const windowSize = getWindowSize();
19+
expect(windowSize).toEqual({ width: 80, height: 300 });
20+
});
21+
it('gets a windowSize without a width', () => {
22+
const windowSize = getWindowSize();
23+
expect(windowSize).toEqual({ width: 80, height: 250 });
24+
});
25+
it('gets a windowSize without a height', () => {
26+
const windowSize = getWindowSize();
27+
expect(windowSize).toEqual({ width: 50, height: 300 });
28+
});
29+
it('gets a windowSize without a width nor a height', () => {
30+
const windowSize = getWindowSize();
31+
expect(windowSize).toEqual({ width: 80, height: 300 });
32+
});
33+
});

0 commit comments

Comments
 (0)