summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-11-28 15:26:03 +0100
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-11-28 15:26:03 +0100
commitefc82b0eafa72902b35c2b22cd9e86bdbdd3edfb (patch)
treea13e7d67d34d9edff704cd0900a18785edb2f89f
parent1f301ad162964eb9079d1c22e3c7ed1c207c4f59 (diff)
downloadsvg.js-efc82b0eafa72902b35c2b22cd9e86bdbdd3edfb.tar.gz
svg.js-efc82b0eafa72902b35c2b22cd9e86bdbdd3edfb.zip
fix testing with svgdom
-rw-r--r--package.json2
-rw-r--r--spec/run.js36
-rw-r--r--spec/runSVGDomTest.js22
-rw-r--r--spec/setupSVGDom.js21
-rw-r--r--spec/spec/utils/adopter.js19
5 files changed, 57 insertions, 43 deletions
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)
})
})