-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vadim Demedes
authored
Mar 4, 2019
1 parent
7f419e4
commit b30ce17
Showing
6 changed files
with
77 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
node_modules | ||
yarn.lock | ||
dist | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
language: node_js | ||
node_js: | ||
- '10' | ||
- '8' | ||
- '6' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,18 +9,18 @@ | |
"email": "[email protected]", | ||
"url": "github.com/vadimdemedes" | ||
}, | ||
"main": "dist/index.js", | ||
"main": "build/index.js", | ||
"engines": { | ||
"node": ">=6" | ||
"node": ">=8" | ||
}, | ||
"scripts": { | ||
"pretest": "npm run build", | ||
"test": "xo && ava", | ||
"build": "babel src --out-dir=dist", | ||
"prepublish": "npm run build" | ||
"build": "babel src --out-dir=build", | ||
"prepare": "npm run build" | ||
}, | ||
"files": [ | ||
"dist" | ||
"build" | ||
], | ||
"keywords": [ | ||
"ink", | ||
|
@@ -32,62 +32,38 @@ | |
"jsx", | ||
"react" | ||
], | ||
"peerDependencies": { | ||
"ink": "^0.5.0" | ||
}, | ||
"dependencies": { | ||
"cli-spinners": "^1.0.0", | ||
"object.omit": "^2.0.1", | ||
"prop-types": "^15.5.10" | ||
}, | ||
"devDependencies": { | ||
"ava": "^0.20.0", | ||
"babel-cli": "^6.24.1", | ||
"babel-plugin-transform-react-jsx": "^6.24.1", | ||
"@babel/cli": "^7.2.3", | ||
"@babel/core": "^7.3.3", | ||
"@babel/plugin-proposal-class-properties": "^7.3.3", | ||
"@babel/preset-react": "^7.0.0", | ||
"ava": "*", | ||
"babel-eslint": "^10.0.1", | ||
"delay": "^4.1.0", | ||
"eslint-config-xo-react": "^0.13.0", | ||
"eslint-plugin-react": "^7.1.0", | ||
"ink": "^0.5.0", | ||
"ink": "^2.0.0", | ||
"react": "^16.8.2", | ||
"sinon": "^2.3.6", | ||
"xo": "^0.18.2" | ||
"xo": "*" | ||
}, | ||
"babel": { | ||
"plugins": [ | ||
[ | ||
"transform-react-jsx", | ||
{ | ||
"pragma": "h", | ||
"useBuiltIns": true | ||
} | ||
] | ||
"@babel/plugin-proposal-class-properties" | ||
], | ||
"presets": [ | ||
"@ava/stage-4", | ||
"@babel/preset-react" | ||
] | ||
}, | ||
"ava": { | ||
"babel": { | ||
"presets": [ | ||
"@ava/stage-4" | ||
], | ||
"plugins": [ | ||
[ | ||
"transform-react-jsx", | ||
{ | ||
"pragma": "h", | ||
"useBuiltIns": true | ||
} | ||
] | ||
] | ||
} | ||
}, | ||
"xo": { | ||
"parser": "babel-eslint", | ||
"extends": [ | ||
"xo-react" | ||
], | ||
"rules": { | ||
"react/no-unused-prop-types": 1 | ||
}, | ||
"settings": { | ||
"react": { | ||
"pragma": "h" | ||
} | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,36 @@ | ||
import {h, build, Color} from 'ink'; | ||
import renderToString from 'ink/lib/render-to-string'; | ||
import {stub} from 'sinon'; | ||
import EventEmitter from 'events'; | ||
import React from 'react'; | ||
import {render} from 'ink'; | ||
import {spy} from 'sinon'; | ||
import spinners from 'cli-spinners'; | ||
import test from 'ava'; | ||
import delay from 'delay'; | ||
import Spinner from '.'; | ||
|
||
test('render', t => { | ||
let component; | ||
test('render spinner', async t => { | ||
const stdout = { | ||
columns: 100, | ||
write: spy() | ||
}; | ||
|
||
function setRef(ref) { | ||
component = ref; | ||
} | ||
const stdin = new EventEmitter(); | ||
stdin.setRawMode = () => {}; | ||
stdin.setEncoding = () => {}; | ||
stdin.pause = () => {}; | ||
|
||
const spinner = spinners.dots; | ||
let tree; | ||
const app = render(<Spinner/>, { | ||
stdout, | ||
stdin, | ||
debug: true | ||
}); | ||
|
||
for (let frame = 0; frame < spinner.frames.length; frame++) { | ||
tree = build(<Spinner ref={setRef}/>, tree); | ||
t.is(renderToString(tree), spinner.frames[frame]); | ||
await delay(spinner.frames.length * spinner.interval); | ||
app.unmount(); | ||
|
||
component.setState({ | ||
frame: frame + 1 | ||
}); | ||
} | ||
}); | ||
|
||
test('pass props to <Color>', t => { | ||
const spinner = spinners.dots; | ||
|
||
const actual = build(<Spinner green/>); | ||
const expected = build(<Color green>{spinner.frames[0]}</Color>); | ||
|
||
t.is(renderToString(actual), renderToString(expected)); | ||
}); | ||
|
||
test('spin', t => { | ||
stub(Spinner.prototype, 'setState'); | ||
|
||
let component; | ||
|
||
function setRef(ref) { | ||
component = ref; | ||
} | ||
|
||
build(<Spinner ref={setRef}/>); | ||
|
||
const spinner = spinners.dots; | ||
|
||
let frame = 1; | ||
let i = 0; | ||
|
||
while (i < spinner.frames.length * 2) { | ||
component.switchFrame(); | ||
|
||
t.deepEqual(component.setState.getCall(i).args[0], {frame}); | ||
component.state = {frame}; | ||
const allFrames = stdout.write.args.map(args => args[0]); | ||
const frames = [...new Set(allFrames)]; | ||
|
||
frame = frame === spinner.frames.length - 1 ? 0 : frame + 1; | ||
i++; | ||
} | ||
t.deepEqual(frames, spinner.frames); | ||
t.pass(); | ||
}); |