Something went wrong. Try again.
Browser extension: detect and subscribe to standard.site publications on ATProto
Something went wrong. Try again.
3.5 kB · 90 lines
JavaScript
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091import { readFileSync } from 'node:fs'import { tmpdir } from 'node:os'import { join } from 'node:path'import { describe, expect, it } from 'vitest'
import { DEV_ICON_SIZES, DEV_NAME_SUFFIX, buildStamp, devManifest } from './dev-channel.mjs'import { invertHexColors, pngSize } from './render-icons.mjs'
const root = join(import.meta.dirname, '..')const manifest = JSON.parse(readFileSync(join(root, 'public', 'manifest.json'), 'utf8'))
describe('devManifest', () => { it('suffixes the name and changes nothing else', () => { const dev = devManifest(manifest) expect(dev.name).toBe(manifest.name + DEV_NAME_SUFFIX) expect({ ...dev, name: manifest.name }).toEqual(manifest) })
it('keeps the key, so the dev install keeps its id and its redirect uri', () => { expect(devManifest(manifest).key).toBe(manifest.key) })
it('is idempotent — a watch rebuild patches an already-patched manifest', () => { const once = devManifest(manifest, 'abc1234') expect(devManifest(once, 'abc1234')).toEqual(once) })
it('stamps the build into version_name, leaving version loadable', () => { const dev = devManifest(manifest, 'abc1234-dirty') expect(dev.version_name).toBe(`${manifest.version}+abc1234-dirty`) // Chrome parses `version` itself: up to four integers, nothing else. expect(dev.version).toBe(manifest.version) expect(dev.version).toMatch(/^\d+(\.\d+){0,3}$/) })
it('restamps rather than appends when the same dist/ is rebuilt at a new commit', () => { const moved = devManifest(devManifest(manifest, 'abc1234'), 'def5678') expect(moved.version_name).toBe(`${manifest.version}+def5678`) })
it('leaves version_name off when git cannot name the build', () => { expect(devManifest(manifest)).not.toHaveProperty('version_name') })})
describe('buildStamp', () => { it('is a short sha for this checkout, marked when the tree is dirty', () => { expect(buildStamp(root)).toMatch(/^[0-9a-f]{7,}(-dirty)?$/) })
it('is undefined outside a git checkout, rather than failing the build', () => { expect(buildStamp(tmpdir())).toBeUndefined() })})
describe('dev icons', () => { // applyDevChannel copies exactly these over dist/icons/; a size in the // manifest with no inverted tile would ship the production one instead. it('cover every size the manifest declares', () => { expect(DEV_ICON_SIZES.map(String).sort()).toEqual(Object.keys(manifest.icons).sort()) })
it.each(DEV_ICON_SIZES)('icon%i.png is rendered and inverted', (size) => { const dev = readFileSync(join(root, 'brand', 'icons-dev', `icon${size}.png`)) expect(pngSize(dev)).toEqual({ width: size, height: size }) expect(dev.equals(readFileSync(join(root, 'public', 'icons', `icon${size}.png`)))).toBe(false) })})
describe('invertHexColors', () => { it('inverts each channel', () => { expect(invertHexColors('#000000 #ffffff #26282b')).toBe('#ffffff #000000 #d9d7d4') })
it('expands three-digit hex', () => { expect(invertHexColors('#f00')).toBe('#00ffff') })
it('leaves keywords alone', () => { expect(invertHexColors('fill="none" stroke="currentColor"')).toBe( 'fill="none" stroke="currentColor"', ) })
it('round-trips the sticker', () => { const svg = readFileSync(join(root, 'brand', 'sticker.svg'), 'utf8') expect(invertHexColors(invertHexColors(svg))).toBe(svg) expect(invertHexColors(svg)).not.toBe(svg) })})