Fix test; start browser with clipboar-read perm
This commit is contained in:
Родитель
afddae7fbd
Коммит
80570f38fc
27
test/test.js
27
test/test.js
|
@ -42,6 +42,7 @@ describe('clipboard-copy element', function () {
|
|||
describe('target element', function () {
|
||||
const nativeClipboard = navigator.clipboard
|
||||
let whenCopied
|
||||
|
||||
beforeEach(function () {
|
||||
const container = document.createElement('div')
|
||||
container.innerHTML = `
|
||||
|
@ -56,16 +57,15 @@ describe('clipboard-copy element', function () {
|
|||
copiedText = text
|
||||
return Promise.resolve()
|
||||
},
|
||||
readText() {
|
||||
return Promise.resolve(copiedText)
|
||||
},
|
||||
})
|
||||
|
||||
whenCopied = new Promise(resolve => {
|
||||
document.addEventListener('clipboard-copy', () => resolve(copiedText), {
|
||||
once: true,
|
||||
})
|
||||
|
||||
document.addEventListener('clipboard-copy-nothing', () => resolve(null), {
|
||||
once: true,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -162,14 +162,21 @@ describe('clipboard-copy element', function () {
|
|||
|
||||
const button = document.querySelector('clipboard-copy')
|
||||
button.setAttribute('aria-disabled', 'true')
|
||||
let fired = false;
|
||||
document.addEventListener('clipboard-copy', () => { fired = true }, { once: true })
|
||||
|
||||
|
||||
let fired = false
|
||||
document.addEventListener(
|
||||
'clipboard-copy',
|
||||
() => {
|
||||
fired = true
|
||||
},
|
||||
{once: true},
|
||||
)
|
||||
|
||||
button.click()
|
||||
|
||||
|
||||
await new Promise(setTimeout)
|
||||
assert.equal(fired, false);
|
||||
assert.equal(null, text)
|
||||
assert.equal(fired, false)
|
||||
assert.equal(null, await navigator.clipboard.readText())
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
@ -1,15 +1,18 @@
|
|||
import {esbuildPlugin} from '@web/dev-server-esbuild'
|
||||
import {playwrightLauncher} from '@web/test-runner-playwright'
|
||||
const browser = product =>
|
||||
const getBrowser = product =>
|
||||
playwrightLauncher({
|
||||
product,
|
||||
createBrowserContext: ({browser}) => {
|
||||
return browser.newContext({permissions: ['clipboard-read']})
|
||||
},
|
||||
})
|
||||
|
||||
export default {
|
||||
files: ['test/*'],
|
||||
nodeResolve: true,
|
||||
plugins: [esbuildPlugin({ts: true, target: 'es2020'})],
|
||||
browsers: [browser('chromium')],
|
||||
browsers: [getBrowser('chromium')],
|
||||
testFramework: {
|
||||
config: {
|
||||
timeout: 1000,
|
||||
|
|
Загрузка…
Ссылка в новой задаче