Skip to content

Migrate usage of document.evaluate to eliminate need for Playwright when running unit tests #955

@st3iny

Description

@st3iny

Currently, unit tests can not be run locally easily as a headless browser needs to be set up. This is caused by the usage of the document.evaluate() API to traverse XML responses which is not supported in usual testing environments, for example, jsdom.

We should migrate the affected tests and source code to another API for checking XML contents not have to set up a browser.

Occurrences

src/request.js
385:            const responses = document.evaluate('/d:multistatus/d:response', document, NS.resolve, XPathResult.ANY_TYPE, null)
389:                    const href = document.evaluate('string(d:href)', responseNode, NS.resolve, XPathResult.ANY_TYPE, null).stringValue
391:                    const propStats = document.evaluate('d:propstat', responseNode, NS.resolve, XPathResult.ANY_TYPE, null)
395:                            const status = document.evaluate('string(d:status)', propStatNode, NS.resolve, XPathResult.ANY_TYPE, null).stringValue
400:                            const props = document.evaluate('d:prop/*', propStatNode, NS.resolve, XPathResult.ANY_TYPE, null)

src/parser.js
207:            return document.evaluate('string(.)', node, resolver, XPathResult.ANY_TYPE, null).stringValue
298:            const children = document.evaluate('*', node, resolver, XPathResult.ANY_TYPE, null)
302:                    const ns = document.evaluate('namespace-uri(.)', childNode, resolver, XPathResult.ANY_TYPE, null).stringValue
303:                    const local = document.evaluate('local-name(.)', childNode, resolver, XPathResult.ANY_TYPE, null).stringValue
320:            return document.evaluate('string(d:href)', node, resolver, XPathResult.ANY_TYPE, null).stringValue
333:            const hrefs = document.evaluate('d:href', node, resolver, XPathResult.ANY_TYPE, null)
337:                    result.push(document.evaluate('string(.)', hrefNode, resolver, XPathResult.ANY_TYPE, null).stringValue)
353:            const privileges = document.evaluate('d:privilege/*', node, resolver, XPathResult.ANY_TYPE, null)
357:                    const ns = document.evaluate('namespace-uri(.)', privilegeNode, resolver, XPathResult.ANY_TYPE, null).stringValue
358:                    const local = document.evaluate('local-name(.)', privilegeNode, resolver, XPathResult.ANY_TYPE, null).stringValue
378:                    = document.evaluate('count(d:unauthenticated)', node, resolver, XPathResult.ANY_TYPE, null).numberValue
403:            const addressDatas = document.evaluate('cr:address-data-type', node, resolver, XPathResult.ANY_TYPE, null)
408:                            'content-type': document.evaluate('string(@content-type)', addressDataNode, resolver, XPathResult.ANY_TYPE, null).stringValue,
409:                            version: document.evaluate('string(@version)', addressDataNode, resolver, XPathResult.ANY_TYPE, null).stringValue,
426:            const collations = document.evaluate('cr:supported-collation', node, resolver, XPathResult.ANY_TYPE, null)
430:                    result.push(document.evaluate('string(.)', collationNode, resolver, XPathResult.ANY_TYPE, null).stringValue)
446:            const collations = document.evaluate('cl:supported-collation', node, resolver, XPathResult.ANY_TYPE, null)
450:                    result.push(document.evaluate('string(.)', collationNode, resolver, XPathResult.ANY_TYPE, null).stringValue)
466:            const comps = document.evaluate('cl:comp', node, resolver, XPathResult.ANY_TYPE, null)
470:                    result.push(document.evaluate('string(@name)', compNode, resolver, XPathResult.ANY_TYPE, null).stringValue)
486:            const calendarDatas = document.evaluate('cl:calendar-data', node, resolver, XPathResult.ANY_TYPE, null)
491:                            'content-type': document.evaluate('string(@content-type)', calendarDataNode, resolver, XPathResult.ANY_TYPE, null).stringValue,
492:                            version: document.evaluate('string(@version)', calendarDataNode, resolver, XPathResult.ANY_TYPE, null).stringValue,
508:            const children = document.evaluate('cl:opaque | cl:transparent', node, resolver, XPathResult.ANY_TYPE, null)
511:                    return document.evaluate('local-name(.)', childNode, resolver, XPathResult.ANY_TYPE, null).stringValue
546:            const children = document.evaluate('cs:can-be-shared | cs:can-be-published', node, resolver, XPathResult.ANY_TYPE, null)
550:                    const ns = document.evaluate('namespace-uri(.)', childNode, resolver, XPathResult.ANY_TYPE, null).stringValue
551:                    const local = document.evaluate('local-name(.)', childNode, resolver, XPathResult.ANY_TYPE, null).stringValue
569:            const users = document.evaluate('oc:user', node, resolver, XPathResult.ANY_TYPE, null)
575:                            'common-name': document.evaluate('string(oc:common-name)', userNode, resolver, XPathResult.ANY_TYPE, null).stringValue,
576:                            'invite-accepted': document.evaluate('count(oc:invite-accepted)', userNode, resolver, XPathResult.ANY_TYPE, null).numberValue === 1,
594:            const privileges = document.evaluate('oc:access/*', node, resolver, XPathResult.ANY_TYPE, null)
598:                    const ns = document.evaluate('namespace-uri(.)', privilegeNode, resolver, XPathResult.ANY_TYPE, null).stringValue
599:                    const local = document.evaluate('local-name(.)', privilegeNode, resolver, XPathResult.ANY_TYPE, null).stringValue

test/unit/parserTest.js
1952:   const responses = document.evaluate('/d:multistatus/d:response', document, resolver, XPathResult.ANY_TYPE, null);
1954:   const propStats = document.evaluate('d:propstat', response, resolver, XPathResult.ANY_TYPE, null);
1956:   const props = document.evaluate('d:prop/*', propStat, resolver, XPathResult.ANY_TYPE, null);

src/models/scheduleOutbox.js
32:             const responses = document.evaluate('/cl:schedule-response/cl:response', document, NS.resolve, XPathResult.ANY_TYPE, null)
36:                     const recipient = document.evaluate('string(cl:recipient/d:href)', responseNode, NS.resolve, XPathResult.ANY_TYPE, null).stringValue
37:                     const status = document.evaluate('string(cl:request-status)', responseNode, NS.resolve, XPathResult.ANY_TYPE, null).stringValue
38:                     const calendarData = document.evaluate('string(cl:calendar-data)', responseNode, NS.resolve, XPathResult.ANY_TYPE, null).stringValue

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

📄 To do

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions