Skip to content

Commit

Permalink
Merge pull request #93 from Krinkle/fixture
Browse files Browse the repository at this point in the history
fix(adapter): only create fixture at begin and only if none exists prior
  • Loading branch information
dignifiedquire authored Mar 14, 2018
2 parents ca9bd6b + 84eab8c commit 0f225e0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 23 deletions.
37 changes: 18 additions & 19 deletions src/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ function createQUnitStartFn (tc, runnerPassedIn) { // eslint-disable-line no-unu
tc.info({ total: args.totalTests })
supportsTestTracking = true
}

if (typeof document !== 'undefined' && document.getElementById && document.createElement && document.body) {
// Create a qunit-fixture element to match behaviour of regular qunit runner.
// The fixture is only created once when the runner begins.
// Resetting is handled by qunit
var fixture = document.getElementById(FIXTURE_ID)
if (!fixture) {
fixture = document.createElement('div')
fixture.id = FIXTURE_ID
// style to match qunit runner's CSS
fixture.style.position = 'absolute'
fixture.style.left = '-10000px'
fixture.style.top = '-10000px'
fixture.style.width = '1000px'
fixture.style.height = '1000px'
document.body.appendChild(fixture)
}
}
})
}

Expand All @@ -51,25 +69,6 @@ function createQUnitStartFn (tc, runnerPassedIn) { // eslint-disable-line no-unu
totalNumberOfTest += 1
timer = new Date().getTime()
testResult = { success: true, errors: [] }

if (typeof document !== 'undefined' && document.getElementById && document.createElement && document.body) {
// create a qunit-fixture element to match behaviour of regular qunit
// runner. The fixture is only removed at the start of a subsequent test
// so it can be inspected after a test run.
var fixture = document.getElementById(FIXTURE_ID)
if (fixture) {
fixture.parentNode.removeChild(fixture)
}
fixture = document.createElement('div')
fixture.id = FIXTURE_ID
// style to match qunit runner's CSS
fixture.style.position = 'absolute'
fixture.style.left = '-10000px'
fixture.style.top = '-10000px'
fixture.style.width = '1000px'
fixture.style.height = '1000px'
document.body.appendChild(fixture)
}
})

runner.log(function (details) {
Expand Down
25 changes: 21 additions & 4 deletions test/adapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,35 @@ describe('adapter qunit', function () {
})

describe('test start', function () {
it('should create a qunit-fixture element, and remove if exists', function () {
it('should create a qunit-fixture element if none exists', function () {
var fixture = document.getElementById('qunit-fixture')
if (fixture) {
fixture.parentNode.removeChild(fixture)
fixture = document.getElementById('qunit-fixture')
}
expect(fixture).toBe(null)

runner.emit('begin', {})
runner.emit('testStart', {})

var fixture = document.getElementById('qunit-fixture')
fixture = document.getElementById('qunit-fixture')
expect(fixture).toBeDefined()
})

it('should preserve any existing qunit-fixture element', function () {
var fixture = document.getElementById('qunit-fixture')
if (!fixture) {
fixture = document.createElement('div')
fixture.id = 'qunit-fixture'
document.body.appendChild(fixture)
}
fixture.className = 'marker'

runner.emit('begin', {})
runner.emit('testStart', {})

fixture = document.getElementById('qunit-fixture')
expect(fixture).toBeDefined()
expect(fixture.className).not.toBe('marker')
expect(fixture.className).toBe('marker')
})
})

Expand Down

0 comments on commit 0f225e0

Please sign in to comment.