Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated tap functions #380

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions test/e2e/toCanvas.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ test('toCanvas - no promise available', function (t) {
}
const canvasEl = createCanvas(200, 200)

t.throw(function () { QRCode.toCanvas() },
t.throws(function () { QRCode.toCanvas() },
'Should throw if no arguments are provided')

t.throw(function () { QRCode.toCanvas('some text') },
t.throws(function () { QRCode.toCanvas('some text') },
'Should throw if a callback is not provided')

t.throw(function () { QRCode.toCanvas(canvasEl, 'some text') },
t.throws(function () { QRCode.toCanvas(canvasEl, 'some text') },
'Should throw if a callback is not provided')

t.throw(function () { QRCode.toCanvas(canvasEl, 'some text', {}) },
t.throws(function () { QRCode.toCanvas(canvasEl, 'some text', {}) },
'Should throw if callback is not a function')

t.end()
Expand All @@ -46,7 +46,7 @@ test('toCanvas', function (t) {

t.plan(7)

t.throw(function () { QRCode.toCanvas() },
t.throws(function () { QRCode.toCanvas() },
'Should throw if no arguments are provided')

QRCode.toCanvas('some text', function (err, canvasEl) {
Expand Down
36 changes: 18 additions & 18 deletions test/e2e/toDataURL.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ const Helpers = require('test/helpers')
test('toDataURL - no promise available', function (t) {
Helpers.removeNativePromise()

t.throw(function () { QRCode.toDataURL() },
t.throws(function () { QRCode.toDataURL() },
'Should throw if no arguments are provided')

t.throw(function () { QRCode.toDataURL(function () {}) },
t.throws(function () { QRCode.toDataURL(function () {}) },
'Should throw if text is not provided')

t.throw(function () { QRCode.toDataURL('some text') },
t.throws(function () { QRCode.toDataURL('some text') },
'Should throw if a callback is not provided')

t.throw(function () { QRCode.toDataURL('some text', {}) },
t.throws(function () { QRCode.toDataURL('some text', {}) },
'Should throw if a callback is not a function')

t.throw(function () { QRCodeBrowser.toDataURL() },
t.throws(function () { QRCodeBrowser.toDataURL() },
'Should throw if no arguments are provided (browser)')

t.throw(function () { QRCodeBrowser.toDataURL(function () {}) },
t.throws(function () { QRCodeBrowser.toDataURL(function () {}) },
'Should throw if text is not provided (browser)')

t.throw(function () { QRCodeBrowser.toDataURL('some text') },
t.throws(function () { QRCodeBrowser.toDataURL('some text') },
'Should throw if a callback is not provided (browser)')

t.throw(function () { QRCodeBrowser.toDataURL('some text', {}) },
t.throws(function () { QRCodeBrowser.toDataURL('some text', {}) },
'Should throw if a callback is not a function (browser)')

t.end()
Expand Down Expand Up @@ -57,15 +57,15 @@ test('toDataURL - image/png', function (t) {

t.plan(8)

t.throw(function () { QRCode.toDataURL() },
t.throws(function () { QRCode.toDataURL() },
'Should throw if no arguments are provided')

QRCode.toDataURL('i am a pony!', {
errorCorrectionLevel: 'L',
type: 'image/png'
}, function (err, url) {
t.ok(!err, 'there should be no error ' + err)
t.equals(url, expectedDataURL,
t.equal(url, expectedDataURL,
'url should match expected value for error correction L')
})

Expand All @@ -78,14 +78,14 @@ test('toDataURL - image/png', function (t) {
t.notOk(url, 'url should be null')
})

t.equals(typeof QRCode.toDataURL('i am a pony!').then, 'function',
t.equal(typeof QRCode.toDataURL('i am a pony!').then, 'function',
'Should return a promise')

QRCode.toDataURL('i am a pony!', {
errorCorrectionLevel: 'L',
type: 'image/png'
}).then(function (url) {
t.equals(url, expectedDataURL,
t.equal(url, expectedDataURL,
'url should match expected value for error correction L (promise)')
})

Expand Down Expand Up @@ -120,10 +120,10 @@ test('Canvas toDataURL - image/png', function (t) {

t.plan(11)

t.throw(function () { QRCodeBrowser.toDataURL() },
t.throws(function () { QRCodeBrowser.toDataURL() },
'Should throw if no arguments are provided')

t.throw(function () { QRCodeBrowser.toDataURL(function () {}) },
t.throws(function () { QRCodeBrowser.toDataURL(function () {}) },
'Should throw if text is not provided')

const canvas = createCanvas(200, 200)
Expand All @@ -132,7 +132,7 @@ test('Canvas toDataURL - image/png', function (t) {
type: 'image/png'
}, function (err, url) {
t.ok(!err, 'there should be no error ' + err)
t.equals(url, expectedDataURL, 'url generated should match expected value')
t.equal(url, expectedDataURL, 'url generated should match expected value')
})

QRCodeBrowser.toDataURL(canvas, 'i am a pony!', {
Expand All @@ -148,7 +148,7 @@ test('Canvas toDataURL - image/png', function (t) {
errorCorrectionLevel: 'H',
type: 'image/png'
}).then(function (url) {
t.equals(url, expectedDataURL, 'url generated should match expected value (promise)')
t.equal(url, expectedDataURL, 'url generated should match expected value (promise)')
})

QRCodeBrowser.toDataURL(canvas, 'i am a pony!', {
Expand All @@ -173,13 +173,13 @@ test('Canvas toDataURL - image/png', function (t) {
type: 'image/png'
}, function (err, url) {
t.ok(!err, 'there should be no error ' + err)
t.equals(url, expectedDataURL, 'url generated should match expected value')
t.equal(url, expectedDataURL, 'url generated should match expected value')
})

QRCodeBrowser.toDataURL('i am a pony!', {
errorCorrectionLevel: 'H',
type: 'image/png'
}).then(function (url) {
t.equals(url, expectedDataURL, 'url generated should match expected value (promise)')
t.equal(url, expectedDataURL, 'url generated should match expected value (promise)')
})
})
8 changes: 4 additions & 4 deletions test/e2e/toFile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ test('toFile - no promise available', function (t) {
Helpers.removeNativePromise()
const fileName = path.join(os.tmpdir(), 'qrimage.png')

t.throw(function () { QRCode.toFile(fileName, 'some text') },
t.throws(function () { QRCode.toFile(fileName, 'some text') },
'Should throw if a callback is not provided')

t.throw(function () { QRCode.toFile(fileName, 'some text', {}) },
t.throws(function () { QRCode.toFile(fileName, 'some text', {}) },
'Should throw if a callback is not a function')

t.end()
Expand All @@ -25,10 +25,10 @@ test('toFile - no promise available', function (t) {
test('toFile', function (t) {
const fileName = path.join(os.tmpdir(), 'qrimage.png')

t.throw(function () { QRCode.toFile('some text', function () {}) },
t.throws(function () { QRCode.toFile('some text', function () {}) },
'Should throw if path is not provided')

t.throw(function () { QRCode.toFile(fileName) },
t.throws(function () { QRCode.toFile(fileName) },
'Should throw if text is not provided')

t.equal(typeof QRCode.toFile(fileName, 'some text').then, 'function',
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/toFileStream.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ const QRCode = require('lib')
const StreamMock = require('../mocks/writable-stream')

test('toFileStream png', function (t) {
t.throw(function () { QRCode.toFileStream('some text') },
t.throws(function () { QRCode.toFileStream('some text') },
'Should throw if stream is not provided')

t.throw(function () { QRCode.toFileStream(new StreamMock()) },
t.throws(function () { QRCode.toFileStream(new StreamMock()) },
'Should throw if text is not provided')

const fstream = new StreamMock()
Expand Down
28 changes: 14 additions & 14 deletions test/e2e/toString.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ const Helpers = require('test/helpers')
test('toString - no promise available', function (t) {
Helpers.removeNativePromise()

t.throw(function () { QRCode.toString() },
t.throws(function () { QRCode.toString() },
'Should throw if text is not provided')

t.throw(function () { QRCode.toString('some text') },
t.throws(function () { QRCode.toString('some text') },
'Should throw if a callback is not provided')

t.throw(function () { QRCode.toString('some text', {}) },
t.throws(function () { QRCode.toString('some text', {}) },
'Should throw if a callback is not a function')

t.throw(function () { QRCode.toString() },
t.throws(function () { QRCode.toString() },
'Should throw if text is not provided (browser)')

t.throw(function () { browser.toString('some text') },
t.throws(function () { browser.toString('some text') },
'Should throw if a callback is not provided (browser)')

t.throw(function () { browser.toString('some text', {}) },
t.throws(function () { browser.toString('some text', {}) },
'Should throw if a callback is not a function (browser)')

t.end()
Expand All @@ -34,43 +34,43 @@ test('toString - no promise available', function (t) {
test('toString', function (t) {
t.plan(5)

t.throw(function () { QRCode.toString() },
t.throws(function () { QRCode.toString() },
'Should throw if text is not provided')

QRCode.toString('some text', function (err, str) {
t.ok(!err, 'There should be no error')
t.equals(typeof str, 'string',
t.equal(typeof str, 'string',
'Should return a string')
})

t.equals(typeof QRCode.toString('some text').then, 'function',
t.equal(typeof QRCode.toString('some text').then, 'function',
'Should return a promise')

QRCode.toString('some text', { errorCorrectionLevel: 'L' })
.then(function (str) {
t.equals(typeof str, 'string',
t.equal(typeof str, 'string',
'Should return a string')
})
})

test('toString (browser)', function (t) {
t.plan(5)

t.throw(function () { browser.toString() },
t.throws(function () { browser.toString() },
'Should throw if text is not provided')

browser.toString('some text', function (err, str) {
t.ok(!err, 'There should be no error (browser)')
t.equals(typeof str, 'string',
t.equal(typeof str, 'string',
'Should return a string (browser)')
})

t.equals(typeof browser.toString('some text').then, 'function',
t.equal(typeof browser.toString('some text').then, 'function',
'Should return a promise')

browser.toString('some text', { errorCorrectionLevel: 'L' })
.then(function (str) {
t.equals(typeof str, 'string',
t.equal(typeof str, 'string',
'Should return a string')
})
})
Expand Down
4 changes: 2 additions & 2 deletions test/unit/core/alignment-pattern.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ test('Alignment pattern - Row/Col coords', function (t) {

for (let i = 1; i <= 40; i++) {
const pos = pattern.getRowColCoords(i)
t.deepEqual(pos, EXPECTED_POSITION_TABLE[i - 1], 'Should return correct coords')
t.same(pos, EXPECTED_POSITION_TABLE[i - 1], 'Should return correct coords')
}
})

Expand All @@ -70,7 +70,7 @@ test('Alignment pattern - Positions', function (t) {
// For each coord value check if it's present in the expected coords table
pos.forEach(function (position) {
position.forEach(function (coord) {
t.notEqual(expectedPos.indexOf(coord), -1, 'Should return valid coord value')
t.not(expectedPos.indexOf(coord), -1, 'Should return valid coord value')
})
})
}
Expand Down
2 changes: 1 addition & 1 deletion test/unit/core/alphanumeric-data.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test('Alphanumeric Data', function (t) {

const bitBuffer = new BitBuffer()
alphanumericData.write(bitBuffer)
t.deepEqual(bitBuffer.buffer, data.dataBit, 'Should write correct data to buffer')
t.same(bitBuffer.buffer, data.dataBit, 'Should write correct data to buffer')
})

t.end()
Expand Down
2 changes: 1 addition & 1 deletion test/unit/core/bit-buffer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test('Bit Buffer', function (t) {
t.equal(bitBuffer.getLengthInBits(), 8, 'Length should be 8')

for (let i = 0; i < 8; i++) {
t.deepEqual(bitBuffer.get(i), expectedDataBits[i], 'Should return correct bit value')
t.same(bitBuffer.get(i), expectedDataBits[i], 'Should return correct bit value')
}

t.end()
Expand Down
4 changes: 2 additions & 2 deletions test/unit/core/bit-matrix.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const test = require('tap').test
const BitMatrix = require('core/bit-matrix')

test('Bit Matrix', function (t) {
t.throw(function () { BitMatrix(0) }, 'Should throw if size is 0')
t.throw(function () { BitMatrix(-1) }, 'Should throw if size less than 0')
t.throws(function () { BitMatrix(0) }, 'Should throw if size is 0')
t.throws(function () { BitMatrix(-1) }, 'Should throw if size less than 0')

const bm = new BitMatrix(2)

Expand Down
4 changes: 2 additions & 2 deletions test/unit/core/byte-data.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test('Byte Data: String Input', function (t) {

const bitBuffer = new BitBuffer()
byteData.write(bitBuffer)
t.deepEqual(bitBuffer.buffer, textByte, 'Should write correct data to buffer')
t.same(bitBuffer.buffer, textByte, 'Should write correct data to buffer')

const byteDataUtf8 = new ByteData(utf8Text)
t.equal(byteDataUtf8.getLength(), 12, 'Should return correct length for utf8 chars')
Expand All @@ -34,7 +34,7 @@ test('Byte Data: Byte Input', function (t) {

const bitBuffer = new BitBuffer()
byteData.write(bitBuffer)
t.deepEqual(bitBuffer.buffer, bytes, 'Should write correct data to buffer')
t.same(bitBuffer.buffer, bytes, 'Should write correct data to buffer')

t.end()
})
2 changes: 1 addition & 1 deletion test/unit/core/galois-field.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const test = require('tap').test
const GF = require('core/galois-field')

test('Galois Field', function (t) {
t.throw(function () { GF.log(0) }, 'Should throw for log(n) with n < 1')
t.throws(function () { GF.log(0) }, 'Should throw for log(n) with n < 1')

for (let i = 1; i < 255; i++) {
t.equal(GF.log(GF.exp(i)), i, 'log and exp should be one the inverse of the other')
Expand Down
4 changes: 2 additions & 2 deletions test/unit/core/kanji-data.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ test('Kanji Data', function (t) {

let bitBuffer = new BitBuffer()
kanjiData.write(bitBuffer)
t.deepEqual(bitBuffer.buffer, dataBit, 'Should write correct data to buffer')
t.same(bitBuffer.buffer, dataBit, 'Should write correct data to buffer')

kanjiData = new KanjiData('abc')
bitBuffer = new BitBuffer()
t.throw(function () { kanjiData.write(bitBuffer) }, 'Should throw if data is invalid')
t.throws(function () { kanjiData.write(bitBuffer) }, 'Should throw if data is invalid')

t.end()
})
Loading