Skip to content

Commit

Permalink
add tests and CI job (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
staltz committed Nov 22, 2023
1 parent 70d2940 commit 4bd25a9
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
24 changes: 24 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: CI

on:
push:
branches: [main]
pull_request:

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 10

strategy:
matrix:
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
"description": "libsodium secretstream as a pull stream",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "node --test"
},
"files": [
"src/**.js"
],
"repository": {
"type": "git",
"url": "git+https://github.com/ahdinosaur/pull-secretstream.git"
Expand Down
28 changes: 28 additions & 0 deletions test/basics.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const test = require('node:test')
const assert = require('node:assert')
const pull = require('pull-stream')
const { randomBytes } = require('crypto')
const { KEYBYTES, createBoxStream, createUnboxStream } = require('../')

test('test basic boxStream and unboxStream', async (t) => {
// generate a random secret, `KEYBYTES` bytes long.
const key = randomBytes(KEYBYTES)

const plaintext1 = Buffer.from('hello world')

await new Promise((resolve, reject) => {
pull(
pull.values([plaintext1]),
createBoxStream(key),
pull.through((ciphertext) => {
console.log('Encrypted: ', ciphertext)
}),
createUnboxStream(key),
pull.concat((err, plaintext2) => {
if (err) return reject(err)
assert.equal(plaintext2.toString('ascii'), plaintext1.toString('ascii'))
resolve()
}),
)
})
})

0 comments on commit 4bd25a9

Please sign in to comment.