Skip to content

Commit

Permalink
fix(tests): use Buffer.alloc to generate correct byte-size texts
Browse files Browse the repository at this point in the history
  • Loading branch information
jankapunkt committed Nov 24, 2023
1 parent 6b0d9cc commit 6ce38a1
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions tests/unit.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
initScope,
createUtteranceClass
} from './test-helpers.js'
import crypto from 'crypto'

describe('unit tests', function () {
afterEach(function () {
Expand Down Expand Up @@ -524,20 +523,16 @@ describe('unit tests', function () {
globalThis.SpeechSynthesisUtterance = SpeechSynthesisUtterance
globalThis.speechSynthesis = speechSynthesis

crypto.randomBytes(4096, (err, buf) => {
if (err) {
return done(err)
}

const text = buf.toString('utf-8')
EasySpeech.init()
.catch(e => done(e))
.then(() => {
expect(() => EasySpeech.speak({ text }))
.to.throw('EasySpeech: text exceeds max length of 4096 bytes.')
done()
})
})
const buffer = Buffer.alloc(4097, '0')
const decoder = new TextDecoder('UTF-8')
const text = decoder.decode(buffer)
EasySpeech.init()
.catch(e => done(e))
.then(() => {
expect(() => EasySpeech.speak({ text }))
.to.throw('EasySpeech: text exceeds max length of 4096 bytes.')
done()
})
})
it('speaks, if at least some text is given', function (done) {
const SpeechSynthesisUtterance = class SpeechSynthesisUtterance {
Expand Down

0 comments on commit 6ce38a1

Please sign in to comment.