Skip to content
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"dep": "yakumo upgrade",
"pub": "yakumo publish",
"lint": "eslint packages adapters --ext=ts --cache",
"test": "yakumo test --import tsx",
"test": "NODE_OPTIONS=\"--import tsx\" yakumo test",
"test:text": "shx rm -rf coverage && c8 -r text yarn test",
"test:json": "shx rm -rf coverage && c8 -r json yarn test",
"test:html": "shx rm -rf coverage && c8 -r html yarn test",
Expand Down
2 changes: 1 addition & 1 deletion packages/element/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ namespace Element {
} else if (is('ArrayBuffer', src)) {
src = prefix + Binary.toBase64(src)
} else if (ArrayBuffer.isView(src)) {
src = prefix + Binary.toBase64(src.buffer)
src = prefix + Binary.toBase64(src)
}
if (src.startsWith('base64://')) {
warn(`protocol "base64:" is deprecated and will be removed in the future, please use "data:" instead`)
Expand Down
40 changes: 40 additions & 0 deletions packages/element/tests/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import * as h from '../src/index.ts'
import { describe, test } from 'node:test'
import { expect } from 'chai'

describe('@satorijs/element', () => {
describe('asset factory', () => {
test('string source', () => {
expect(h.image('https://example.com/foo.png').attrs.src)
.to.equal('https://example.com/foo.png')
})

test('Buffer source', () => {
expect(h.image(Buffer.from([1, 2, 3])).attrs.src)
.to.equal('base64://AQID')
})

test('ArrayBuffer source', () => {
expect(h.image(Uint8Array.from([1, 2, 3]).buffer).attrs.src)
.to.equal('base64://AQID')
})

test('Uint8Array view', () => {
const buffer = Uint8Array.from([0, 0, 1, 2, 3, 0]).buffer
expect(h.image(new Uint8Array(buffer, 2, 3)).attrs.src)
.to.equal('base64://AQID')
})

test('DataView', () => {
const buffer = Uint8Array.from([0, 0, 1, 2, 3, 0]).buffer
expect(h.image(new DataView(buffer, 2, 3)).attrs.src)
.to.equal('base64://AQID')
})

test('mime type', () => {
const buffer = Uint8Array.from([0, 0, 1, 2, 3, 0]).buffer
expect(h.file(new Uint8Array(buffer, 2, 3), 'image/png').attrs.src)
.to.equal('data:image/png;base64,AQID')
})
})
})
Loading