mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-16 17:46:17 -08:00
build(site): [SITE-07] reproduce core outputs and validate localized editing
This commit is contained in:
1 parent
244695e726
commit
0cfdf4a7e3
24 files changed
+10598
-5
No files matched your search
@@ -1,5 +1,11 @@
|
||||
# Browser regression entry
|
||||
|
||||
`editor-core.spec.js` checks editing, keyboard undo/redo, find navigation and disposal
|
||||
for all ten bundled locales. Names come from statically parsed frozen NLS inputs;
|
||||
each localized bundle must load over HTTP. A separate case requires the real core
|
||||
diff worker to compute and clear changes after input updates. On Windows the ten
|
||||
locale cases and worker case pass in Chromium/Firefox/WebKit (33 cases total).
|
||||
|
||||
`editor-markdown.spec.js` runs the bundled DOMPurify/marked renderer, verifies
|
||||
formatting, selected filtering and temporary-hook cleanup. `site-vendor.spec.js`
|
||||
also checks all 85 notice files and the core-origin attribution links over HTTP.
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
import fs from 'node:fs'
|
||||
import { expect, test } from './fixtures.js'
|
||||
|
||||
const locales = JSON.parse(fs.readFileSync(new URL('../../refactor/baselines/monaco-core-locales.json', import.meta.url)))
|
||||
|
||||
test('docs Monaco core diff worker computes changes and updates after edits', async ({ page }, testInfo) => {
|
||||
const workers = []
|
||||
page.on('worker', worker => workers.push(worker.url()))
|
||||
await page.goto('/test/player.html?core=candidate&chapter=published')
|
||||
await page.addScriptTag({ url: '/assets/js/vs/loader.js' })
|
||||
await page.evaluate(async () => {
|
||||
window.require.config({ paths: { vs: '/assets/js/vs' } })
|
||||
await new Promise((resolve, reject) => window.require(['vs/editor/editor.main'], resolve, reject))
|
||||
const host = document.createElement('div')
|
||||
host.style.cssText = 'width:800px;height:400px'
|
||||
document.body.appendChild(host)
|
||||
const api = window.monaco.editor
|
||||
const original = api.createModel('first\nsecond\nthird', 'plaintext')
|
||||
const modified = api.createModel('first\nchanged\nthird', 'plaintext')
|
||||
const editor = api.createDiffEditor(host)
|
||||
editor.setModel({ original, modified })
|
||||
window.diffProbe = { host, editor, original, modified }
|
||||
})
|
||||
try {
|
||||
await expect.poll(() => page.evaluate(() => window.diffProbe.editor.getLineChanges()?.map(change => [change.originalStartLineNumber, change.originalEndLineNumber, change.modifiedStartLineNumber, change.modifiedEndLineNumber]))).toEqual([[2, 2, 2, 2]])
|
||||
expect(workers.length).toBeGreaterThan(0)
|
||||
await page.evaluate(() => window.diffProbe.modified.setValue(window.diffProbe.original.getValue()))
|
||||
await expect.poll(() => page.evaluate(() => window.diffProbe.editor.getLineChanges())).toEqual([])
|
||||
await testInfo.attach('monaco-core-worker', { contentType: 'application/json', body: JSON.stringify({ workers, initialChangedLines: [2, 2, 2, 2], finalChanges: [] }) })
|
||||
}
|
||||
finally {
|
||||
await page.evaluate(() => {
|
||||
const { host, editor, original, modified } = window.diffProbe
|
||||
editor.dispose()
|
||||
original.dispose()
|
||||
modified.dispose()
|
||||
host.remove()
|
||||
})
|
||||
}
|
||||
expect(await page.evaluate(() => window.monaco.editor.getModels().length)).toBe(0)
|
||||
})
|
||||
|
||||
for (const locale of locales) {
|
||||
test(`docs Monaco core editing and localized find: ${locale.locale}`, async ({ page }, testInfo) => {
|
||||
const responses = []
|
||||
page.on('response', (response) => {
|
||||
if (/editor\.main\.nls/.test(response.url()))
|
||||
responses.push({ url: response.url(), status: response.status() })
|
||||
})
|
||||
await page.goto('/test/player.html?core=candidate&chapter=published')
|
||||
await page.addScriptTag({ url: '/assets/js/vs/loader.js' })
|
||||
const modifier = await page.evaluate(async (locale) => {
|
||||
window.require.config({ 'paths': { vs: '/assets/js/vs' }, 'vs/nls': { availableLanguages: locale === 'en' ? {} : { '*': locale } } })
|
||||
const load = ids => new Promise((resolve, reject) => window.require(ids, (...modules) => resolve(modules), reject))
|
||||
await load(['vs/editor/editor.main'])
|
||||
const [platform] = await load(['vs/base/common/platform'])
|
||||
const host = document.createElement('div')
|
||||
host.style.cssText = 'width:800px;height:400px'
|
||||
document.body.appendChild(host)
|
||||
const editor = window.monaco.editor.create(host, { value: 'first\nsecond\nfirst', language: 'plaintext', minimap: { enabled: false } })
|
||||
editor.setPosition({ lineNumber: 1, column: 6 })
|
||||
editor.focus()
|
||||
window.coreProbe = { editor, host }
|
||||
return platform.isMacintosh ? 'Meta' : 'Control'
|
||||
}, locale.locale)
|
||||
try {
|
||||
await page.keyboard.insertText(' beta')
|
||||
await expect.poll(() => page.evaluate(() => window.coreProbe.editor.getValue())).toBe('first beta\nsecond\nfirst')
|
||||
await page.keyboard.press(`${modifier}+z`)
|
||||
await expect.poll(() => page.evaluate(() => window.coreProbe.editor.getValue())).toBe('first\nsecond\nfirst')
|
||||
await page.keyboard.press(modifier === 'Meta' ? 'Meta+Shift+z' : 'Control+y')
|
||||
await expect.poll(() => page.evaluate(() => window.coreProbe.editor.getValue())).toBe('first beta\nsecond\nfirst')
|
||||
await page.evaluate(() => {
|
||||
window.coreProbe.editor.setPosition({ lineNumber: 1, column: 1 })
|
||||
return window.coreProbe.editor.getAction('actions.find').run()
|
||||
})
|
||||
const input = page.getByRole('textbox', { name: locale.find, exact: true })
|
||||
await expect(input).toBeVisible()
|
||||
await expect(input).toHaveAttribute('aria-label', locale.find)
|
||||
await input.fill('st')
|
||||
await expect.poll(() => page.evaluate(() => {
|
||||
const selection = window.coreProbe.editor.getSelection()
|
||||
return [selection.startLineNumber, selection.startColumn, selection.endColumn]
|
||||
})).toEqual([1, 4, 6])
|
||||
await input.press('Enter')
|
||||
await expect.poll(() => page.evaluate(() => window.coreProbe.editor.getSelection().startLineNumber)).toBe(3)
|
||||
await input.press('Escape')
|
||||
await expect(input).not.toBeVisible()
|
||||
expect(responses).toHaveLength(1)
|
||||
expect(responses[0].status).toBe(200)
|
||||
expect(responses[0].url).toContain(`editor.main.nls${locale.locale === 'en' ? '' : `.${locale.locale}`}.js`)
|
||||
await testInfo.attach('monaco-core-editing', { contentType: 'application/json', body: JSON.stringify({ locale, modifier, responses }) })
|
||||
}
|
||||
finally {
|
||||
await page.evaluate(() => {
|
||||
const { editor, host } = window.coreProbe
|
||||
const model = editor.getModel()
|
||||
editor.dispose()
|
||||
model.dispose()
|
||||
host.remove()
|
||||
})
|
||||
}
|
||||
expect(await page.evaluate(() => window.monaco.editor.getModels().length)).toBe(0)
|
||||
})
|
||||
}
|
||||
@@ -4,10 +4,27 @@ import test from 'node:test'
|
||||
import ts from 'typescript'
|
||||
import { extractBasicFixtures } from '../scripts/site-vendor/monaco/basic-fixtures.ts'
|
||||
import { emitAmd } from '../scripts/site-vendor/monaco/compiler.ts'
|
||||
import { inventoryCoreMap, readCoreNls, restoreCoreMapComment } from '../scripts/site-vendor/monaco/core-build.ts'
|
||||
import { adaptCoreOrigin } from '../scripts/site-vendor/monaco/core-origins.ts'
|
||||
import { aliasModule, moduleIds, nameModule, verifyWorkerSources } from '../scripts/site-vendor/monaco/languages.ts'
|
||||
import { browserTypeScript, verifyTypeScriptSource } from '../scripts/site-vendor/monaco/typescript.ts'
|
||||
|
||||
test('Core NLS extraction accepts historical trailing commas without evaluating expressions', () => {
|
||||
assert.deepEqual(readCoreNls('define("nls", { "find": ["Find", "查找",], });'), { id: 'nls', messages: { find: ['Find', '查找'] } })
|
||||
assert.throws(() => readCoreNls('define("nls", { "find": [translate()], });'), /literal translation text/)
|
||||
assert.throws(() => readCoreNls('define("nls", { "find": [], "find": [] });'), /Repeated translation/)
|
||||
assert.throws(() => readCoreNls('run(); define("nls", {});'), /one NLS registration/)
|
||||
})
|
||||
|
||||
test('Core source inventories and map comments reject incomplete or ambiguous evidence', () => {
|
||||
assert.equal(inventoryCoreMap({ sources: ['test'], sourcesContent: ['查找'] })[0].bytes, 6)
|
||||
assert.throws(() => inventoryCoreMap({ sources: ['a'], sourcesContent: [] }), /Missing mapped/)
|
||||
assert.throws(() => inventoryCoreMap({ sources: ['a', 'a'], sourcesContent: ['', ''] }), /Repeated mapped/)
|
||||
assert.equal(restoreCoreMapComment('code;\n', 'vs/loader.js'), 'code;\n\n//# sourceMappingURL=../../min-maps/vs/loader.js.map')
|
||||
assert.throws(() => restoreCoreMapComment('code;', 'vs/loader.js'), /newline/)
|
||||
assert.throws(() => restoreCoreMapComment('code;\n', 'vs/../outside.js'), /output path/)
|
||||
})
|
||||
|
||||
test('Core origin adaptation rejects duplicate boundaries and preserves replacement bytes', () => {
|
||||
const edits = [{ before: 'export default purify;', after: 'define(factory); // $&' }]
|
||||
assert.equal(adaptCoreOrigin('export default purify;', edits), 'define(factory); // $&')
|
||||
|
||||
Reference in new issue
Block a user