Skip to content

Commit

Permalink
fix(qunit-hooks): handles QUnit v1 change of URL
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBuchholz committed Jul 2, 2024
1 parent 7e2af45 commit e0e4a42
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/qunit-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@ function filterModules (modules, url) {
}

function get (job, urlWithHash, { testId, modules, isOpa } = {}) {
const url = stripUrlHash(urlWithHash)
const page = job.qunitPages && job.qunitPages[url]
const progress = (job[$browsers] && job[$browsers][url] && job[$browsers][url].progress) || { total: 0, count: 0 }
let url = stripUrlHash(urlWithHash)
let page = job.qunitPages && job.qunitPages[url]
if (!page && url.includes('module=')) {
url = url.replace(/\bmodule=([^&]+)/, (_, name) => `module=${name.replace(/\+/g, '%20')}`)
page = job.qunitPages && job.qunitPages[url]
}
if (!page) {
error(job, url, `No QUnit page found for ${urlWithHash}`)
}
const progress = (job[$browsers] && job[$browsers][url] && job[$browsers][url].progress) || { total: 0, count: 0 }
merge(page.modules, filterModules(modules || [], url))
progress.total = page.count = page.modules.reduce((total, { tests }) => total + tests.length, 0)
if (!page.isOpa && isOpa) {
Expand Down
13 changes: 13 additions & 0 deletions src/qunit-hooks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ describe('src/qunit-hooks', () => {
modules: getModules()
})

describe('get', () => {
it('handles module escaping required for QUnit v1', () => {
job.qunitPages = {
'http://localhost:80/page1.html?module=module%201': {
modules: []
}
}
const { page, url } = get(job, 'http://localhost:80/page1.html?module=module+1')
expect(page).not.toBeUndefined()
expect(url).toStrictEqual('http://localhost:80/page1.html?module=module%201')
})
})

describe('begin', () => {
it('allocates a placeholder page', async () => {
await begin(job, url, getBeginInfo())
Expand Down

0 comments on commit e0e4a42

Please sign in to comment.