-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from HarryPeach/dev
v0.3.0
- Loading branch information
Showing
9 changed files
with
245 additions
and
55 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# This is a basic workflow to help you get started with Actions | ||
|
||
name: CI | ||
|
||
# Controls when the action will run. Triggers the workflow on push or pull request | ||
# events but only for the master branch | ||
on: | ||
push: | ||
branches: [dev] | ||
pull_request: | ||
branches: [master] | ||
|
||
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | ||
jobs: | ||
# This workflow contains a single job called "build" | ||
build: | ||
# The type of runner that the job will run on | ||
runs-on: ubuntu-latest | ||
|
||
# Steps represent a sequence of tasks that will be executed as part of the job | ||
steps: | ||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Setup Deno environment | ||
uses: denolib/[email protected] | ||
|
||
- name: Run Deno Tests | ||
run: deno test -A |
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 |
---|---|---|
|
@@ -2,7 +2,9 @@ | |
|
||
> Simple terminal spinners for Deno 🦕 | ||
`Version 0.2.0` | ||
`Version 0.3.0` | ||
|
||
![](https://github.com/HarryPeach/kia/workflows/CI/badge.svg) | ||
|
||
![weather.ts example](https://user-images.githubusercontent.com/4750998/81313185-710ac900-907f-11ea-9735-d623559d08f6.gif) | ||
|
||
|
@@ -12,18 +14,20 @@ | |
## Usage | ||
|
||
```typescript | ||
import Kia from "./mod.ts"; | ||
import Kia from "https://deno.land/x/[email protected]/mod.ts"; | ||
|
||
const kia = new Kia("Hello"); | ||
await kia.start(); | ||
kia.start(); | ||
// Some async action that'll take some time | ||
await kia.success("Action completed"); | ||
kia.success("Action completed"); | ||
``` | ||
|
||
More thorough examples are available in the [examples folder](https://github.com/HarryPeach/kia/tree/master/examples) | ||
|
||
## API | ||
|
||
### kia() | ||
|
||
### kia(text) | ||
|
||
### kia(options) | ||
|
@@ -94,6 +98,14 @@ Default: false | |
|
||
Whether or not to display a cursor when the spinner is active | ||
|
||
##### writer | ||
|
||
Type: Deno.Writer | ||
|
||
Default: Deno.stdout | ||
|
||
The resource to output to. This can be anything that uses the Writer interface including stdout, stderr, and files. | ||
|
||
### Instance | ||
|
||
#### .start(text?) | ||
|
@@ -104,13 +116,15 @@ Starts the spinner. Optionally sets the text at the same time. Returns Kia insta | |
|
||
Stops the spinner and clears the line. Returns Kia instance. | ||
|
||
#### .set(text) | ||
|
||
#### .set(options) | ||
|
||
Allows you to change the spinners options. Returns Kia instance. | ||
|
||
```typescript | ||
const kia = new Kia("Hello"); | ||
await kia.set({ text: "Goodbye", color: "Red" }); | ||
kia.set({ text: "Goodbye", color: "Red" }); | ||
``` | ||
|
||
#### .succeed(text?) | ||
|
@@ -127,12 +141,20 @@ Stops the spinner, and returns a message with the current text or the provided ` | |
|
||
Stops the spinner, and returns a message with the current text or the provided `text` as well as the preceding flair/icon. Returns Kia instance. | ||
|
||
#### .stopAndPersist(options) | ||
|
||
Stops the spinner and holds it in a static state. Returns the instance. | ||
|
||
#### .renderNextFrame() | ||
|
||
Renders the next frame of the spinner when it is stopped (i.e. can only be run after .stopAndPersist()). | ||
|
||
### forPromise(action, text) | ||
|
||
### forPromise(action, options) | ||
|
||
```typescript | ||
import { forPromise } from "./mod.ts"; | ||
import { forPromise } from "https://deno.land/x/[email protected]/mod.ts"; | ||
|
||
forPromise( | ||
async () => { | ||
|
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 +1 @@ | ||
export * as Colors from "https://deno.land/std/fmt/colors.ts"; | ||
export * as Colors from "https://deno.land/std@0.52.0/fmt/colors.ts"; |
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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import Kia from "./mod.ts"; | ||
import { | ||
assertThrowsAsync, | ||
assertThrows, | ||
} from "https://deno.land/[email protected]/testing/asserts.ts"; | ||
import { expect } from "https://deno.land/x/expect/mod.ts"; | ||
class TestWriter implements Deno.WriterSync { | ||
buffer: string[] = []; | ||
writeSync(p: Uint8Array): number { | ||
this.buffer.push(new TextDecoder().decode(p)); | ||
return p.length; | ||
} | ||
} | ||
|
||
function sleep(ms: number) { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} | ||
|
||
Deno.test("spinner isSpinning when running", () => { | ||
const kia = new Kia(); | ||
kia.start(); | ||
expect(kia.isSpinning()).toEqual(true); | ||
kia.stop(); | ||
}); | ||
|
||
Deno.test("spinner !isSpinning when not running", () => { | ||
const kia = new Kia().start(); | ||
kia.stop(); | ||
expect(kia.isSpinning()).toEqual(false); | ||
}); | ||
|
||
Deno.test("stopAndPersist stops the spinner output", async () => { | ||
const testWriter = new TestWriter(); | ||
const kia = new Kia({ text: "", writer: testWriter }).start(); | ||
kia?.stopAndPersist(); | ||
|
||
// Wait and check that there are no extra prints | ||
const sizeAfterStop = testWriter.buffer.length; | ||
await sleep(1000); | ||
expect(kia?.isSpinning()).toEqual(false); | ||
expect(sizeAfterStop).toEqual(testWriter.buffer.length); | ||
}); | ||
|
||
Deno.test("renderNextFrame() advances the spinner", () => { | ||
const testWriter = new TestWriter(); | ||
const kia = new Kia({ | ||
text: "", | ||
writer: testWriter, | ||
}).start(); | ||
kia.stopAndPersist(); | ||
|
||
const sizeAfterStop = testWriter.buffer.length; | ||
kia.renderNextFrame(); | ||
|
||
// Check that the frame is advancing | ||
const sizeAfterNextStop = testWriter.buffer.length; | ||
expect(sizeAfterStop).toBeLessThan(sizeAfterNextStop); | ||
|
||
// Check that each frame is only advancing once | ||
kia.renderNextFrame(); | ||
expect(sizeAfterNextStop - sizeAfterStop).toEqual( | ||
testWriter.buffer.length - sizeAfterNextStop | ||
); | ||
}); | ||
|
||
Deno.test("check renderNextFrame can't be called if spinner is running", () => { | ||
const kia = new Kia().start(); | ||
assertThrows(() => { | ||
kia.renderNextFrame(); | ||
}, Error); | ||
kia.stop(); | ||
}); | ||
|
||
Deno.test("set() changes the kia options", () => { | ||
const testWriter = new TestWriter(); | ||
const SEARCH_KEY = "XXX"; | ||
|
||
const kia = new Kia({ | ||
text: "sample", | ||
writer: testWriter, | ||
}).start(); | ||
|
||
// Change the text to the search key and then check if it has actually changed | ||
kia.stopAndPersist(); | ||
kia.set({ text: SEARCH_KEY }); | ||
kia.renderNextFrame(); | ||
|
||
let inArray = false; | ||
testWriter.buffer.forEach((item) => { | ||
if (item.includes(SEARCH_KEY)) { | ||
inArray = true; | ||
} | ||
}); | ||
|
||
expect(inArray).toBe(true); | ||
}); |
Oops, something went wrong.