Skip to content

Commit

Permalink
fix(qunit-hooks): filters out unwanted modules (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBuchholz committed Jul 3, 2024
1 parent e0e4a42 commit ecc523e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 22 deletions.
12 changes: 9 additions & 3 deletions src/qunit-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,17 @@ function merge (targetModules, modules) {
}

function filterModules (modules, url) {
const moduleMatch = url.match(/\?.*\bmoduleId=([^&]+)/)
if (moduleMatch) {
const [, moduleId] = moduleMatch
const moduleIdMatch = url.match(/\?.*\bmoduleId=([^&]+)/)
if (moduleIdMatch) {
const [, moduleId] = moduleIdMatch
return modules.filter(module => module.moduleId === moduleId)
}
const moduleNameMatch = url.match(/\?.*\bmodule=([^&]+)/)
if (moduleNameMatch) {
const [, escapedModuleName] = moduleNameMatch
const moduleName = escapedModuleName.replace(/\+|%20/g, ' ')
return modules.filter(module => module.name === moduleName)
}
return modules
}

Expand Down
65 changes: 46 additions & 19 deletions src/qunit-hooks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,6 @@ describe('src/qunit-hooks', () => {
})

describe('moduleId filtering', () => {
const urlWithModuleId = 'http://localhost:80/page1.html?moduleId=1'
const module1 = {
name: 'module 1',
moduleId: '1',
Expand All @@ -888,16 +887,8 @@ describe('src/qunit-hooks', () => {
}]
}

beforeEach(async () => {
await begin(job, urlWithModuleId, {
isOpa: true,
totalTests: 0,
modules: [module1, module2]
})
})

function checkPageModules () {
const { page: { modules } } = get(job, urlWithModuleId)
function checkPageModules (url) {
const { page: { modules } } = get(job, url)
expect(modules.length).toStrictEqual(1)
expect(modules[0]).toMatchObject({
name: 'module 1',
Expand All @@ -909,16 +900,52 @@ describe('src/qunit-hooks', () => {
})
}

it('filters out module on startup', () => checkPageModules())
describe('QUnit v1', () => {
const urlWithModuleName = 'http://localhost:80/page1.html?module=module%201'

it('filters modules if new ones are added', async () => {
await testStart(job, urlWithModuleId, {
module: 'test.html?journey=1A',
name: 'test 1a',
testId: '1a',
modules: [module1, module2, module3]
beforeEach(async () => {
await begin(job, urlWithModuleName, {
isOpa: true,
totalTests: 0,
modules: [module1, module2]
})
})

it('filters out module on startup', () => checkPageModules(urlWithModuleName))

it('filters modules if new ones are added', async () => {
await testStart(job, urlWithModuleName, {
module: 'test.html?journey=1A',
name: 'test 1a',
testId: '1a',
modules: [module1, module2, module3]
})
checkPageModules(urlWithModuleName)
})
})

describe('QUnit v2', () => {
const urlWithModuleId = 'http://localhost:80/page1.html?moduleId=1'

beforeEach(async () => {
await begin(job, urlWithModuleId, {
isOpa: true,
totalTests: 0,
modules: [module1, module2]
})
})

it('filters out module on startup', () => checkPageModules(urlWithModuleId))

it('filters modules if new ones are added', async () => {
await testStart(job, urlWithModuleId, {
module: 'test.html?journey=1A',
name: 'test 1a',
testId: '1a',
modules: [module1, module2, module3]
})
checkPageModules(urlWithModuleId)
})
checkPageModules()
})
})
})

0 comments on commit ecc523e

Please sign in to comment.