@gongfpp/dsh-novel-fish 0.1.6 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,60 +1,73 @@
1
- import test from 'node:test'
2
- import assert from 'node:assert/strict'
3
- import { readFile, access } from 'node:fs/promises'
4
-
5
- const root = new URL('../', import.meta.url)
6
- const read = path => readFile(new URL(path, root), 'utf8')
7
-
8
- test('public package identity matches the Host patch and browser module', async () => {
9
- const manifest = JSON.parse(await read('package.json'))
10
- assert.equal(manifest.name, '@gongfpp/dsh-novel-fish')
11
- assert.equal(manifest.repository.url, 'https://github.com/gongfpp/dsh-novel-fish.git')
12
- assert.equal(manifest.engines.dsh, '>=0.2.1-rc.2 <0.3.0-0')
13
- assert.ok((await read('cordis.patch.yml')).includes(`name: '${manifest.name}'`))
14
- assert.ok((await read('src/client.js')).includes(`const MODULE_ID = '${manifest.name}'`))
15
- assert.ok((await read('lib/client.js')).includes(manifest.name))
16
- for (const path of ['./index.js', './lib/client.js', './assets/icon.svg', './locale/en.json', './locale/zh.json']) {
17
- await access(new URL(path, root))
18
- }
19
- })
20
-
21
- test('notices include JSZip prebundled libraries and the zlib copyright', async () => {
22
- const notices = await read('THIRD-PARTY-NOTICES.txt')
23
- for (const name of ['pako@1.0.11', 'lie@3.3.0', 'immediate@3.0.6', 'setimmediate@1.0.5', 'crc-32@1.2.2', 'Jean-loup Gailly and Mark Adler']) {
24
- assert.ok(notices.includes(name), `Missing third-party notice: ${name}`)
25
- }
26
- })
27
-
28
- test('市场索引保留固定提交来源、版本唯一和宿主兼容范围', async () => {
29
- const manifest = JSON.parse(await read('package.json'))
30
- const index = JSON.parse(await read('index.json'))
31
- assert.equal(index.format, 1)
32
- const entry = index.plugins.find(plugin => plugin.name === manifest.name)
33
- assert.ok(entry)
34
- assert.equal(entry.author, manifest.author)
35
- assert.equal(entry.repository.url + '.git', manifest.repository.url)
36
- await access(new URL(entry.icon, root))
37
- assert.ok(entry.versions.length)
38
- assert.equal(new Set(entry.versions.map(version => version.version)).size, entry.versions.length)
39
- for (const version of entry.versions) {
40
- assert.match(version.version, /^\d+\.\d+\.\d+$/u)
41
- assert.ok(Number.isSafeInteger(version.publishTimestamp) && version.publishTimestamp > 0)
42
- if (version.version === manifest.version) assert.equal(version.engines.dsh, manifest.engines.dsh)
43
- else assert.match(version.engines.dsh, /^(?:\^|~|>=)?\d+\.\d+\.\d+(?:-[\w.-]+)?/u)
44
- assert.equal(version.source.type, 'git')
45
- assert.equal(version.source.url, entry.repository.url)
46
- assert.match(version.source.commit, /^[a-f0-9]{40}$/u)
47
- }
48
- })
49
-
50
- test('README local links resolve and installation contains no personal absolute path', async () => {
51
- const readme = await read('README.md')
52
- assert.doesNotMatch(readme, /\/Users\/|C:\\Users\\/u)
53
- const manifest = JSON.parse(await read('package.json'))
54
- assert.ok(readme.includes(`github:gongfpp/dsh-novel-fish#v${manifest.version}`))
55
- for (const match of readme.matchAll(/\]\(([^)]+)\)/gu)) {
56
- const path = match[1].replace(/^<|>$/gu, '').split('#')[0]
57
- if (!path || /^[a-z]+:/iu.test(path)) continue
58
- await access(new URL(path, root))
59
- }
60
- })
1
+ import test from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+ import semver from 'semver'
4
+ import { readFile, access } from 'node:fs/promises'
5
+
6
+ const root = new URL('../', import.meta.url)
7
+ const read = path => readFile(new URL(path, root), 'utf8')
8
+
9
+ test('public package identity matches the Host patch and browser module', async () => {
10
+ const manifest = JSON.parse(await read('package.json'))
11
+ assert.equal(manifest.name, '@gongfpp/dsh-novel-fish')
12
+ assert.equal(manifest.repository.url, 'https://github.com/gongfpp/dsh-novel-fish.git')
13
+ assert.equal(manifest.engines.dsh, '>=0.2.1-rc.2 <=0.2.2-alpha.2')
14
+ assert.ok((await read('cordis.patch.yml')).includes(`name: '${manifest.name}'`))
15
+ assert.ok((await read('src/client.js')).includes(`const MODULE_ID = '${manifest.name}'`))
16
+ assert.ok((await read('lib/client.js')).includes(manifest.name))
17
+ for (const path of ['./index.js', './lib/client.js', './assets/icon.png', './locale/en.json', './locale/zh.json']) {
18
+ await access(new URL(path, root))
19
+ }
20
+ })
21
+
22
+ test('host compatibility includes rc.2–rc.5 and alpha.2 but does not promise unknown releases', async () => {
23
+ const { engines } = JSON.parse(await read('package.json'))
24
+ // DSH preflight evaluates prereleases explicitly, unlike npm's default semver rules.
25
+ for (const version of ['0.2.1-rc.2', '0.2.1-rc.3', '0.2.1-rc.4', '0.2.1-rc.5', '0.2.2-alpha.2']) {
26
+ assert.equal(semver.satisfies(version, engines.dsh, { includePrerelease: true }), true, version)
27
+ }
28
+ for (const version of ['0.2.0', '0.2.1-alpha.5', '0.2.1-rc.1', '0.2.2-alpha.3', '0.2.2', '0.3.0', '1.0.0']) {
29
+ assert.equal(semver.satisfies(version, engines.dsh, { includePrerelease: true }), false, version)
30
+ }
31
+ })
32
+
33
+ test('notices include JSZip prebundled libraries and the zlib copyright', async () => {
34
+ const notices = await read('THIRD-PARTY-NOTICES.txt')
35
+ for (const name of ['pako@1.0.11', 'lie@3.3.0', 'immediate@3.0.6', 'setimmediate@1.0.5', 'crc-32@1.2.2', 'Jean-loup Gailly and Mark Adler']) {
36
+ assert.ok(notices.includes(name), `Missing third-party notice: ${name}`)
37
+ }
38
+ })
39
+
40
+ test('市场索引保留固定提交来源、版本唯一和宿主兼容范围', async () => {
41
+ const manifest = JSON.parse(await read('package.json'))
42
+ const index = JSON.parse(await read('index.json'))
43
+ assert.equal(index.format, 1)
44
+ const entry = index.plugins.find(plugin => plugin.name === manifest.name)
45
+ assert.ok(entry)
46
+ assert.equal(entry.author, manifest.author)
47
+ assert.equal(entry.repository.url + '.git', manifest.repository.url)
48
+ await access(new URL(entry.icon, root))
49
+ assert.ok(entry.versions.length)
50
+ assert.equal(new Set(entry.versions.map(version => version.version)).size, entry.versions.length)
51
+ for (const version of entry.versions) {
52
+ assert.match(version.version, /^\d+\.\d+\.\d+$/u)
53
+ assert.ok(Number.isSafeInteger(version.publishTimestamp) && version.publishTimestamp > 0)
54
+ if (version.version === manifest.version) assert.equal(version.engines.dsh, manifest.engines.dsh)
55
+ else assert.match(version.engines.dsh, /^(?:\^|~|>=)?\d+\.\d+\.\d+(?:-[\w.-]+)?/u)
56
+ assert.equal(version.source.type, 'git')
57
+ assert.equal(version.source.url, entry.repository.url)
58
+ assert.match(version.source.commit, /^[a-f0-9]{40}$/u)
59
+ }
60
+ })
61
+
62
+ test('README local links resolve and installation contains no personal absolute path', async () => {
63
+ const readme = await read('README.md')
64
+ assert.doesNotMatch(readme, /\/Users\/|C:\\Users\\/u)
65
+ const index = JSON.parse(await read('index.json'))
66
+ const published = index.plugins.find(plugin => plugin.name === '@gongfpp/dsh-novel-fish').versions[0]
67
+ assert.ok(readme.includes(`github:gongfpp/dsh-novel-fish#v${published.version}`), 'installation uses an actually published version')
68
+ for (const match of readme.matchAll(/\]\(([^)]+)\)/gu)) {
69
+ const path = match[1].replace(/^<|>$/gu, '').split('#')[0]
70
+ if (!path || /^[a-z]+:/iu.test(path)) continue
71
+ await access(new URL(path, root))
72
+ }
73
+ })
@@ -198,10 +198,10 @@ test('原生阅读开关保存时禁用并合并快速点击,不影响书籍
198
198
  }
199
199
  view = await mount(model)
200
200
  try {
201
- const toggle = () => view.root.findByProps({ role: 'switch' })
201
+ const toggle = () => view.root.findByProps({ 'aria-label': t('settings.enabled') })
202
202
  assert.equal(toggle().props['aria-label'], zh.settings.enabled)
203
203
  assert.equal(toggle().props['aria-checked'], false)
204
- const change = view.root.findByType(HostSwitch).props.onChange
204
+ const change = view.root.findAllByType(HostSwitch).find(node => node.props.label === t('settings.enabled')).props.onChange
205
205
  await act(async () => { change(true); change(true) })
206
206
  assert.deepEqual(model.options, [['enabled', true]])
207
207
  assert.equal(toggle().props.disabled, true)
@@ -220,14 +220,14 @@ test('阅读开关保存失败不假装开启,报错后可以重试', async ()
220
220
  model.props.onSetOption = async () => { throw new Error('模拟存储失败') }
221
221
  const view = await mount(model)
222
222
  try {
223
- await act(async () => view.root.findByProps({ role: 'switch' }).props.onClick())
224
- const toggle = view.root.findByProps({ role: 'switch' })
223
+ await act(async () => view.root.findByProps({ 'aria-label': t('settings.enabled') }).props.onClick())
224
+ const toggle = view.root.findByProps({ 'aria-label': t('settings.enabled') })
225
225
  assert.equal(toggle.props.disabled, false)
226
226
  assert.equal(toggle.props['aria-checked'], false)
227
227
  assert.match(model.notices.at(-1), /操作失败.*模拟存储失败/u)
228
228
  model.props.onSetOption = async (...values) => model.options.push(values)
229
229
  await act(async () => view.update(React.createElement(SettingsRow, { ...model.props })))
230
- await act(async () => view.root.findByProps({ role: 'switch' }).props.onClick())
230
+ await act(async () => view.root.findByProps({ 'aria-label': t('settings.enabled') }).props.onClick())
231
231
  assert.deepEqual(model.options, [['enabled', true]])
232
232
  } finally { await act(async () => view.unmount()) }
233
233
  })
@@ -238,7 +238,7 @@ test('书库未就绪或出错时原生控件禁用,不写设置', async () =>
238
238
  Object.assign(model.state, state)
239
239
  const view = await mount(model)
240
240
  try {
241
- const toggle = view.root.findByProps({ role: 'switch' })
241
+ const toggle = view.root.findByProps({ 'aria-label': t('settings.enabled') })
242
242
  assert.equal(toggle.props.disabled, true)
243
243
  assert.equal(control(view, 'data-novel-import').props.disabled, true)
244
244
  assert.equal(menu(view, 'data-novel-type-select').props.items.every(item => item.disabled), true)
@@ -248,6 +248,19 @@ test('书库未就绪或出错时原生控件禁用,不写设置', async () =>
248
248
  }
249
249
  })
250
250
 
251
+ test('同一区域续读是默认关闭的设置项,开启后写入 continueOnReopen', async () => {
252
+ const model = setup()
253
+ const view = await mount(model)
254
+ try {
255
+ const toggle = view.root.findByProps({ 'aria-label': t('settings.continueOnReopen') })
256
+ assert.equal(toggle.props['aria-checked'], false)
257
+ assert.equal(view.root.findAllByType(HostSwitch).length, 2)
258
+ await act(async () => toggle.props.onClick())
259
+ assert.deepEqual(model.options.at(-1), ['continueOnReopen', true])
260
+ assert.equal(model.state.settings.continueOnReopen, true)
261
+ } finally { await act(async () => view.unmount()) }
262
+ })
263
+
251
264
  test('中英文设置文案键一致,不再含位置选择翻译', () => {
252
265
  assert.deepEqual(Object.keys(zh.settings).sort(), Object.keys(en.settings).sort())
253
266
  for (const key of ['targetType', 'typeReasoning', 'typeHint', 'importBook', 'cancel', 'confirmDelete']) {
@@ -575,3 +575,43 @@ test('end of book does not wrap and target settings contain no passage binding',
575
575
  assert.equal(Object.hasOwn(store.getSettingsSnapshot(), 'targets'), false)
576
576
  assert.equal(Object.hasOwn(storage.settings, 'targets'), false)
577
577
  })
578
+
579
+ test('续读设置默认关闭、按布尔归一化,未知设置项仍被拒绝', async () => {
580
+ const { store } = makeStore()
581
+ await store.ready
582
+ assert.equal(store.getSettingsSnapshot().continueOnReopen, false)
583
+ await store.setOption('continueOnReopen', 'yes')
584
+ assert.equal(store.getSettingsSnapshot().continueOnReopen, true)
585
+ await store.setOption('continueOnReopen', 0)
586
+ assert.equal(store.getSettingsSnapshot().continueOnReopen, false)
587
+ await assert.rejects(() => store.setOption('unknown', true), /未知设置项/u)
588
+ store.dispose()
589
+ })
590
+
591
+ test('claimPassage 保留该区域已读段,continuePassage 才在同一区域推进', async () => {
592
+ const { store, storage } = makeStore()
593
+ await store.ready
594
+ assert.equal((await store.claimPassage('A')).passage.text, 'A')
595
+ assert.equal((await store.claimPassage('A')).passage.text, 'A', '重复展开仍显示这一页')
596
+ assert.equal((await store.continuePassage('A')).passage.text, 'B')
597
+ assert.equal(storage.books.get('book-a').progress, 2)
598
+ assert.equal((await store.claimPassage('A')).passage.text, 'B', '关闭续读后显示该区域最后读到的段落')
599
+ assert.equal((await store.continuePassage('A')).passage.text, 'C')
600
+ assert.equal(storage.books.get('book-a').progress, 3)
601
+ assert.equal((await store.continuePassage('A')).kind, 'end')
602
+ assert.equal((await store.continuePassage('A')).kind, 'end', '读完后不再推进')
603
+ store.dispose()
604
+ })
605
+
606
+ test('continuePassage 对未读区域等同首次读取,并遵守停读与切书', async () => {
607
+ const { store, storage } = makeStore()
608
+ await store.ready
609
+ assert.equal((await store.continuePassage('A')).passage.text, 'A')
610
+ await store.setOption('enabled', false)
611
+ assert.equal((await store.continuePassage('A')).kind, 'empty')
612
+ assert.equal(storage.books.get('book-a').progress, 1, '停读后续读不再推进进度')
613
+ await store.setOption('enabled', true)
614
+ await store.selectBook('book-b')
615
+ assert.equal((await store.continuePassage('A')).passage.text, 'X', '切书后从新书自己的进度续读')
616
+ store.dispose()
617
+ })
package/assets/icon.svg DELETED
@@ -1 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><rect x="8" y="9" width="48" height="46" rx="12" fill="#3076a8"/><path d="M19 20c7-4 13-4 20 0v27c-7-4-13-4-20 0zm26 0c-7-4-13-4-20 0v27c7-4 13-4 20 0z" fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="3"/><path d="M32 21v27" stroke="#fff" stroke-width="2"/></svg>