-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests and integrate with CI
- Loading branch information
1 parent
e2646c5
commit 114f3ea
Showing
3 changed files
with
96 additions
and
2 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,36 @@ | ||
name: Test and Release | ||
|
||
on: push | ||
|
||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
JSR_TOKEN: ${{ secrets.JSR_TOKEN }} | ||
|
||
permissions: | ||
contents: write | ||
issues: write | ||
id-token: write | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-24.04 | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: "22.x" | ||
cache: "npm" | ||
|
||
- name: Install dependencies | ||
run: npm ci --no-audit | ||
|
||
- name: Test | ||
run: npm test | ||
|
||
- name: Semantic release | ||
continue-on-error: true | ||
run: | | ||
npm install -D @sebbo2002/semantic-release-jsr | ||
npx semantic-release |
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,47 @@ | ||
import assert from 'node:assert' | ||
import { describe, it, mock } from 'node:test' | ||
import { waitForIt } from './waitForIt.ts' | ||
|
||
describe('waitForIt()', () => { | ||
it('returns the result of a successful promise', async () => { | ||
const expectedResult = 'success' | ||
const succeeding = mock.fn(() => Promise.resolve(expectedResult)) | ||
|
||
const result = await waitForIt(succeeding) | ||
|
||
assert.strictEqual(result, expectedResult) | ||
assert.equal(succeeding.mock.calls.length, 1) | ||
}) | ||
|
||
it('returns the error of a failing promise', async () => { | ||
const expectedTries = 2 | ||
const expectedError = new Error('failure') | ||
const failing = mock.fn(() => Promise.reject(expectedError)) | ||
|
||
try { | ||
await waitForIt(failing, expectedTries) | ||
assert.fail('Expected waitForIt to throw an error') | ||
} catch (error) { | ||
assert.strictEqual(error, expectedError) | ||
} | ||
assert.equal(failing.mock.calls.length, expectedTries) | ||
}) | ||
|
||
it('returns the result after failing twice and succeeding on the third try', async () => { | ||
const expectedResult = 'success' | ||
const expectedTries = 3 | ||
let callCount = 0 | ||
const fn = mock.fn(() => { | ||
callCount++ | ||
if (callCount < expectedTries) { | ||
return Promise.reject(new Error('failure')) | ||
} | ||
return Promise.resolve(expectedResult) | ||
}) | ||
|
||
const result = await waitForIt(fn, expectedTries) | ||
|
||
assert.strictEqual(result, expectedResult) | ||
assert.equal(fn.mock.calls.length, expectedTries) | ||
}) | ||
}) |