From: Ulrich-Matthias Schäfer Date: Wed, 28 Nov 2018 14:26:03 +0000 (+0100) Subject: fix testing with svgdom X-Git-Tag: 3.0.0~15 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=efc82b0eafa72902b35c2b22cd9e86bdbdd3edfb;p=svg.js.git fix testing with svgdom --- diff --git a/package.json b/package.json index b3701fe..8fc5e37 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "server": "npx http-server ./ -d", "test": "npx karma start .config/karma.conf.js", "test:ci": "karma start .config/karma.conf.saucelabs.js", - "test:svgdom": "node -r esm ./spec/run.js || true", + "test:svgdom": "node -r esm ./spec/runSVGDomTest.js || true", "test:es6": "npx karma start .config/karma.es6.js --single-run", "prepublishOnly": "npm run build && npm run build:polyfills && npm test", "postPublish": "echo Please upload a zip to the github release containing the dist, license and changelog" diff --git a/spec/run.js b/spec/run.js deleted file mode 100644 index 19c5027..0000000 --- a/spec/run.js +++ /dev/null @@ -1,36 +0,0 @@ -import Jasmine from 'jasmine' -import svgdom from 'svgdom' - -import { buildCanvas, buildFixtures, clear } from './helpers.js' -import { registerWindow } from '../src/main.js' - -const jasmine = new Jasmine() - -//jasmine.loadConfigFile('spec/support/jasmine.json') - -jasmine.loadConfig({ - "spec_dir": "spec/spec", - "spec_files": [ - "types/*.js", - // "!(helpers).js" - ], - "helpers": [ - // "helpers.js" - ] -}) - -jasmine.jasmine.currentEnv_.beforeEach(() => { - let win = /*new*/ svgdom - registerWindow(win, win.document) - buildCanvas() - buildFixtures() - global.container = win.document.getElementById('canvas') -}) - -jasmine.jasmine.currentEnv_.afterEach(() => { - clear() - global.container = null - registerWindow() -}) - -jasmine.execute() diff --git a/spec/runSVGDomTest.js b/spec/runSVGDomTest.js new file mode 100644 index 0000000..0db744d --- /dev/null +++ b/spec/runSVGDomTest.js @@ -0,0 +1,22 @@ +/* + This file has to be run with esm because node does not understand imports yet: + node -r esm ./spec/runSvgdomTest.js || true + + Without "|| true" node reports a super long error when a test fails + */ + +import Jasmine from 'jasmine' +const jasmine = new Jasmine() + +jasmine.loadConfig({ + "spec_dir": "spec/", + "spec_files": [ + "spec/types/*.js", + "spec/utils/*.js" + ], + "helpers": [ + "setupSVGDom.js" + ] +}) + +jasmine.execute() diff --git a/spec/setupSVGDom.js b/spec/setupSVGDom.js new file mode 100644 index 0000000..3da401d --- /dev/null +++ b/spec/setupSVGDom.js @@ -0,0 +1,21 @@ +import svgdom from 'svgdom' + +import { buildCanvas, buildFixtures, clear } from './helpers.js' +import { registerWindow } from '../src/main.js' + +function setup () { + let win = /*new*/ svgdom + registerWindow(win, win.document) + buildCanvas() + buildFixtures() + global.container = win.document.getElementById('canvas') +} + +function teardown () { + clear() + global.container = null + registerWindow() +} + +beforeEach(setup) +afterEach(teardown) diff --git a/spec/spec/utils/adopter.js b/spec/spec/utils/adopter.js index 53ee198..8087731 100644 --- a/spec/spec/utils/adopter.js +++ b/spec/spec/utils/adopter.js @@ -15,13 +15,17 @@ import { root } from '../../../src/main.js' -import { getWindow } from '../../../src/utils/window.js' import { mockAdopt } from '../../../src/utils/adopter.js' import { buildFixtures } from '../../helpers.js' - -const Node = getWindow().Node +import { globals } from '../../../src/utils/window.js' describe('Adopter.js', () => { + let Node + + beforeEach(() => { + Node = globals.window.Node + }) + describe('makeNode()', () => { it('creates a node of the specified type', () => { let rect = makeNode('rect') @@ -65,7 +69,7 @@ describe('Adopter.js', () => { it('searches for element in dom if selector given', () => { buildFixtures() - let path = getWindow().document.getElementById('lineAB') + let path = globals.window.document.getElementById('lineAB') makeInstance('#lineAB') makeInstance('#doesNotExist') @@ -90,8 +94,11 @@ describe('Adopter.js', () => { }) it('returns the node if one is passed', () => { - let div = document.createElement('div') - expect(nodeOrNew('something', div)).toBe(div) + let div = globals.window.document.createElement('div') + let node = nodeOrNew('something', div) + + // jasmine chucks on this when using the node directly + expect(node.outerHTML).toBe(div.outerHTML) }) })