Skip to content

Commit

Permalink
chore: migrate to yakumo v1 & node:test
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Dec 12, 2023
1 parent 0fdfe0f commit fb02dda
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 38 deletions.
5 changes: 0 additions & 5 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@ root: true
env:
browser: true
node: true
mocha: true
es2020: true

globals:
NodeJS: true
KOISHI_CONFIG: true

extends:
- '@cordisjs/eslint-config'

plugins:
- mocha

rules:
'@typescript-eslint/naming-convention': off
18 changes: 6 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"dep": "yakumo upgrade",
"pub": "yakumo publish",
"lint": "eslint packages adapters --ext=ts --cache",
"test": "yakumo mocha -r esbuild-register",
"test": "yakumo test -r esbuild-register",
"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 All @@ -24,24 +24,18 @@
"devDependencies": {
"@cordisjs/eslint-config": "^1.0.4",
"@types/chai": "^4.3.11",
"@types/mocha": "^9.1.1",
"@types/node": "^20.10.2",
"c8": "^7.14.0",
"chai": "^4.3.10",
"esbuild": "^0.18.20",
"esbuild-register": "^3.5.0",
"eslint": "^8.55.0",
"eslint-plugin-mocha": "^10.2.0",
"mocha": "^9.2.2",
"shx": "^0.3.4",
"typescript": "^5.3.2",
"yakumo": "^0.3.13",
"yakumo-esbuild": "^0.3.26",
"yakumo-mocha": "^0.3.1",
"yakumo-publish": "^0.3.10",
"yakumo-publish-sync": "^0.3.3",
"yakumo-tsc": "^0.3.12",
"yakumo-upgrade": "^0.3.6",
"yakumo-version": "^0.3.4"
"yakumo": "^1.0.0-alpha.3",
"yakumo-esbuild": "^1.0.0-alpha.0",
"yakumo-mocha": "^1.0.0-alpha.0",
"yakumo-publish-sync": "^1.0.0-alpha.0",
"yakumo-tsc": "^1.0.0-alpha.1"
}
}
27 changes: 14 additions & 13 deletions packages/element/tests/segment.spec.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import Element from '../src'
import { describe, test } from 'node:test'
import { expect, use } from 'chai'
import shape from 'chai-shape'

use(shape)

describe('Element API', () => {
it('Element.escape()', () => {
test('Element.escape()', () => {
expect(Element.escape('<foo>')).to.equal('&lt;foo&gt;')
expect(Element.escape('&quot;')).to.equal('&amp;quot;')
})

it('Element.unescape()', () => {
test('Element.unescape()', () => {
expect(Element.unescape('&lt;foo&gt;')).to.equal('<foo>')
expect(Element.unescape('&amp;quot;')).to.equal('&quot;')
})

describe('Element.parse()', () => {
it('basic support', () => {
test('basic support', () => {
expect(Element.parse('<img src="https://test.com/?foo=1&amp;bar=2"/>'))
.to.deep.equal([Element('img', { src: 'https://test.com/?foo=1&bar=2' })])
expect(Element.parse(`<tag foo="'" bar='"'>text</tag>`))
Expand All @@ -25,13 +26,13 @@ describe('Element API', () => {
.to.deep.equal([Element('tag', { foo: false, barQux: true }, 'text')])
})

it('mismatched tags', () => {
test('mismatched tags', () => {
expect(Element.parse('1<foo>2<bar attr>3').join('')).to.equal('1<foo>2<bar attr>3</bar></foo>')
expect(Element.parse('1<foo/>4').join('')).to.equal('1<foo/>4')
expect(Element.parse('1</foo>4').join('')).to.equal('14')
})

it('whitespace', () => {
test('whitespace', () => {
expect(Element.parse(`<>
<foo> 1 </foo>
<!-- comment -->
Expand All @@ -41,7 +42,7 @@ describe('Element API', () => {
})

describe('Interpolation', () => {
it('interpolate', () => {
test('interpolate', () => {
expect(Element.parse('<tag bar={bar}>1{foo}1</tag>', { foo: 233, bar: 666 }))
.to.deep.equal([Element('tag', { bar: 666 }, '1', '233', '1')])
expect(Element.parse('<tag>&gt;{"&gt;"}</tag>', {}))
Expand All @@ -50,29 +51,29 @@ describe('Element API', () => {
.to.deep.equal([Element('tag', '233', '2')])
})

it('control flow', () => {
test('control flow', () => {
expect(Element.parse('{#if foo >= 0}{foo}{:else}<p>negative</p>{/if}', { foo: 233 }))
.to.deep.equal([Element.text('233')])
expect(Element.parse('{#if foo >= 0}{foo}{:else}<p>negative</p>{/if}', { foo: -233 }))
.to.deep.equal([Element('p', 'negative')])
})

it('#each', () => {
test('#each', () => {
expect(Element.parse('{#each arr as i}{i ** 2}{/each}', { arr: [1, 2, 3] }))
.to.deep.equal([Element.text('1'), Element.text('4'), Element.text('9')])
})
})

describe('Element.toString()', () => {
it('basic support', () => {
test('basic support', () => {
expect(Element('img', { src: 'https://test.com/?foo=1&bar=2' }).toString())
.to.equal('<img src="https://test.com/?foo=1&amp;bar=2"/>')
expect(Element('tag', { foo: false, barQux: true }, 'text').toString())
.to.equal('<tag no-foo bar-qux>text</tag>')
expect(Element('template', Element.parse('<tag foo>&lt;bar&gt;</tag>')).toString(true)).to.equal('<bar>')
})

it('validate children', () => {
test('validate children', () => {
expect(() => Element('tag', {}, {} as any)).to.throw()
expect(Element('tag', ['123', null, Element('span', '456')]).toString())
.to.equal('<tag>123<span>456</span></tag>')
Expand All @@ -84,21 +85,21 @@ describe('Element API', () => {
describe('Selectors', () => {
const selectIds = (source: string, query: string) => Element.select(source, query).map(el => el.attrs.id)

it('type selector', () => {
test('type selector', () => {
expect(selectIds('<a id="1"><a id="2"></a></a>', 'a')).to.deep.equal(['1', '2'])
expect(selectIds('<a id="1"><b id="2"></b></a>', 'b')).to.deep.equal(['2'])
expect(selectIds('<a id="1"><b id="2"></b></a>', 'c')).to.deep.equal([])
})

it('descendant', () => {
test('descendant', () => {
expect(selectIds('<a id="1"><b id="2"><c id="3"></c></b></a>', 'b>c')).to.deep.equal(['3'])
expect(selectIds('<a id="1"><b id="2"><c id="3"></c></b></a>', 'a c')).to.deep.equal(['3'])
expect(selectIds('<a id="1"><b id="2"><c id="3"></c></b></a>', 'a>c')).to.deep.equal([])
expect(selectIds('<a id="1"><b id="2"></b><c id="3"></c></a>', 'b c')).to.deep.equal([])
expect(selectIds('<a id="1"><b id="2"></b><c id="3"></c></a>', 'a>c')).to.deep.equal(['3'])
})

it('sibling', () => {
test('sibling', () => {
expect(selectIds('<a id="2"></a><b id="3"></b><b id="4"></b>', 'a+b')).to.deep.equal(['3'])
expect(selectIds('<a id="2"></a><b id="3"></b><b id="4"></b>', 'a~b')).to.deep.equal(['3', '4'])
})
Expand Down
21 changes: 13 additions & 8 deletions yakumo.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
require:
- yakumo-esbuild
- yakumo-mocha
- yakumo-publish
- yakumo-publish-sync
- yakumo-tsc
- yakumo-upgrade
- yakumo-version
- name: yakumo
config:
pipeline:
build:
- tsc
- esbuild
clean:
- tsc --clean
- name: yakumo-esbuild
- name: yakumo-esbuild-yaml
- name: yakumo-mocha
- name: yakumo-publish-sync
- name: yakumo-tsc

0 comments on commit fb02dda

Please sign in to comment.