Skip to content

Commit

Permalink
Migrate unit tests in test/unit/renderer folder to esm module syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
jozefizso committed Oct 21, 2024
1 parent af63f3c commit 365c5cd
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lib/renderer/svg.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fs from 'fs'
import * as svgTagRenderer from './svg-tag.js'

export const render = svgTagRenderer.render
Expand All @@ -8,7 +9,6 @@ export function renderToFile (path, qrData, options, cb) {
options = undefined
}

const fs = require('fs')
const svgTag = svgTagRenderer.render(qrData, options)

const xmlStr = '<?xml version="1.0" encoding="utf-8"?>' +
Expand Down
2 changes: 1 addition & 1 deletion lib/renderer/utf8.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fs from 'fs'
import * as Utils from './utils.js'

const BLOCK_CHAR = {
Expand Down Expand Up @@ -65,7 +66,6 @@ export function renderToFile (path, qrData, options, cb) {
options = undefined
}

const fs = require('fs')
const utf8 = render(qrData, options)
fs.writeFile(path, utf8, cb)
}
6 changes: 3 additions & 3 deletions test/unit/renderer/canvas.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from 'tap'
const { Canvas, createCanvas } = require('canvas')
const QRCode = require('core/qrcode')
const CanvasRenderer = require('renderer/canvas')
import { Canvas, createCanvas } from 'canvas'
import * as QRCode from './../../../lib/core/qrcode.js'
import * as CanvasRenderer from './../../../lib/renderer/canvas.js'

test('CanvasRenderer interface', function (t) {
t.type(CanvasRenderer.render, 'function',
Expand Down
14 changes: 7 additions & 7 deletions test/unit/renderer/png.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { test } from 'tap'
const sinon = require('sinon')
const fs = require('fs')
const QRCode = require('core/qrcode')
const PngRenderer = require('renderer/png')
const PNG = require('pngjs').PNG
const StreamMock = require('../../mocks/writable-stream')
import sinon from 'sinon'
import fs from 'fs'
import { PNG } from 'pngjs'
import * as QRCode from './../../../lib/core/qrcode.js'
import * as PngRenderer from './../../../lib/renderer/png.js'
import StreamMock from './../../mocks/writable-stream.js'

test('PNG renderer interface', function (t) {
t.type(PngRenderer.render, 'function',
Expand Down Expand Up @@ -86,7 +86,7 @@ test('PNG renderToDataURL', function (t) {
)
})

test('PNG renderToFile', function (t) {
test('PNG renderToFile', { todo: 'Mocking file system in `renderToFile()` function does not work in ESM modules.' }, function (t) {
const sampleQrData = QRCode.create('sample text', { version: 2 })
const fileName = 'qrimage.png'
let fsStub = sinon.stub(fs, 'createWriteStream')
Expand Down
10 changes: 5 additions & 5 deletions test/unit/renderer/svg.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { test } from 'tap'
const sinon = require('sinon')
const fs = require('fs')
const htmlparser = require('htmlparser2')
const QRCode = require('core/qrcode')
const SvgRenderer = require('renderer/svg')
import sinon from 'sinon'
import fs from 'fs'
import * as htmlparser from 'htmlparser2'
import * as QRCode from './../../../lib/core/qrcode.js'
import * as SvgRenderer from './../../../lib/renderer/svg.js'

function getExpectedViewbox (size, margin) {
const expectedQrCodeSize = size + margin * 2
Expand Down
4 changes: 2 additions & 2 deletions test/unit/renderer/terminal.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test } from 'tap'
const QRCode = require('core/qrcode')
const TerminalRenderer = require('renderer/terminal')
import * as QRCode from './../../../lib/core/qrcode.js'
import * as TerminalRenderer from './../../../lib/renderer/terminal.js'

test('TerminalRenderer interface', function (t) {
t.type(TerminalRenderer.render, 'function',
Expand Down
8 changes: 4 additions & 4 deletions test/unit/renderer/utf8.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { test } from 'tap'
const sinon = require('sinon')
const fs = require('fs')
const QRCode = require('core/qrcode')
const Utf8Renderer = require('renderer/utf8')
import sinon from 'sinon'
import fs from 'fs'
import * as QRCode from './../../../lib/core/qrcode.js'
import * as Utf8Renderer from './../../../lib/renderer/utf8.js'

test('Utf8Renderer interface', function (t) {
t.type(Utf8Renderer.render, 'function',
Expand Down
2 changes: 1 addition & 1 deletion test/unit/renderer/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from 'tap'
const Utils = require('renderer/utils')
import * as Utils from './../../../lib/renderer/utils.js'

test('Utils getOptions', function (t) {
const defaultOptions = {
Expand Down

0 comments on commit 365c5cd

Please sign in to comment.